diff options
author | Benjamin Poulain <benjamin.poulain@nokia.com> | 2010-06-16 10:01:42 +0200 |
---|---|---|
committer | Benjamin Poulain <benjamin.poulain@nokia.com> | 2010-06-16 11:33:26 +0200 |
commit | 71ba2b0973d291e991e1498c266e69d6640c8531 (patch) | |
tree | 2c56a1a5d23b00c3f89be1c608df846f1cf420ef | |
parent | c9a89b253176547901e11d27c042983a65f43b1f (diff) | |
download | qt4-tools-71ba2b0973d291e991e1498c266e69d6640c8531.tar.gz |
Reduce the memory consumption of QtFontStyle
QtFontSize::pixelSize() was allocating 8 slots for QtFontSize
while most fonts only require one.
This patch add a special case for the first QtFontSize in order to
reduce memory consumption.
The size of QtFontSize in memory has also been reduced.
Overall, the memory consumtion of QtFontStyle instances go down
from 100kb to 10kb.
Reviewed-by: Eskil Abrahamsen Blomfeldt
-rw-r--r-- | src/gui/text/qfontdatabase.cpp | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/src/gui/text/qfontdatabase.cpp b/src/gui/text/qfontdatabase.cpp index ff29462d3f..4c058cef90 100644 --- a/src/gui/text/qfontdatabase.cpp +++ b/src/gui/text/qfontdatabase.cpp @@ -145,18 +145,18 @@ struct QtFontEncoding struct QtFontSize { - unsigned short pixelSize; - #ifdef Q_WS_X11 - int count; QtFontEncoding *encodings; QtFontEncoding *encodingID(int id, uint xpoint = 0, uint xres = 0, uint yres = 0, uint avgwidth = 0, bool add = false); + unsigned short count : 16; #endif // Q_WS_X11 #if defined(Q_WS_QWS) || defined(Q_OS_SYMBIAN) QByteArray fileName; int fileIndex; #endif // defined(Q_WS_QWS) || defined(Q_OS_SYMBIAN) + + unsigned short pixelSize : 16; }; @@ -284,7 +284,12 @@ QtFontSize *QtFontStyle::pixelSize(unsigned short size, bool add) if (!add) return 0; - if (!(count % 8)) { + if (!pixelSizes) { + // Most style have only one font size, we avoid waisting memory + QtFontSize *newPixelSizes = (QtFontSize *)malloc(sizeof(QtFontSize)); + Q_CHECK_PTR(newPixelSizes); + pixelSizes = newPixelSizes; + } else if (!(count % 8)) { QtFontSize *newPixelSizes = (QtFontSize *) realloc(pixelSizes, (((count+8) >> 3) << 3) * sizeof(QtFontSize)); |