summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorElvis Angelaccio <elvis.angelaccio@kde.org>2016-11-29 18:39:55 (GMT)
committerElvis Angelaccio <elvis.angelaccio@kde.org>2016-11-29 18:39:55 (GMT)
commit7618ea17108877e308d6c7b4e767fedda9534f9f (patch)
tree30963e6221066659e36de5a39933b951570f18b7
parent7a5e4e4c402e64ef5815e7bc10d9efb6468846a9 (diff)
pluginmanager: cache list of preferred plugins
PluginManager::preferredPluginsFor() is an hot path as it can be called thousands of times from the extractfileitemaction plugin. We can save the list of preferred plugins in a cache, instead of re-computing it over and over again. Tested in Dolphin by right-clicking: * 1K files: no delay * 10K files: ~1 sec. of delay * 50K files: ~4 sec. of delay The (empty) test files were created with: printf '%s ' {1..1000} | xargs touch BUG: 372999 FIXED-IN: 16.11.90 Differential Revision: D3527
-rw-r--r--kerfuffle/pluginmanager.cpp13
-rw-r--r--kerfuffle/pluginmanager.h7
2 files changed, 14 insertions, 6 deletions
diff --git a/kerfuffle/pluginmanager.cpp b/kerfuffle/pluginmanager.cpp
index 1cccd76..fd53f0c 100644
--- a/kerfuffle/pluginmanager.cpp
+++ b/kerfuffle/pluginmanager.cpp
@@ -85,9 +85,16 @@ QVector<Plugin*> PluginManager::enabledPlugins() const
return enabledPlugins;
}
-QVector<Plugin*> PluginManager::preferredPluginsFor(const QMimeType &mimeType) const
+QVector<Plugin*> PluginManager::preferredPluginsFor(const QMimeType &mimeType)
{
- return preferredPluginsFor(mimeType, false);
+ const auto mimeName = mimeType.name();
+ if (m_preferredPluginsCache.contains(mimeName)) {
+ return m_preferredPluginsCache.value(mimeName);
+ }
+
+ const auto plugins = preferredPluginsFor(mimeType, false);
+ m_preferredPluginsCache.insert(mimeName, plugins);
+ return plugins;
}
QVector<Plugin*> PluginManager::preferredWritePluginsFor(const QMimeType &mimeType) const
@@ -95,7 +102,7 @@ QVector<Plugin*> PluginManager::preferredWritePluginsFor(const QMimeType &mimeTy
return preferredPluginsFor(mimeType, true);
}
-Plugin *PluginManager::preferredPluginFor(const QMimeType &mimeType) const
+Plugin *PluginManager::preferredPluginFor(const QMimeType &mimeType)
{
const QVector<Plugin*> preferredPlugins = preferredPluginsFor(mimeType);
return preferredPlugins.isEmpty() ? new Plugin() : preferredPlugins.first();
diff --git a/kerfuffle/pluginmanager.h b/kerfuffle/pluginmanager.h
index e32d8fd..eda0bdf 100644
--- a/kerfuffle/pluginmanager.h
+++ b/kerfuffle/pluginmanager.h
@@ -76,10 +76,10 @@ public:
/**
* @return The list of preferred plugins for the given @p mimeType, among all the available ones.
- * The list is sorted according to the plugins priority.
+ * The list is sorted according to the plugins priority. The list is saved in a cache for efficiency.
* If no plugin is available, returns an empty list.
*/
- QVector<Plugin*> preferredPluginsFor(const QMimeType &mimeType) const;
+ QVector<Plugin*> preferredPluginsFor(const QMimeType &mimeType);
/**
* @return The list of preferred read-write plugins for the given @p mimeType, among all the available ones.
@@ -92,7 +92,7 @@ public:
* @return The preferred plugin for the given @p mimeType, among all the available ones.
* If no plugin is available, returns an invalid plugin.
*/
- Plugin *preferredPluginFor(const QMimeType &mimeType) const;
+ Plugin *preferredPluginFor(const QMimeType &mimeType);
/**
* @return The preferred read-write plugin for the given @p mimeType, among all the available ones.
@@ -131,6 +131,7 @@ private:
static QStringList sortByComment(const QSet<QString> &mimeTypes);
QVector<Plugin*> m_plugins;
+ QHash<QString, QVector<Plugin*>> m_preferredPluginsCache;
};
}