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);
Q_EMIT pluginsChanged();
}
EventPluginsManager::~EventPluginsManager()

View File

@ -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

View File

@ -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();

View File

@ -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();

View File

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

View File

@ -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();
}
}

View File

@ -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();
});

View File

@ -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<Plasma::Applet *>(parent())) {
emit p->containment()->configureRequested(a);
}

View File

@ -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)

View File

@ -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;
}

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);
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);
}

View File

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

View File

@ -82,13 +82,13 @@ void StorageJob::start()
QWeakPointer<StorageJob> me(this);
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")) {
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")) {
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")) {
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 {
setError(true);
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();
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();

View File

@ -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);

View File

@ -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;

View File

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