From f74ee5cde96e7747a61687a61d943b583336047b Mon Sep 17 00:00:00 2001 From: Phenom Date: Sat, 20 Jan 2018 17:21:37 +0100 Subject: [PATCH] Move File Icon Cache in FilesDefs --- retroshare-gui/src/gui/common/FilesDefs.cpp | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/retroshare-gui/src/gui/common/FilesDefs.cpp b/retroshare-gui/src/gui/common/FilesDefs.cpp index b20660b20..4ca20699a 100644 --- a/retroshare-gui/src/gui/common/FilesDefs.cpp +++ b/retroshare-gui/src/gui/common/FilesDefs.cpp @@ -19,11 +19,14 @@ * Boston, MA 02110-1301, USA. ****************************************************************/ +#include "FilesDefs.h" + +#include "RsCollection.h" + #include #include -#include "FilesDefs.h" -#include "RsCollection.h" +#include static QString getInfoFromFilename(const QString& filename, bool anyForUnknown, bool image) { @@ -85,7 +88,19 @@ QString FilesDefs::getImageFromFilename(const QString& filename, bool anyForUnkn QIcon FilesDefs::getIconFromFilename(const QString& filename) { - return QIcon(getInfoFromFilename(filename, true, true)); + QString sImage = getInfoFromFilename(filename, true, true); + static std::map mIconCache; + QIcon icon; + auto item = mIconCache.find(sImage); + if (item == mIconCache.end()) + { + icon = QIcon(sImage); + mIconCache[sImage] = icon; + } + else + icon = item->second; + + return icon; } QString FilesDefs::getNameFromFilename(const QString &filename)