summaryrefslogtreecommitdiffstats
path: root/src/corelib/kernel/qobject.cpp
diff options
context:
space:
mode:
authorAhmad Samir <a.samirh78@gmail.com>2023-07-10 18:48:17 +0300
committerAhmad Samir <a.samirh78@gmail.com>2023-07-31 01:52:25 +0300
commitb902b152af0bf144c9c9833502e1dcfae0166620 (patch)
treef0b4c7d96fd59ce9f8136aaa8b4b762daafea719 /src/corelib/kernel/qobject.cpp
parente8e9c287ec6a086a96b36e692ab6d5ed11b64951 (diff)
QObject: replace _q_reregisterTimers with a lambda
- Pass the QList by value, no heap allocation and no plain new/delete - A lambda means that there isn't runtime string-based lookup to find the member method in QObjectPrivate The code is only a couple of lines and used in a single place, so might as well move the code from _q_reregisterTimers to the local lambda. Modify tst_moc to account for the numer of methods in QObjectPrivate changing. The test had hardcoded numbers. Change-Id: I07906fc7138b8e601e4695f8d2de1b5fdd88449c Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/kernel/qobject.cpp')
-rw-r--r--src/corelib/kernel/qobject.cpp22
1 files changed, 7 insertions, 15 deletions
diff --git a/src/corelib/kernel/qobject.cpp b/src/corelib/kernel/qobject.cpp
index baad864a39..002b9bcab1 100644
--- a/src/corelib/kernel/qobject.cpp
+++ b/src/corelib/kernel/qobject.cpp
@@ -1451,8 +1451,13 @@ bool QObject::event(QEvent *e)
Q_ASSERT_X(res, Q_FUNC_INFO,
"QAbstractEventDispatcher::unregisterTimers() returned false,"
" but there are timers associated with this object.");
- QMetaObject::invokeMethod(this, "_q_reregisterTimers", Qt::QueuedConnection,
- Q_ARG(void*, (new QList<QAbstractEventDispatcher::TimerInfo>(timers))));
+ auto reRegisterTimers = [this, timers = std::move(timers)]() {
+ QAbstractEventDispatcher *eventDispatcher =
+ d_func()->threadData.loadRelaxed()->eventDispatcher.loadRelaxed();
+ for (const auto &ti : timers)
+ eventDispatcher->registerTimer(ti.timerId, ti.interval, ti.timerType, this);
+ };
+ QMetaObject::invokeMethod(this, std::move(reRegisterTimers), Qt::QueuedConnection);
}
}
break;
@@ -1808,19 +1813,6 @@ void QObjectPrivate::setThreadData_helper(QThreadData *currentData, QThreadData
}
}
-void QObjectPrivate::_q_reregisterTimers(void *pointer)
-{
- Q_Q(QObject);
- QList<QAbstractEventDispatcher::TimerInfo> *timerList = reinterpret_cast<QList<QAbstractEventDispatcher::TimerInfo> *>(pointer);
- QAbstractEventDispatcher *eventDispatcher = threadData.loadRelaxed()->eventDispatcher.loadRelaxed();
- for (int i = 0; i < timerList->size(); ++i) {
- const QAbstractEventDispatcher::TimerInfo &ti = timerList->at(i);
- eventDispatcher->registerTimer(ti.timerId, ti.interval, ti.timerType, q);
- }
- delete timerList;
-}
-
-
//
// The timer flag hasTimer is set when startTimer is called.
// It is not reset when killing the timer because more than