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. Change-Id: Iace9a3f904730064f44939b2269316484ac6da2e Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io> (cherry picked from commit 620373e1ad47affbf7e63b73b8f634fbb273da99) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
parent
cce1222cc0
commit
a73453fdb3
@ -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();
|
||||
|
Loading…
x
Reference in New Issue
Block a user