From 8778eaaaa06c669b35377ca8b61d509444acdb86 Mon Sep 17 00:00:00 2001 From: Eike Ziller Date: Tue, 14 Mar 2023 14:39:24 +0100 Subject: [PATCH] FileIconProvider: Improve performance of icon(FilePath) By re-using the caching QFileInfo variant for icon(FilePath). QFileInfo/FSEngine caches the result of isDir etc for a while, which improves performance for slower devices in case that is called for the same file paths over and over again, like it is the case for locator. The cache might be out of date for some time when things change on disk, but for a cosmetic property like an icon that is not a big deal. (And it would be a file that transforms into a directory or vice versa, which is not very common either.) Change-Id: I663ac7e81f8f2996b87591dad17c5483e3f4ad3c Reviewed-by: Marcus Tillmanns --- src/libs/utils/fsengine/fileiconprovider.cpp | 41 +------------------- 1 file changed, 1 insertion(+), 40 deletions(-) diff --git a/src/libs/utils/fsengine/fileiconprovider.cpp b/src/libs/utils/fsengine/fileiconprovider.cpp index e5ed4a1281f..07ea4b3f5a8 100644 --- a/src/libs/utils/fsengine/fileiconprovider.cpp +++ b/src/libs/utils/fsengine/fileiconprovider.cpp @@ -216,46 +216,7 @@ QIcon FileIconProviderImplementation::icon(const FilePath &filePath) const { qCDebug(fileIconProvider) << "FileIconProvider::icon" << filePath.absoluteFilePath(); - if (filePath.isEmpty()) - return unknownFileIcon(); - - // Check if its one of the virtual devices directories - if (filePath.path().startsWith(FilePath::specialRootPath())) { - // If the filepath does not need a device, it is a virtual device directory - if (!filePath.needsDevice()) - return dirIcon(); - } - - bool isDir = filePath.isDir(); - - // Check for cached overlay icons by file suffix. - const QString filename = !isDir ? filePath.fileName() : QString(); - if (!filename.isEmpty()) { - const std::optional icon = getIcon(m_filenameCache, filename); - if (icon) - return *icon; - } - - const QString suffix = !isDir ? filePath.suffix() : QString(); - if (!suffix.isEmpty()) { - const std::optional icon = getIcon(m_suffixCache, suffix); - if (icon) - return *icon; - } - - if (filePath.needsDevice()) - return isDir ? dirIcon() : unknownFileIcon(); - - // Get icon from OS (and cache it based on suffix!) - QIcon icon; - if (HostOsInfo::isWindowsHost() || HostOsInfo::isMacHost()) - icon = QFileIconProvider::icon(filePath.toFileInfo()); - else // File icons are unknown on linux systems. - icon = isDir ? QFileIconProvider::icon(filePath.toFileInfo()) : unknownFileIcon(); - - if (!isDir && !suffix.isEmpty()) - m_suffixCache.insert(suffix, icon); - return icon; + return icon(QFileInfo(filePath.toFSPathString())); } /*!