From 16e8cf1e6607ae496515edce00a771ad0153b348 Mon Sep 17 00:00:00 2001 From: Milian Wolff Date: Thu, 11 Jan 2018 15:39:35 +0100 Subject: Optimize: use QMetaObject::invokeMethod with functor Summary: When using this method with a string argument, the method would need to be queried every time via QMetaObject::indexOfMethod. Using a functor one can get rid of this, saving a few cycles which can add up when handling many inotify events. Note that the benchmark timing does not really improve significantly. Using a profiler like perf, we do see that less cycles are consumed though. In my measurement, this reduces the cpu cyles by about 2%. Reviewers: dfaure Subscribers: #frameworks Tags: #frameworks Differential Revision: https://phabricator.kde.org/D9823 --- src/lib/io/kdirwatch.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'src/lib/io/kdirwatch.cpp') Rebased by Antonio Larrosa to recover this patch which was later removed by https://cgit.kde.org/kcoreaddons.git/commit/src/lib/io/kdirwatch.cpp?id=026bbfe17707b0f3999b8b461e24480a8a539226 diff --git a/src/lib/io/kdirwatch.cpp b/src/lib/io/kdirwatch.cpp index eb8aeeb..7213ee6 100644 --- a/src/lib/io/kdirwatch.cpp +++ b/src/lib/io/kdirwatch.cpp @@ -1405,16 +1405,28 @@ void KDirWatchPrivate::emitEvent(Entry *e, int event, const QString &fileName) // Emit the signals delayed, to avoid unexpected re-entrance from the slots (#220153) if (event & Deleted) { +#if QT_VERSION < QT_VERSION_CHECK(5, 10, 0) + QMetaObject::invokeMethod(c.instance, "setDeleted", Qt::QueuedConnection, Q_ARG(QString, path)); +#else QMetaObject::invokeMethod(c.instance, [c, path]() { c.instance->setDeleted(path); }, Qt::QueuedConnection); +#endif } if (event & Created) { +#if QT_VERSION < QT_VERSION_CHECK(5, 10, 0) + QMetaObject::invokeMethod(c.instance, "setCreated", Qt::QueuedConnection, Q_ARG(QString, path)); +#else QMetaObject::invokeMethod(c.instance, [c, path]() { c.instance->setCreated(path); }, Qt::QueuedConnection); +#endif // possible emit Change event after creation } if (event & Changed) { +#if QT_VERSION < QT_VERSION_CHECK(5, 10, 0) + QMetaObject::invokeMethod(c.instance, "setDirty", Qt::QueuedConnection, Q_ARG(QString, path)); +#else QMetaObject::invokeMethod(c.instance, [c, path]() { c.instance->setDirty(path); }, Qt::QueuedConnection); +#endif } } } -- cgit v1.1