From b1749e9052c68dff6089bf5f0d2a41cd88dfcb50 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Sat, 15 May 2010 11:39:26 +0200 Subject: Revert "Optimized pixmapcache key generation for icons and styles" This reverts commit b8f1d7fd87985375a373ca85052c475241822b03. --- src/gui/image/qicon.cpp | 23 ++++++------- src/gui/styles/qgtkpainter.cpp | 16 ++------- src/gui/styles/qstylehelper.cpp | 74 +++++++++++++++++++++++++++++------------ 3 files changed, 65 insertions(+), 48 deletions(-) diff --git a/src/gui/image/qicon.cpp b/src/gui/image/qicon.cpp index 9f1eea2..891b1db 100644 --- a/src/gui/image/qicon.cpp +++ b/src/gui/image/qicon.cpp @@ -261,19 +261,16 @@ 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); - int digits = sizeof(qint64)/sizeof(QChar); - quint64 tkey = pm.cacheKey(), - tmode = pe->mode, - tpalkey = QApplication::palette().cacheKey(), - twidth = actualSize.width(), - theight = actualSize.height(); - - QString key = QLatin1Literal("qt_") - % QString::fromRawData((QChar*)&tkey, digits) - % QString::fromRawData((QChar*)&tmode, digits) - % QString::fromRawData((QChar*)&tpalkey, digits) - % QString::fromRawData((QChar*)&twidth, digits) - % QString::fromRawData((QChar*)&theight, digits); + 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('_'); + if (mode == QIcon::Active) { if (QPixmapCache::find(key + QString::number(mode), pm)) diff --git a/src/gui/styles/qgtkpainter.cpp b/src/gui/styles/qgtkpainter.cpp index a6686e2..1f68f2f 100644 --- a/src/gui/styles/qgtkpainter.cpp +++ b/src/gui/styles/qgtkpainter.cpp @@ -154,21 +154,9 @@ QGtkPainter::QGtkPainter(QPainter *_painter) static QString uniqueName(const QString &key, GtkStateType state, GtkShadowType shadow, const QSize &size, GtkWidget *widget = 0) { - - int digits = sizeof(qint64)/sizeof(QChar); - quint64 tstate= state, - tshadow = shadow, - twidth = size.width(), - theight = size.height(), - twidget = quint64(widget); - // Note the widget arg should ideally use the widget path, though would compromise performance - QString tmp = key - % QString::fromRawData((QChar*)&tstate, digits) - % QString::fromRawData((QChar*)&tshadow, digits) - % QString::fromRawData((QChar*)&twidth, digits) - % QString::fromRawData((QChar*)&theight, digits) - % QString::fromRawData((QChar*)&twidget, digits); + QString tmp = QString(QLS("%0-%1-%2-%3x%4-%5")).arg(key).arg(uint(state)).arg(shadow) + .arg(size.width()).arg(size.height()).arg(quintptr(widget)); return tmp; } diff --git a/src/gui/styles/qstylehelper.cpp b/src/gui/styles/qstylehelper.cpp index 22f2014..296c51c 100644 --- a/src/gui/styles/qstylehelper.cpp +++ b/src/gui/styles/qstylehelper.cpp @@ -58,35 +58,67 @@ QT_BEGIN_NAMESPACE +// internal helper. Converts an integer value to an unique string token +template +struct HexString +{ + inline HexString(const T t) + : val(t) + {} + + inline void write(QChar *&dest) const + { + const ushort hexChars[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' }; + const char *c = reinterpret_cast(&val); + for (uint i = 0; i < sizeof(T); ++i) { + *dest++ = hexChars[*c & 0xf]; + *dest++ = hexChars[(*c & 0xf0) >> 4]; + ++c; + } + } + + const T val; +}; + +// specialization to enable fast concatenating of our string tokens to a string +template +struct QConcatenable > +{ + typedef HexString type; + enum { ExactSize = true }; + static int size(const HexString &str) { return sizeof(str.val) * 2; } + static inline void appendTo(const HexString &str, QChar *&out) { str.write(out); } +}; + namespace QStyleHelper { QString uniqueName(const QString &key, const QStyleOption *option, const QSize &size) { const QStyleOptionComplex *complexOption = qstyleoption_cast(option); - int digits = sizeof(qint64)/sizeof(QChar); - quint64 state = option->state, - direction = option->direction, - subcontrols = (complexOption ? uint(complexOption->activeSubControls) : 0u), - palettekey = option->palette.cacheKey(), - width = size.width(), - height = size.height(); - - QString tmp = key % QString::fromRawData((QChar*)&state, digits) - % QString::fromRawData((QChar*)&direction, digits) - % QString::fromRawData((QChar*)&subcontrols, digits) - % QString::fromRawData((QChar*)&palettekey, digits) - % QString::fromRawData((QChar*)&width, digits) - % QString::fromRawData((QChar*)&height, digits); + + QString tmp = key + % QLatin1Char('-') + % HexString(option->state) + % QLatin1Char('-') + % HexString(option->direction) + % QLatin1Char('-') + % HexString(complexOption ? uint(complexOption->activeSubControls) : 0u) + % QLatin1Char('-') + % HexString(option->palette.cacheKey()) + % QLatin1Char('-') + % HexString(size.width()) + % QLatin1Char('x') + % HexString(size.height()); #ifndef QT_NO_SPINBOX if (const QStyleOptionSpinBox *spinBox = qstyleoption_cast(option)) { - quint64 buttonsymbols = spinBox->buttonSymbols, - stepEnabled = spinBox->stepEnabled, - frame = spinBox->frame; - - tmp = tmp % QString::fromRawData((QChar*)&buttonsymbols, digits) - % QString::fromRawData((QChar*)&stepEnabled, digits) - % QString::fromRawData((QChar*)&frame, digits); + tmp = tmp + % QLatin1Char('-') + % HexString(spinBox->buttonSymbols) + % QLatin1Char('-') + % HexString(spinBox->stepEnabled) + % QLatin1Char('-') + % QLatin1Char(spinBox->frame ? '1' : '0'); } #endif // QT_NO_SPINBOX return tmp; -- cgit v0.12