From 1f9b5ed657dfc690a565314bd57aaf84eacc534f Mon Sep 17 00:00:00 2001 From: Aleix Pol Date: Sat, 2 Dec 2017 15:52:22 +0100 Subject: [PATCH] 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 --- .../calendar/eventpluginsmanager.cpp | 1 - src/declarativeimports/core/datamodel.cpp | 4 ++-- src/declarativeimports/core/framesvgitem.cpp | 4 ++-- src/declarativeimports/core/iconitem.cpp | 4 ++-- src/declarativeimports/core/iconitem.h | 2 +- .../plasmacomponentsplugin.cpp | 2 +- .../plasmacomponents/qmenu.cpp | 2 +- src/plasma/containment.cpp | 2 +- src/plasma/corona.h | 10 +++++----- src/plasma/dataengine.cpp | 2 +- src/plasma/private/applet_p.cpp | 2 +- .../private/associatedapplicationmanager.cpp | 1 - src/plasma/private/storage.cpp | 8 ++++---- src/plasma/private/storagethread.cpp | 4 +++- src/plasma/private/theme_p.cpp | 4 ++-- src/plasmaquick/packageurlinterceptor.cpp | 19 +++++++------------ .../qml/plasmoid/declarativeappletscript.h | 1 - 17 files changed, 33 insertions(+), 39 deletions(-) diff --git a/src/declarativeimports/calendar/eventpluginsmanager.cpp b/src/declarativeimports/calendar/eventpluginsmanager.cpp index 72c6aa7b4..c4b46063e 100644 --- a/src/declarativeimports/calendar/eventpluginsmanager.cpp +++ b/src/declarativeimports/calendar/eventpluginsmanager.cpp @@ -183,7 +183,6 @@ EventPluginsManager::EventPluginsManager(QObject *parent) } m_model = new EventPluginsModel(this); - Q_EMIT pluginsChanged(); } EventPluginsManager::~EventPluginsManager() diff --git a/src/declarativeimports/core/datamodel.cpp b/src/declarativeimports/core/datamodel.cpp index 3a3f4f8b1..224e19460 100644 --- a/src/declarativeimports/core/datamodel.cpp +++ b/src/declarativeimports/core/datamodel.cpp @@ -110,7 +110,7 @@ void SortFilterModel::setFilterRegExp(const QString &exp) return; } QSortFilterProxyModel::setFilterRegExp(QRegExp(exp, Qt::CaseInsensitive)); - filterRegExpChanged(exp); + Q_EMIT filterRegExpChanged(exp); } QString SortFilterModel::filterRegExp() const @@ -125,7 +125,7 @@ void SortFilterModel::setFilterString(const QString &filterString) } m_filterString = filterString; QSortFilterProxyModel::setFilterFixedString(filterString); - filterStringChanged(filterString); + Q_EMIT filterStringChanged(filterString); } QString SortFilterModel::filterString() const diff --git a/src/declarativeimports/core/framesvgitem.cpp b/src/declarativeimports/core/framesvgitem.cpp index fd63e1927..b57ca7ba6 100644 --- a/src/declarativeimports/core/framesvgitem.cpp +++ b/src/declarativeimports/core/framesvgitem.cpp @@ -621,7 +621,7 @@ void FrameSvgItem::applyPrefixes() } bool found = false; - for (const QString &prefix : m_prefixes) { + for (const QString &prefix : qAsConst(m_prefixes)) { if (m_frameSvg->hasElementPrefix(prefix)) { m_frameSvg->setElementPrefix(prefix); found = true; @@ -630,7 +630,7 @@ void FrameSvgItem::applyPrefixes() } if (!found) { //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()) { emit usedPrefixChanged(); diff --git a/src/declarativeimports/core/iconitem.cpp b/src/declarativeimports/core/iconitem.cpp index 8e0befe57..20437fc5b 100644 --- a/src/declarativeimports/core/iconitem.cpp +++ b/src/declarativeimports/core/iconitem.cpp @@ -68,7 +68,7 @@ IconItem::IconItem(QQuickItem *parent) this, &IconItem::updateImplicitSize); connect(this, &QQuickItem::enabledChanged, - this, &IconItem::enabledChanged); + this, &IconItem::onEnabledChanged); connect(this, &QQuickItem::windowChanged, this, &IconItem::schedulePixmapUpdate); @@ -525,7 +525,7 @@ void IconItem::valueChanged(const QVariant &value) update(); } -void IconItem::enabledChanged() +void IconItem::onEnabledChanged() { m_allowNextAnimation = true; schedulePixmapUpdate(); diff --git a/src/declarativeimports/core/iconitem.h b/src/declarativeimports/core/iconitem.h index 8b524e7a0..e32da0d1d 100644 --- a/src/declarativeimports/core/iconitem.h +++ b/src/declarativeimports/core/iconitem.h @@ -190,7 +190,7 @@ private Q_SLOTS: void schedulePixmapUpdate(); void animationFinished(); void valueChanged(const QVariant &value); - void enabledChanged(); + void onEnabledChanged(); private: void loadPixmap(); diff --git a/src/declarativeimports/plasmacomponents/plasmacomponentsplugin.cpp b/src/declarativeimports/plasmacomponents/plasmacomponentsplugin.cpp index 26588b8ea..891476565 100644 --- a/src/declarativeimports/plasmacomponents/plasmacomponentsplugin.cpp +++ b/src/declarativeimports/plasmacomponents/plasmacomponentsplugin.cpp @@ -57,7 +57,7 @@ QQmlEngine *EngineBookKeeping::engine() const qWarning() << "No engines found, this should never happen"; return 0; } else { - return m_engines.values().at(0); + return *m_engines.constBegin(); } } diff --git a/src/declarativeimports/plasmacomponents/qmenu.cpp b/src/declarativeimports/plasmacomponents/qmenu.cpp index cc09b557b..96249a8db 100644 --- a/src/declarativeimports/plasmacomponents/qmenu.cpp +++ b/src/declarativeimports/plasmacomponents/qmenu.cpp @@ -45,7 +45,7 @@ QMenuProxy::QMenuProxy(QObject *parent) KAcceleratorManager::manage(m_menu); connect(m_menu, &QMenu::triggered, this, &QMenuProxy::itemTriggered); - connect(m_menu, &QMenu::aboutToHide, [ = ]() { + connect(m_menu, &QMenu::aboutToHide, this, [ = ]() { m_status = DialogStatus::Closed; emit statusChanged(); }); diff --git a/src/plasma/containment.cpp b/src/plasma/containment.cpp index 20d93f403..15b8abadc 100644 --- a/src/plasma/containment.cpp +++ b/src/plasma/containment.cpp @@ -148,7 +148,7 @@ void Containment::init() } //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(parent())) { emit p->containment()->configureRequested(a); } diff --git a/src/plasma/corona.h b/src/plasma/corona.h index e07f707f5..ed8ecaa0e 100644 --- a/src/plasma/corona.h +++ b/src/plasma/corona.h @@ -218,6 +218,11 @@ public: */ virtual int screenForContainment(const Containment *containment) const; + /** + * @return The type of immutability of this Corona + */ + Types::ImmutabilityType immutability() const; + public Q_SLOTS: /** * 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; - /** - * @return The type of immutability of this Corona - */ - Types::ImmutabilityType immutability() const; - /** * Sets the immutability type for this Corona (not immutable, * user immutable or system immutable) diff --git a/src/plasma/dataengine.cpp b/src/plasma/dataengine.cpp index c01f3cf5e..03eef4b1d 100644 --- a/src/plasma/dataengine.cpp +++ b/src/plasma/dataengine.cpp @@ -556,7 +556,7 @@ void DataEnginePrivate::connectSource(DataContainer *s, QObject *visualization, if (s->d->model) { QMetaObject::invokeMethod(visualization, "modelChanged", Q_ARG(QString, s->objectName()), - Q_ARG(QAbstractItemModel *, s->d->model.data())); + Q_ARG(QAbstractItemModel*, s->d->model.data())); } s->d->dirty = false; } diff --git a/src/plasma/private/applet_p.cpp b/src/plasma/private/applet_p.cpp index fd8fd4ed4..a48f521c3 100644 --- a/src/plasma/private/applet_p.cpp +++ b/src/plasma/private/applet_p.cpp @@ -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); a->setVisible(false); q->actions()->addAction(QStringLiteral("alternatives"), a); - QObject::connect(a, &QAction::triggered,[=] { + QObject::connect(a, &QAction::triggered, [this] { if (q->containment()) { emit q->containment()->appletAlternativesRequested(q); } diff --git a/src/plasma/private/associatedapplicationmanager.cpp b/src/plasma/private/associatedapplicationmanager.cpp index 87cbb25c6..f53d68770 100644 --- a/src/plasma/private/associatedapplicationmanager.cpp +++ b/src/plasma/private/associatedapplicationmanager.cpp @@ -67,7 +67,6 @@ public: void updateActionNames() { QMimeDatabase mimeDb; - KService::List apps; QHash >::iterator i; for (i = urlLists.begin(); i != urlLists.end(); ++i) { diff --git a/src/plasma/private/storage.cpp b/src/plasma/private/storage.cpp index 0b1cce540..7e1c6b3b3 100644 --- a/src/plasma/private/storage.cpp +++ b/src/plasma/private/storage.cpp @@ -82,13 +82,13 @@ void StorageJob::start() QWeakPointer me(this); if (operationName() == QLatin1String("save")) { - QMetaObject::invokeMethod(Plasma::StorageThread::self(), "save", Qt::QueuedConnection, Q_ARG(QWeakPointer, me), Q_ARG(const QVariantMap &, params)); + QMetaObject::invokeMethod(Plasma::StorageThread::self(), "save", Qt::QueuedConnection, Q_ARG(QWeakPointer, me), Q_ARG(QVariantMap, params)); } else if (operationName() == QLatin1String("retrieve")) { - QMetaObject::invokeMethod(Plasma::StorageThread::self(), "retrieve", Qt::QueuedConnection, Q_ARG(QWeakPointer, me), Q_ARG(const QVariantMap &, params)); + QMetaObject::invokeMethod(Plasma::StorageThread::self(), "retrieve", Qt::QueuedConnection, Q_ARG(QWeakPointer, me), Q_ARG(QVariantMap, params)); } else if (operationName() == QLatin1String("delete")) { - QMetaObject::invokeMethod(Plasma::StorageThread::self(), "deleteEntry", Qt::QueuedConnection, Q_ARG(QWeakPointer, me), Q_ARG(const QVariantMap &, params)); + QMetaObject::invokeMethod(Plasma::StorageThread::self(), "deleteEntry", Qt::QueuedConnection, Q_ARG(QWeakPointer, me), Q_ARG(QVariantMap, params)); } else if (operationName() == QLatin1String("expire")) { - QMetaObject::invokeMethod(Plasma::StorageThread::self(), "expire", Qt::QueuedConnection, Q_ARG(QWeakPointer, me), Q_ARG(const QVariantMap &, params)); + QMetaObject::invokeMethod(Plasma::StorageThread::self(), "expire", Qt::QueuedConnection, Q_ARG(QWeakPointer, me), Q_ARG(QVariantMap, params)); } else { setError(true); setResult(false); diff --git a/src/plasma/private/storagethread.cpp b/src/plasma/private/storagethread.cpp index fd2d5362e..b8811ac22 100644 --- a/src/plasma/private/storagethread.cpp +++ b/src/plasma/private/storagethread.cpp @@ -145,7 +145,9 @@ void StorageThread::save(QWeakPointer wcaller, const QVariantMap &pa const QString key = params.value(QStringLiteral("key")).toString(); 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(); diff --git a/src/plasma/private/theme_p.cpp b/src/plasma/private/theme_p.cpp index 771fc6968..26a0bba7f 100644 --- a/src/plasma/private/theme_p.cpp +++ b/src/plasma/private/theme_p.cpp @@ -877,8 +877,8 @@ bool ThemePrivate::eventFilter(QObject *watched, QEvent *event) colorsChanged(); } if (event->type() == QEvent::ApplicationFontChange || event->type() == QEvent::FontChange) { - defaultFontChanged(); - smallestFontChanged(); + Q_EMIT defaultFontChanged(); + Q_EMIT smallestFontChanged(); } } return QObject::eventFilter(watched, event); diff --git a/src/plasmaquick/packageurlinterceptor.cpp b/src/plasmaquick/packageurlinterceptor.cpp index ea314b427..09113a6fb 100644 --- a/src/plasmaquick/packageurlinterceptor.cpp +++ b/src/plasmaquick/packageurlinterceptor.cpp @@ -108,9 +108,10 @@ QUrl PackageUrlInterceptor::intercept(const QUrl &path, QQmlAbstractUrlIntercept pkgRoot = QFileInfo(base + QStringLiteral("/plasma/plasmoids/")).canonicalFilePath(); if (!pkgRoot.isEmpty() && path.path().startsWith(pkgRoot)) { const QString pkgName = path.path().midRef(pkgRoot.length() + 1).split(QLatin1Char('/')).first().toString(); -#warning FIX double look-up - if (PackageUrlInterceptorPrivate::s_packages.contains(pkgName)) { - package = PackageUrlInterceptorPrivate::s_packages.value(pkgName); + + auto it = PackageUrlInterceptorPrivate::s_packages.constFind(pkgName); + if (it != PackageUrlInterceptorPrivate::s_packages.constEnd()) { + package = *it; } else { package = Plasma::PluginLoader::self()->loadPackage(QStringLiteral("Plasma/Applet")).kPackage(); package.setPath(pkgName); @@ -161,15 +162,9 @@ QUrl PackageUrlInterceptor::intercept(const QUrl &path, QQmlAbstractUrlIntercept //should never happen Q_ASSERT(!relativePath.isEmpty()); - QStringList components = relativePath.split(QLatin1Char('/')); - //a path with less than 2 items should ever happen - Q_ASSERT(components.count() >= 2); - - 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)); + const int firstSlash = relativePath.indexOf(QLatin1Char('/')) + 1; + const QString filename = firstSlash > 0 ? relativePath.mid(firstSlash) : relativePath; + const QUrl ret = QUrl::fromLocalFile(package.filePath(prefixForType(type, filename), filename)); //qDebug() << "Returning" << ret; diff --git a/src/scriptengines/qml/plasmoid/declarativeappletscript.h b/src/scriptengines/qml/plasmoid/declarativeappletscript.h index cee44faa5..744a52f8a 100644 --- a/src/scriptengines/qml/plasmoid/declarativeappletscript.h +++ b/src/scriptengines/qml/plasmoid/declarativeappletscript.h @@ -52,7 +52,6 @@ Q_SIGNALS: void formFactorChanged(); void locationChanged(); void contextChanged(); - void uiReadyChanged(bool ready); private: AppletInterface *m_interface;