Windows: Fix one of the two file dialog bottlenecks.

This patch reduces the number of calls to GetFileAttributesEx()
when icon lookup is being done.

The second bottleneck is a couple of isSymLink() calls. Will fix
that next.

Task-number: QTBUG-13182
Change-Id: Ife3ff6cfb49d2294c501253ccc55d8c26036be94
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@digia.com>
This commit is contained in:
Sérgio Martins 2013-03-25 14:37:44 +00:00 committed by The Qt Project
parent 36cb3f3f65
commit b611da0d97

View File

@ -220,6 +220,22 @@ QIcon QFileIconProvider::icon(IconType type) const
return QIcon();
}
static bool isCacheable(const QFileInfo &fi)
{
if (!fi.isFile())
return false;
#ifdef Q_OS_WIN
// On windows it's faster to just look at the file extensions. QTBUG-13182
const QString fileExtension = fi.suffix();
return fileExtension.compare(QLatin1String("exe"), Qt::CaseInsensitive) &&
fileExtension.compare(QLatin1String("lnk"), Qt::CaseInsensitive) &&
fileExtension.compare(QLatin1String("ico"), Qt::CaseInsensitive);
#else
return !fi.isExecutable() && !fi.isSymLink();
#endif
}
QIcon QFileIconProviderPrivate::getIcon(const QFileInfo &fi) const
{
QIcon retIcon;
@ -234,7 +250,7 @@ QIcon QFileIconProviderPrivate::getIcon(const QFileInfo &fi) const
const QString fileExtension = fi.suffix().toUpper();
const QString keyBase = QLatin1String("qt_.") + fi.suffix().toUpper();
bool cacheable = fi.isFile() && !fi.isExecutable() && !fi.isSymLink() && fileExtension != QLatin1String("ICO");
bool cacheable = isCacheable(fi);
if (cacheable) {
QPixmap pixmap;
QPixmapCache::find(keyBase + QString::number(sizes.at(0)), pixmap);