Performance

Summary:
Remove splitting + joining of a string just to remove the beginning of a
string.
Remove double look-up.
Solves Clazy warnings

Reviewers: #frameworks, #plasma, hein

Reviewed By: #plasma, hein

Subscribers: hein, plasma-devel

Tags: #plasma, #frameworks

Differential Revision: https://phabricator.kde.org/D9109
This commit is contained in:
Aleix Pol 2017-12-02 15:52:22 +01:00
parent b8b8a69fd1
commit 1f9b5ed657
17 changed files with 33 additions and 39 deletions

View File

@ -183,7 +183,6 @@ EventPluginsManager::EventPluginsManager(QObject *parent)
} }
m_model = new EventPluginsModel(this); m_model = new EventPluginsModel(this);
Q_EMIT pluginsChanged();
} }
EventPluginsManager::~EventPluginsManager() EventPluginsManager::~EventPluginsManager()

View File

@ -110,7 +110,7 @@ void SortFilterModel::setFilterRegExp(const QString &exp)
return; return;
} }
QSortFilterProxyModel::setFilterRegExp(QRegExp(exp, Qt::CaseInsensitive)); QSortFilterProxyModel::setFilterRegExp(QRegExp(exp, Qt::CaseInsensitive));
filterRegExpChanged(exp); Q_EMIT filterRegExpChanged(exp);
} }
QString SortFilterModel::filterRegExp() const QString SortFilterModel::filterRegExp() const
@ -125,7 +125,7 @@ void SortFilterModel::setFilterString(const QString &filterString)
} }
m_filterString = filterString; m_filterString = filterString;
QSortFilterProxyModel::setFilterFixedString(filterString); QSortFilterProxyModel::setFilterFixedString(filterString);
filterStringChanged(filterString); Q_EMIT filterStringChanged(filterString);
} }
QString SortFilterModel::filterString() const QString SortFilterModel::filterString() const

View File

@ -621,7 +621,7 @@ void FrameSvgItem::applyPrefixes()
} }
bool found = false; bool found = false;
for (const QString &prefix : m_prefixes) { for (const QString &prefix : qAsConst(m_prefixes)) {
if (m_frameSvg->hasElementPrefix(prefix)) { if (m_frameSvg->hasElementPrefix(prefix)) {
m_frameSvg->setElementPrefix(prefix); m_frameSvg->setElementPrefix(prefix);
found = true; found = true;
@ -630,7 +630,7 @@ void FrameSvgItem::applyPrefixes()
} }
if (!found) { if (!found) {
//this setElementPrefix is done to keep the same behavior as before, when it was a simple string //this setElementPrefix is done to keep the same behavior as before, when it was a simple string
m_frameSvg->setElementPrefix(m_prefixes.last()); m_frameSvg->setElementPrefix(m_prefixes.constLast());
} }
if (oldPrefix != m_frameSvg->prefix()) { if (oldPrefix != m_frameSvg->prefix()) {
emit usedPrefixChanged(); emit usedPrefixChanged();

View File

@ -68,7 +68,7 @@ IconItem::IconItem(QQuickItem *parent)
this, &IconItem::updateImplicitSize); this, &IconItem::updateImplicitSize);
connect(this, &QQuickItem::enabledChanged, connect(this, &QQuickItem::enabledChanged,
this, &IconItem::enabledChanged); this, &IconItem::onEnabledChanged);
connect(this, &QQuickItem::windowChanged, connect(this, &QQuickItem::windowChanged,
this, &IconItem::schedulePixmapUpdate); this, &IconItem::schedulePixmapUpdate);
@ -525,7 +525,7 @@ void IconItem::valueChanged(const QVariant &value)
update(); update();
} }
void IconItem::enabledChanged() void IconItem::onEnabledChanged()
{ {
m_allowNextAnimation = true; m_allowNextAnimation = true;
schedulePixmapUpdate(); schedulePixmapUpdate();

View File

@ -190,7 +190,7 @@ private Q_SLOTS:
void schedulePixmapUpdate(); void schedulePixmapUpdate();
void animationFinished(); void animationFinished();
void valueChanged(const QVariant &value); void valueChanged(const QVariant &value);
void enabledChanged(); void onEnabledChanged();
private: private:
void loadPixmap(); void loadPixmap();

View File

@ -57,7 +57,7 @@ QQmlEngine *EngineBookKeeping::engine() const
qWarning() << "No engines found, this should never happen"; qWarning() << "No engines found, this should never happen";
return 0; return 0;
} else { } else {
return m_engines.values().at(0); return *m_engines.constBegin();
} }
} }

View File

@ -45,7 +45,7 @@ QMenuProxy::QMenuProxy(QObject *parent)
KAcceleratorManager::manage(m_menu); KAcceleratorManager::manage(m_menu);
connect(m_menu, &QMenu::triggered, this, &QMenuProxy::itemTriggered); connect(m_menu, &QMenu::triggered, this, &QMenuProxy::itemTriggered);
connect(m_menu, &QMenu::aboutToHide, [ = ]() { connect(m_menu, &QMenu::aboutToHide, this, [ = ]() {
m_status = DialogStatus::Closed; m_status = DialogStatus::Closed;
emit statusChanged(); emit statusChanged();
}); });

