From c2c17fd0536d9ea15e56fa83ef165db710896f28 Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Fri, 27 May 2022 03:44:23 +0800 Subject: [PATCH] Revise icon cache look up Find in `m_iconCache` first because it is cheaper than calling `QIcon::fromTheme()`. --- src/gui/uithememanager.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/gui/uithememanager.cpp b/src/gui/uithememanager.cpp index 4e8aa6933..3fadcd826 100644 --- a/src/gui/uithememanager.cpp +++ b/src/gui/uithememanager.cpp @@ -201,7 +201,13 @@ void UIThemeManager::applyStyleSheet() const QIcon UIThemeManager::getIcon(const QString &iconId, const QString &fallback) const { + // Cache to avoid rescaling svg icons + const auto iter = m_iconCache.find(iconId); + if (iter != m_iconCache.end()) + return *iter; + #if (defined(Q_OS_UNIX) && !defined(Q_OS_MACOS)) + // Don't cache system icons because users might change them at run time if (m_useSystemTheme) { QIcon icon = QIcon::fromTheme(iconId); @@ -211,12 +217,6 @@ QIcon UIThemeManager::getIcon(const QString &iconId, const QString &fallback) co } #endif - // Cache to avoid rescaling svg icons - // And don't cache system icons because users might change them at run time - const auto iter = m_iconCache.find(iconId); - if (iter != m_iconCache.end()) - return *iter; - const QIcon icon {getIconPathFromResources(iconId, fallback).data()}; m_iconCache[iconId] = icon; return icon;