summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Hodge <tpg@ucc.asn.au>2017-09-10 09:10:26 +0800
committerJohn Hodge <tpg@ucc.asn.au>2017-09-10 09:10:26 +0800
commit24fe34bfd1fa06d4aacba07e752134d5774884be (patch)
treed05c6553107389728f49d3e2cf623a5830e11ae7
parentbb567552b92d92b92f9e54a3c1e01baff9caf9f6 (diff)
downloadmrust-24fe34bfd1fa06d4aacba07e752134d5774884be.tar.gz
Codegen C - Slightly more efficient static string output
-rw-r--r--src/trans/codegen_c.cpp16
1 files changed, 11 insertions, 5 deletions
diff --git a/src/trans/codegen_c.cpp b/src/trans/codegen_c.cpp
index 56bbdfe2..416aa1f9 100644
--- a/src/trans/codegen_c.cpp
+++ b/src/trans/codegen_c.cpp
@@ -1611,12 +1611,18 @@ namespace {
m_of << "\\n";
break;
default:
- if( ' ' <= v )
+ if( ' ' <= v && static_cast<uint8_t>(v) < 0x7F )
m_of << v;
- else if( v < 16 )
- m_of << "\\x0" << (unsigned int)static_cast<uint8_t>(v) << "\"\"";
- else
- m_of << "\\x" << (unsigned int)static_cast<uint8_t>(v) << "\"\"";
+ else {
+ if( static_cast<uint8_t>(v) < 16 )
+ m_of << "\\x0" << (unsigned int)static_cast<uint8_t>(v);
+ else
+ m_of << "\\x" << (unsigned int)static_cast<uint8_t>(v);
+ // If the next character is a hex digit,
+ // close/reopen the string.
+ if( isxdigit(*(&v+1)) )
+ m_of << "\"\"";
+ }
}
}
m_of << "\"" << ::std::dec;