View File

@ -148,7 +148,7 @@ void Containment::init()
} }
//HACK: this is valid only in the systray case //HACK: this is valid only in the systray case
connect(this, &Containment::configureRequested, [=] (Plasma::Applet *a) { connect(this, &Containment::configureRequested, this, [=] (Plasma::Applet *a) {
if (Plasma::Applet *p = qobject_cast<Plasma::Applet *>(parent())) { if (Plasma::Applet *p = qobject_cast<Plasma::Applet *>(parent())) {
emit p->containment()->configureRequested(a); emit p->containment()->configureRequested(a);
} }

View File

@ -218,6 +218,11 @@ public:
*/ */
virtual int screenForContainment(const Containment *containment) const; virtual int screenForContainment(const Containment *containment) const;
/**
* @return The type of immutability of this Corona
*/
Types::ImmutabilityType immutability() const;
public Q_SLOTS: public Q_SLOTS:
/** /**
* Load applet layout from a config file. The results will be added to the * Load applet layout from a config file. The results will be added to the
@ -234,11 +239,6 @@ public Q_SLOTS:
*/ */
void saveLayout(const QString &config = QString()) const; void saveLayout(const QString &config = QString()) const;
/**
* @return The type of immutability of this Corona
*/
Types::ImmutabilityType immutability() const;
/** /**
* Sets the immutability type for this Corona (not immutable, * Sets the immutability type for this Corona (not immutable,
* user immutable or system immutable) * user immutable or system immutable)

View File

@ -556,7 +556,7 @@ void DataEnginePrivate::connectSource(DataContainer *s, QObject *visualization,
if (s->d->model) { if (s->d->model) {
QMetaObject::invokeMethod(visualization, "modelChanged", QMetaObject::invokeMethod(visualization, "modelChanged",
Q_ARG(QString, s->objectName()), Q_ARG(QString, s->objectName()),
Q_ARG(QAbstractItemModel *, s->d->model.data())); Q_ARG(QAbstractItemModel*, s->d->model.data()));
} }
s->d->dirty = false; s->d->dirty = false;
} }

View File

@ -191,7 +191,7 @@ void AppletPrivate::init(const QString &_packagePath, const QVariantList &args)
QAction *a = new QAction(QIcon::fromTheme(QStringLiteral("preferences-desktop-default-applications")), i18n("Alternatives..."), q); QAction *a = new QAction(QIcon::fromTheme(QStringLiteral("preferences-desktop-default-applications")), i18n("Alternatives..."), q);
a->setVisible(false); a->setVisible(false);
q->actions()->addAction(QStringLiteral("alternatives"), a); q->actions()->addAction(QStringLiteral("alternatives"), a);
QObject::connect(a, &QAction::triggered,[=] { QObject::connect(a, &QAction::triggered, [this] {
if (q->containment()) { if (q->containment()) {
emit q->containment()->appletAlternativesRequested(q); emit q->containment()->appletAlternativesRequested(q);
} }

View File

@ -67,7 +67,6 @@ public:
void updateActionNames() void updateActionNames()
{ {
QMimeDatabase mimeDb; QMimeDatabase mimeDb;
KService::List apps;
QHash<const Plasma::Applet *, QList<QUrl> >::iterator i; QHash<const Plasma::Applet *, QList<QUrl> >::iterator i;
for (i = urlLists.begin(); i != urlLists.end(); ++i) { for (i = urlLists.begin(); i != urlLists.end(); ++i) {

View File

@ -82,13 +82,13 @@ void StorageJob::start()
QWeakPointer<StorageJob> me(this); QWeakPointer<StorageJob> me(this);
if (operationName() == QLatin1String("save")) { if (operationName() == QLatin1String("save")) {
QMetaObject::invokeMethod(Plasma::StorageThread::self(), "save", Qt::QueuedConnection, Q_ARG(QWeakPointer<StorageJob>, me), Q_ARG(const QVariantMap &, params)); QMetaObject::invokeMethod(Plasma::StorageThread::self(), "save", Qt::QueuedConnection, Q_ARG(QWeakPointer<StorageJob>, me), Q_ARG(QVariantMap, params));
} else if (operationName() == QLatin1String("retrieve")) { } else if (operationName() == QLatin1String("retrieve")) {
QMetaObject::invokeMethod(Plasma::StorageThread::self(), "retrieve", Qt::QueuedConnection, Q_ARG(QWeakPointer<StorageJob>, me), Q_ARG(const QVariantMap &, params)); QMetaObject::invokeMethod(Plasma::StorageThread::self(), "retrieve", Qt::QueuedConnection, Q_ARG(QWeakPointer<StorageJob>, me), Q_ARG(QVariantMap, params));
} else if (operationName() == QLatin1String("delete")) { } else if (operationName() == QLatin1String("delete")) {
QMetaObject::invokeMethod(Plasma::StorageThread::self(), "deleteEntry", Qt::QueuedConnection, Q_ARG(QWeakPointer<StorageJob>, me), Q_ARG(const QVariantMap &, params)); QMetaObject::invokeMethod(Plasma::StorageThread::self(), "deleteEntry", Qt::QueuedConnection, Q_ARG(QWeakPointer<StorageJob>, me), Q_ARG(QVariantMap, params));
} else if (operationName() == QLatin1String("expire")) { } else if (operationName() == QLatin1String("expire")) {
QMetaObject::invokeMethod(Plasma::StorageThread::self(), "expire", Qt::QueuedConnection, Q_ARG(QWeakPointer<StorageJob>, me), Q_ARG(const QVariantMap &, params)); QMetaObject::invokeMethod(Plasma::StorageThread::self(), "expire", Qt::QueuedConnection, Q_ARG(QWeakPointer<StorageJob>, me), Q_ARG(QVariantMap, params));
} else { } else {
setError(true); setError(true);
setResult(false); setResult(false);

View File

@ -145,7 +145,9 @@ void StorageThread::save(QWeakPointer<StorageJob> wcaller, const QVariantMap &pa
const QString key = params.value(QStringLiteral("key")).toString(); const QString key = params.value(QStringLiteral("key")).toString();
if (!key.isEmpty()) { if (!key.isEmpty()) {
caller->data().insert(key, params[QStringLiteral("data")]); QVariantMap data = caller->data();
data.insert(key, params[QStringLiteral("data")]);
caller->setData(data);
} }
it.toFront(); it.toFront();

View File

@ -877,8 +877,8 @@ bool ThemePrivate::eventFilter(QObject *watched, QEvent *event)
colorsChanged(); colorsChanged();
} }
if (event->type() == QEvent::ApplicationFontChange || event->type() == QEvent::FontChange) { if (event->type() == QEvent::ApplicationFontChange || event->type() == QEvent::FontChange) {
defaultFontChanged(); Q_EMIT defaultFontChanged();
smallestFontChanged(); Q_EMIT smallestFontChanged();
} }
} }
return QObject::eventFilter(watched, event); return QObject::eventFilter(watched, event);

View File

@ -108,9 +108,10 @@ QUrl PackageUrlInterceptor::intercept(const QUrl &path, QQmlAbstractUrlIntercept
pkgRoot = QFileInfo(base + QStringLiteral("/plasma/plasmoids/")).canonicalFilePath(); pkgRoot = QFileInfo(base + QStringLiteral("/plasma/plasmoids/")).canonicalFilePath();
if (!pkgRoot.isEmpty() && path.path().startsWith(pkgRoot)) { if (!pkgRoot.isEmpty() && path.path().startsWith(pkgRoot)) {
const QString pkgName = path.path().midRef(pkgRoot.length() + 1).split(QLatin1Char('/')).first().toString(); const QString pkgName = path.path().midRef(pkgRoot.length() + 1).split(QLatin1Char('/')).first().toString();
#warning FIX double look-up
if (PackageUrlInterceptorPrivate::s_packages.contains(pkgName)) { auto it = PackageUrlInterceptorPrivate::s_packages.constFind(pkgName);
package = PackageUrlInterceptorPrivate::s_packages.value(pkgName); if (it != PackageUrlInterceptorPrivate::s_packages.constEnd()) {
package = *it;
} else { } else {
package = Plasma::PluginLoader::self()->loadPackage(QStringLiteral("Plasma/Applet")).kPackage(); package = Plasma::PluginLoader::self()->loadPackage(QStringLiteral("Plasma/Applet")).kPackage();
package.setPath(pkgName); package.setPath(pkgName);
@ -161,15 +162,9 @@ QUrl PackageUrlInterceptor::intercept(const QUrl &path, QQmlAbstractUrlIntercept
//should never happen //should never happen
Q_ASSERT(!relativePath.isEmpty()); Q_ASSERT(!relativePath.isEmpty());
QStringList components = relativePath.split(QLatin1Char('/')); const int firstSlash = relativePath.indexOf(QLatin1Char('/')) + 1;
//a path with less than 2 items should ever happen const QString filename = firstSlash > 0 ? relativePath.mid(firstSlash) : relativePath;
Q_ASSERT(components.count() >= 2); const QUrl ret = QUrl::fromLocalFile(package.filePath(prefixForType(type, filename), filename));
components.pop_front();
//obtain a string in the form foo/bar/baz.qml: ui/ gets discarded
const QString &filename = components.join(QStringLiteral("/"));
QUrl ret = QUrl::fromLocalFile(package.filePath(prefixForType(type, filename), filename));
//qDebug() << "Returning" << ret; //qDebug() << "Returning" << ret;

View File

@ -52,7 +52,6 @@ Q_SIGNALS:
void formFactorChanged(); void formFactorChanged();
void locationChanged(); void locationChanged();
void contextChanged(); void contextChanged();
void uiReadyChanged(bool ready);
private: private:
AppletInterface *m_interface; AppletInterface *m_interface;