# HG changeset patch # User Chris Cannam # Date 1589470685 -3600 # Node ID 705d1d979ae4182183c8fd24a43ee787d0f34c5a # Parent 6616e1899daa5d7177693e8c146ed3f32c23c4f5 It turns out icons are loaded repeatedly when recreating menus, causing an actually appreciable slowdown when some cases. Provide a cache diff -r 6616e1899daa -r 705d1d979ae4 widgets/IconLoader.cpp --- a/widgets/IconLoader.cpp Mon May 11 17:28:12 2020 +0100 +++ b/widgets/IconLoader.cpp Thu May 14 16:38:05 2020 +0100 @@ -22,11 +22,15 @@ #include #include #include +#include +#include #include #include +#include #include "base/Debug.h" +#include "base/Profiler.h" using namespace std; @@ -58,16 +62,29 @@ "zoom" }; -static vector sizes { 0, 16, 22, 24, 32, 48, 64, 128 }; - QIcon IconLoader::load(QString name) { + Profiler profiler("IconLoader::load"); + + static QMutex mutex; + static map icons; + static const vector sizes { 0, 16, 22, 24, 32, 48, 64, 128 }; + + QMutexLocker locker(&mutex); + + if (icons.find(name) != icons.end()) { + return icons.at(name); + } + QIcon icon; for (int sz: sizes) { QPixmap pmap(loadPixmap(name, sz)); if (!pmap.isNull()) icon.addPixmap(pmap); } + + icons[name] = icon; + return icon; }