Commit a46179d9 authored by Kevin Funk's avatar Kevin Funk

Perf: Do expensive regexp construction earlier

Summary:
SystemTray::serviceRegistered is called tons of times; the regexp
construction inside the for-loop is expensive and should be avoided.
Thus construct the regexp once, and re-use the regexp object each time.

Test Plan:
Before:
{F6432674}

After:
{F6432675}

Reviewers: davidedmundson

Reviewed By: davidedmundson

Subscribers: apol, plasma-devel

Tags: #plasma

Differential Revision: https://phabricator.kde.org/D17025
parent e2ba40a4
......@@ -85,7 +85,9 @@ void SystemTray::init()
const QString dbusactivation = info.value(QStringLiteral("X-Plasma-DBusActivationService"));
if (!dbusactivation.isEmpty()) {
qCDebug(SYSTEM_TRAY) << "ST Found DBus-able Applet: " << info.pluginId() << dbusactivation;
m_dbusActivatableTasks[info.pluginId()] = dbusactivation;
QRegExp rx(dbusactivation);
rx.setPatternSyntax(QRegExp::Wildcard);
m_dbusActivatableTasks[info.pluginId()] = rx;
}
}
}
......@@ -541,9 +543,7 @@ void SystemTray::serviceRegistered(const QString &service)
continue;
}
const QString &pattern = it.value();
QRegExp rx(pattern);
rx.setPatternSyntax(QRegExp::Wildcard);
const auto &rx = it.value();
if (rx.exactMatch(service)) {
//qCDebug(SYSTEM_TRAY) << "ST : DBus service " << m_dbusActivatableTasks[plugin] << "appeared. Loading " << plugin;
newTask(plugin);
......@@ -562,9 +562,7 @@ void SystemTray::serviceUnregistered(const QString &service)
continue;
}
const QString &pattern = it.value();
QRegExp rx(pattern);
rx.setPatternSyntax(QRegExp::Wildcard);
const auto &rx = it.value();
if (rx.exactMatch(service)) {
m_dbusServiceCounts[plugin]--;
Q_ASSERT(m_dbusServiceCounts[plugin] >= 0);
......
......@@ -22,6 +22,8 @@
#define SYSTEMTRAY_H
#include <QAbstractItemModel>
#include <QRegExp>
#include <Plasma/Containment>
class QDBusPendingCallWatcher;
......@@ -114,7 +116,7 @@ private:
void initDBusActivatables();
QStringList m_defaultPlasmoids;
QHash<QString /*plugin name*/, KPluginInfo> m_systrayApplets;
QHash<QString /*plugin name*/, QString /*DBus Service*/> m_dbusActivatableTasks;
QHash<QString /*plugin name*/, QRegExp /*DBus Service*/> m_dbusActivatableTasks;
QStringList m_allowedPlasmoids;
PlasmoidModel *m_availablePlasmoidsModel;
......
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