summaryrefslogtreecommitdiffstats
path: root/src/gui/text
diff options
context:
space:
mode:
authorBenjamin Poulain <benjamin.poulain@nokia.com>2010-06-16 08:01:42 (GMT)
committerBenjamin Poulain <benjamin.poulain@nokia.com>2010-06-16 09:33:26 (GMT)
commit71ba2b0973d291e991e1498c266e69d6640c8531 (patch)
tree2c56a1a5d23b00c3f89be1c608df846f1cf420ef /src/gui/text
parentc9a89b253176547901e11d27c042983a65f43b1f (diff)
downloadQt-71ba2b0973d291e991e1498c266e69d6640c8531.zip
Qt-71ba2b0973d291e991e1498c266e69d6640c8531.tar.gz
Qt-71ba2b0973d291e991e1498c266e69d6640c8531.tar.bz2
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
Diffstat (limited to 'src/gui/text')
-rw-r--r--src/gui/text/qfontdatabase.cpp13
1 files changed, 9 insertions, 4 deletions
diff --git a/src/gui/text/qfontdatabase.cpp b/src/gui/text/qfontdatabase.cpp
index ff29462..4c058ce 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));