From e14503d353de7246a1d6e36894dd77bb32c4af3b Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Fri, 11 Oct 2013 00:12:27 +0200 Subject: [PATCH] QTextDocument: avoid relocations Hand-roll a string table here, since there's opportunity for sharing string data between string entries. Effects on Linux AMD64 GCC 4.9-trunk release stripped: text: -88B data: -64B relocs: -5 Maintainability is hurt somewhat, but it is expected that the contents of this string table do not change much, so the overall effect is still very low. Change-Id: I2a22da4c8548c53ef31c33319b4652f3cb6f62f5 Reviewed-by: Simon Hausmann --- src/gui/text/qtextdocument.cpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/gui/text/qtextdocument.cpp b/src/gui/text/qtextdocument.cpp index 82d63237e7f..fa54776b6db 100644 --- a/src/gui/text/qtextdocument.cpp +++ b/src/gui/text/qtextdocument.cpp @@ -2160,13 +2160,21 @@ bool QTextHtmlExporter::emitCharFormatStyle(const QTextCharFormat &format) html += QLatin1String("pt;"); attributesEmitted = true; } else if (format.hasProperty(QTextFormat::FontSizeAdjustment)) { - static const char * const sizeNames[] = { - "small", "medium", "large", "x-large", "xx-large" + static const char sizeNameData[] = + "small" "\0" + "medium" "\0" + "xx-large" ; + static const quint8 sizeNameOffsets[] = { + 0, // "small" + sizeof("small"), // "medium" + sizeof("small") + sizeof("medium") + 3, // "large" ) + sizeof("small") + sizeof("medium") + 1, // "x-large" )> compressed into "xx-large" + sizeof("small") + sizeof("medium"), // "xx-large" ) }; const char *name = 0; const int idx = format.intProperty(QTextFormat::FontSizeAdjustment) + 1; if (idx >= 0 && idx <= 4) { - name = sizeNames[idx]; + name = sizeNameData + sizeNameOffsets[idx]; } if (name) { html += QLatin1String(" font-size:");