summaryrefslogtreecommitdiffstats
path: root/src/gui
diff options
context:
space:
mode:
authoraavit <qt-info@nokia.com>2010-05-10 14:23:44 (GMT)
committerSamuli Piippo <samuli.piippo@digia.com>2011-06-09 10:05:56 (GMT)
commit523ccf891c67a43fc58bf07728b44973fbc4de12 (patch)
tree6f81443c356317c1e14f0961f6cba221400372ec /src/gui
parent9c8458889b6d4bc6d1674737fccb0d0d61354500 (diff)
downloadQt-523ccf891c67a43fc58bf07728b44973fbc4de12.zip
Qt-523ccf891c67a43fc58bf07728b44973fbc4de12.tar.gz
Qt-523ccf891c67a43fc58bf07728b44973fbc4de12.tar.bz2
Optimize QPixmapIconEngine's pixmap() function
Replace needlessly expensive cache key generation Task-number: QTBUG-9850 Reviewed-by: Trond (cherry picked from commit ad6dafee9be288bcef6b2c4b318b234d2995abff)
Diffstat (limited to 'src/gui')
-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 888a7fd..d3e800a 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;
}