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>
bb10
John Lindgren 2015-08-29 15:06:00 -04:00 committed by Allan Sandfeld Jensen
parent 1af802a9a6
commit 36aaf851ff
1 changed files with 12 additions and 10 deletions

View File

@ -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);
}
}
}
}