summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authoraavit <qt-info@nokia.com>2010-05-10 14:23:44 (GMT)
committeraavit <qt-info@nokia.com>2010-05-11 09:29:16 (GMT)
commitad6dafee9be288bcef6b2c4b318b234d2995abff (patch)
treee1b2ba7e20990b734ed6d36ccb5af4d1307ff894 /src
parenta7b128ae838b006be1259ef6ba79da5440ed52dd (diff)
downloadQt-ad6dafee9be288bcef6b2c4b318b234d2995abff.zip
Qt-ad6dafee9be288bcef6b2c4b318b234d2995abff.tar.gz
Qt-ad6dafee9be288bcef6b2c4b318b234d2995abff.tar.bz2
Optimize QPixmapIconEngine's pixmap() function
Replace needlessly expensive cache key generation Task-number: QTBUG-9850 Reviewed-by: Trond
Diffstat (limited to 'src')
-rw-r--r--src/gui/image/qicon.cpp35
1 files changed, 21 insertions, 14 deletions
diff --git a/src/gui/image/qicon.cpp b/src/gui/image/qicon.cpp
index 891b1db..5ef0ff9 100644
--- a/src/gui/image/qicon.cpp
+++ b/src/gui/image/qicon.cpp
@@ -261,21 +261,28 @@ QPixmap QPixmapIconEngine::pixmap(const QSize &size, QIcon::Mode mode, QIcon::St
if (!actualSize.isNull() && (actualSize.width() > size.width() || actualSize.height() > size.height()))
actualSize.scale(size, Qt::KeepAspectRatio);
- QString key = QLatin1String("$qt_icon_")
- + QString::number(pm.cacheKey())
- + QString::number(pe->mode)
- + QString::number(QApplication::palette().cacheKey())
- + QLatin1Char('_')
- + QString::number(actualSize.width())
- + QLatin1Char('_')
- + QString::number(actualSize.height())
- + QLatin1Char('_');
-
+ struct {
+ quint64 pmc;
+ qint32 w;
+ qint32 h;
+ quint64 pac;
+ qint32 m; // Make struct size a multiple of 4, for safety's sake
+ } dill;
+
+ dill.pmc = pm.cacheKey();
+ dill.w = actualSize.width();
+ dill.h = actualSize.height();
+ dill.pac = QApplication::palette().cacheKey();
+ dill.m = pe->mode;
+
+ QString keyBase = QLatin1String("$qt_icon_")
+ + QString::fromRawData((QChar *)&dill, sizeof(dill)/sizeof(QChar));
+ QString key = keyBase + QString::number(mode, 16);
if (mode == QIcon::Active) {
- if (QPixmapCache::find(key + QString::number(mode), pm))
+ if (QPixmapCache::find(key, pm))
return pm; // horray
- if (QPixmapCache::find(key + QString::number(QIcon::Normal), pm)) {
+ if (QPixmapCache::find(keyBase + QString::number(QIcon::Normal, 16), pm)) {
QStyleOption opt(0);
opt.palette = QApplication::palette();
QPixmap active = QApplication::style()->generatedIconPixmap(QIcon::Active, pm, &opt);
@@ -284,7 +291,7 @@ QPixmap QPixmapIconEngine::pixmap(const QSize &size, QIcon::Mode mode, QIcon::St
}
}
- if (!QPixmapCache::find(key + QString::number(mode), pm)) {
+ if (!QPixmapCache::find(key, pm)) {
if (pm.size() != actualSize)
pm = pm.scaled(actualSize, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
if (pe->mode != mode && mode != QIcon::Normal) {
@@ -294,7 +301,7 @@ QPixmap QPixmapIconEngine::pixmap(const QSize &size, QIcon::Mode mode, QIcon::St
if (!generated.isNull())
pm = generated;
}
- QPixmapCache::insert(key + QString::number(mode), pm);
+ QPixmapCache::insert(key, pm);
}
return pm;
}