summaryrefslogtreecommitdiffstats
path: root/src/gui
diff options
context:
space:
mode:
authorJohn Lindgren <john.lindgren@aol.com>2015-08-29 15:06:00 -0400
committerAllan Sandfeld Jensen <allan.jensen@qt.io>2016-05-24 10:39:00 +0000
commit36aaf851ff2814e9e5c024e21b866c403137ff26 (patch)
tree06bdeef6a9336638b22d5f4c057023e8ab7d4a73 /src/gui
parent1af802a9a62f7237800db17419e57c6f848ed00d (diff)
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 <gunnar@sletta.org>
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/image/qiconloader.cpp22
1 files changed, 12 insertions, 10 deletions
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);
+ }
}
}
}