1
0
mirror of https://github.com/d47081/qBittorrent.git synced 2025-02-02 09:55:55 +00:00

Revise icon cache look up

Find in `m_iconCache` first because it is cheaper than calling
`QIcon::fromTheme()`.
This commit is contained in:
Chocobo1 2022-05-27 03:44:23 +08:00
parent f54cc5796e
commit c2c17fd053
No known key found for this signature in database
GPG Key ID: 210D9C873253A68C

View File

@ -201,7 +201,13 @@ void UIThemeManager::applyStyleSheet() const
QIcon UIThemeManager::getIcon(const QString &iconId, const QString &fallback) 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)) #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) if (m_useSystemTheme)
{ {
QIcon icon = QIcon::fromTheme(iconId); QIcon icon = QIcon::fromTheme(iconId);
@ -211,12 +217,6 @@ QIcon UIThemeManager::getIcon(const QString &iconId, const QString &fallback) co
} }
#endif #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()}; const QIcon icon {getIconPathFromResources(iconId, fallback).data()};
m_iconCache[iconId] = icon; m_iconCache[iconId] = icon;
return icon; return icon;