From a48fbac7d758b321a8b6da87653b29d824b9b7e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Blanchon?= Date: Wed, 9 Jul 2014 13:19:12 +0200 Subject: [PATCH] Reduced the size of EscapedString::printTo() by 4 more bytes --- JsonGenerator/EscapedString.cpp | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/JsonGenerator/EscapedString.cpp b/JsonGenerator/EscapedString.cpp index 7671049f..dee8cd9e 100644 --- a/JsonGenerator/EscapedString.cpp +++ b/JsonGenerator/EscapedString.cpp @@ -21,6 +21,19 @@ static inline char getSpecialChar(char c) return p[1]; } +static inline size_t printCharTo(char c, Print& p) +{ + char specialChar = getSpecialChar(c); + if (specialChar) + { + return p.write('\\') + p.write(specialChar); + } + else + { + return p.write(c); + } +} + size_t EscapedString::printTo(Print& p) const { const char* s = rawString; @@ -36,17 +49,7 @@ size_t EscapedString::printTo(Print& p) const while (*s) { - char specialChar = getSpecialChar(*s); - - if (specialChar) - { - n += p.write('\\'); - n += p.write(specialChar); - } - else - { - n += p.write(*s); - } + n += printCharTo(*s, p); s++; }