From 36aaf851ff2814e9e5c024e21b866c403137ff26 Mon Sep 17 00:00:00 2001 From: John Lindgren Date: Sat, 29 Aug 2015 15:06:00 -0400 Subject: Optimize QIconLoader::findIconHelper() Profiling QIconLoader::findIconHelper() shows that a significant portion of CPU time is being spent in QDir::exists(), which creates a new QFileInfo object for the sole purpose of determining whether the passed-in file path is relative or absolute, and then calls QFile::exists(). In this context, we can just as easily generate the absolute path and call QFile::exists() directly, avoiding the creation of extra QDir and QFileInfo objects. Change-Id: Ib0b4568b6c16d423eb6c1b15158e44ff141e6175 Task-number: QTBUG-46767 Reviewed-by: Gunnar Sletta --- src/gui/image/qiconloader.cpp | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) (limited to 'src/gui/image') diff --git a/src/gui/image/qiconloader.cpp b/src/gui/image/qiconloader.cpp index 7b6bfc60b3..cc8337fcb9 100644 --- a/src/gui/image/qiconloader.cpp +++ b/src/gui/image/qiconloader.cpp @@ -431,21 +431,23 @@ QThemeIconInfo QIconLoader::findIconHelper(const QString &themeName, QString contentDir = contentDirs.at(i) + QLatin1Char('/'); for (int j = 0; j < subDirs.size() ; ++j) { const QIconDirInfo &dirInfo = subDirs.at(j); - QString subdir = dirInfo.path; - QDir currentDir(contentDir + subdir); - if (currentDir.exists(pngIconName)) { + const QString subDir = contentDir + dirInfo.path + QLatin1Char('/'); + const QString pngPath = subDir + pngIconName; + if (QFile::exists(pngPath)) { PixmapEntry *iconEntry = new PixmapEntry; iconEntry->dir = dirInfo; - iconEntry->filename = currentDir.filePath(pngIconName); + iconEntry->filename = pngPath; // Notice we ensure that pixmap entries always come before // scalable to preserve search order afterwards info.entries.prepend(iconEntry); - } else if (m_supportsSvg && - currentDir.exists(svgIconName)) { - ScalableEntry *iconEntry = new ScalableEntry; - iconEntry->dir = dirInfo; - iconEntry->filename = currentDir.filePath(svgIconName); - info.entries.append(iconEntry); + } else if (m_supportsSvg) { + const QString svgPath = subDir + svgIconName; + if (QFile::exists(svgPath)) { + ScalableEntry *iconEntry = new ScalableEntry; + iconEntry->dir = dirInfo; + iconEntry->filename = svgPath; + info.entries.append(iconEntry); + } } } } -- cgit v1.2.3