summaryrefslogtreecommitdiffstats
path: root/src/gui/image
diff options
context:
space:
mode:
authorDavid Redondo <qt@david-redondo.de>2023-12-12 15:56:39 +0100
committerDavid Redondo <qt@david-redondo.de>2023-12-13 15:15:24 +0100
commit620373e1ad47affbf7e63b73b8f634fbb273da99 (patch)
treef31dff9c7d6359de86eb24e0e8505815ed9b5028 /src/gui/image
parent9ea9e2476d72ae67178d55df99419f202b36131f (diff)
Do not create icon engine multiple times
Creating an icon engine is a potentially expensive operation involving many file lookups. In the case where neither QIconLoaderEngine nor the engine from the platform theme is valid, QIconLoader tries to unsuccesfully find the icon in all theme directories, the theme engine is constructed potentially doing some expensive operation and finally a new QIconLoaderEngine is constructed which does all the file lookups again. Instead keep the existing QIconLoaderEngine around if it was already constructed. Pick-to: 6.7 Change-Id: Iace9a3f904730064f44939b2269316484ac6da2e Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Diffstat (limited to 'src/gui/image')
-rw-r--r--src/gui/image/qiconloader.cpp14
1 files changed, 8 insertions, 6 deletions
diff --git a/src/gui/image/qiconloader.cpp b/src/gui/image/qiconloader.cpp
index c196179777..a597d1e8b6 100644
--- a/src/gui/image/qiconloader.cpp
+++ b/src/gui/image/qiconloader.cpp
@@ -633,14 +633,16 @@ QIconEngine *QIconLoader::iconEngine(const QString &iconName) const
qCDebug(lcIconLoader) << "Icon is not available from theme or fallback theme.";
if (auto *platformTheme = QGuiApplicationPrivate::platformTheme()) {
qCDebug(lcIconLoader) << "Trying platform engine.";
- iconEngine.reset(platformTheme->createIconEngine(iconName));
+ std::unique_ptr<QIconEngine> themeEngine(platformTheme->createIconEngine(iconName));
+ if (themeEngine && !themeEngine->isNull()) {
+ iconEngine = std::move(themeEngine);
+ qCDebug(lcIconLoader) << "Icon provided by platform engine.";
+ }
}
- // We need to maintain the invariant that the QIcon has a valid engine
- if (!iconEngine || iconEngine->isNull())
- iconEngine.reset(new QIconLoaderEngine(iconName));
- else
- qCDebug(lcIconLoader) << "Icon provided by platform engine.";
}
+ // We need to maintain the invariant that the QIcon has a valid engine
+ if (!iconEngine)
+ iconEngine.reset(new QIconLoaderEngine(iconName));
qCDebug(lcIconLoader) << "Resulting engine" << iconEngine.get();
return iconEngine.release();