Commit a60960a8 authored by Eike Ziller's avatar Eike Ziller

FileIconProvider: Use hash for cache, instead of list.

Change-Id: I5d633ca2d21b6352c59cdeb7cd85267ced1d2170
Reviewed-by: default avatarhjk <hjk121@nokiamail.com>
parent d9e6854a
......@@ -37,7 +37,7 @@
#include <QStyle>
#include <QPainter>
#include <QFileInfo>
#include <QPair>
#include <QHash>
#include <QDebug>
#include <QFileIconProvider>
......@@ -68,9 +68,6 @@ namespace FileIconProvider {
enum { debug = 0 };
typedef QPair<QString, QIcon> StringIconPair;
typedef QList<StringIconPair> StringIconPairList;
class FileIconProviderImplementation : public QFileIconProvider
{
public:
......@@ -89,15 +86,8 @@ public:
QTC_ASSERT(!icon.isNull() && !suffix.isEmpty(), return);
const QPixmap fileIconPixmap = FileIconProvider::overlayIcon(QStyle::SP_FileIcon, icon, QSize(16, 16));
// replace old icon, if it exists
for (int i = 0, n = m_cache.size(); i != n; ++i) {
if (m_cache.at(i).first == suffix) {
m_cache[i].second = fileIconPixmap;
return;
}
}
m_cache.append(StringIconPair(suffix, fileIconPixmap));
m_cache.insert(suffix, fileIconPixmap);
}
void registerIconOverlayForMimeType(const QIcon &icon, const MimeType &mimeType)
......@@ -107,7 +97,7 @@ public:
}
// Mapping of file suffix to icon.
StringIconPairList m_cache;
QHash<QString, QIcon> m_cache;
QIcon m_unknownFileIcon;
};
......@@ -130,10 +120,8 @@ QIcon FileIconProviderImplementation::icon(const QFileInfo &fileInfo) const
// Check for cached overlay icons by file suffix.
if (!m_cache.isEmpty() && !fileInfo.isDir()) {
const QString suffix = fileInfo.suffix();
if (!suffix.isEmpty()) {
for (int i = 0, n = m_cache.size(); i != n; ++i)
if (m_cache.at(i).first == suffix)
return m_cache[i].second;
if (!suffix.isEmpty() && m_cache.contains(suffix)) {
return m_cache.value(suffix);
}
}
// Get icon from OS.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment