QStyleSheetStyle: optimize away triple key lookup

Instead of contains()/value()/remove(), all of which perform a new
lookup, and a new application of qHash(), get an iterator using
find(), deref it, then pass it to erase().

Also add some optimistic std::move().

Change-Id: I27a623dcd974de9c67d11d030e9b98d7598efc93
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
bb10
Marc Mutz 2017-02-24 00:48:33 +01:00
parent 1d0ee89548
commit 46d4dc8afb
1 changed files with 8 additions and 6 deletions

View File

@ -2607,9 +2607,10 @@ void QStyleSheetStyle::unsetPalette(QWidget *w)
const bool useStyleSheetPropagationInWidgetStyles =
QCoreApplication::testAttribute(Qt::AA_UseStyleSheetPropagationInWidgetStyles);
if (styleSheetCaches->customPaletteWidgets.contains(w)) {
QPair<QPalette, uint> p = styleSheetCaches->customPaletteWidgets.value(w);
styleSheetCaches->customPaletteWidgets.remove(w);
const auto it = styleSheetCaches->customPaletteWidgets.find(w);
if (it != styleSheetCaches->customPaletteWidgets.end()) {
QPair<QPalette, uint> p = std::move(*it);
styleSheetCaches->customPaletteWidgets.erase(it);
QPalette original = p.first;
@ -2649,9 +2650,10 @@ void QStyleSheetStyle::unsetPalette(QWidget *w)
void QStyleSheetStyle::unsetStyleSheetFont(QWidget *w) const
{
if (styleSheetCaches->customFontWidgets.contains(w)) {
QPair<QFont, uint> f = styleSheetCaches->customFontWidgets.value(w);
styleSheetCaches->customFontWidgets.remove(w);
const auto it = styleSheetCaches->customFontWidgets.find(w);
if (it != styleSheetCaches->customFontWidgets.end()) {
QPair<QFont, uint> f = std::move(*it);
styleSheetCaches->customFontWidgets.erase(it);
QFont original = f.first;
original.resolve(original.resolve() & f.second);