Commit 7618ea17 authored by Elvis Angelaccio's avatar Elvis Angelaccio
Browse files

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
parent 7a5e4e4c
......@@ -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();
......
......@@ -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;
};
}
......
Supports Markdown
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