From 24fe34bfd1fa06d4aacba07e752134d5774884be Mon Sep 17 00:00:00 2001 From: John Hodge Date: Sun, 10 Sep 2017 09:10:26 +0800 Subject: Codegen C - Slightly more efficient static string output --- src/trans/codegen_c.cpp | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'src') 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(v) < 0x7F ) m_of << v; - else if( v < 16 ) - m_of << "\\x0" << (unsigned int)static_cast(v) << "\"\""; - else - m_of << "\\x" << (unsigned int)static_cast(v) << "\"\""; + else { + if( static_cast(v) < 16 ) + m_of << "\\x0" << (unsigned int)static_cast(v); + else + m_of << "\\x" << (unsigned int)static_cast(v); + // If the next character is a hex digit, + // close/reopen the string. + if( isxdigit(*(&v+1)) ) + m_of << "\"\""; + } } } m_of << "\"" << ::std::dec; -- cgit v1.2.3