forked from qt-creator/qt-creator
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 <marcus.tillmanns@qt.io>
This commit is contained in:
committed by
Marcus Tillmanns
parent
c43ff702f7
commit
8778eaaaa0
@@ -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<QIcon> icon = getIcon(m_filenameCache, filename);
|
||||
if (icon)
|
||||
return *icon;
|
||||
}
|
||||
|
||||
const QString suffix = !isDir ? filePath.suffix() : QString();
|
||||
if (!suffix.isEmpty()) {
|
||||
const std::optional<QIcon> 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()));
|
||||
}
|
||||
|
||||
/*!
|
||||
|
Reference in New Issue
Block a user