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>
This commit is contained in:
parent
e8e9c287ec
commit
b902b152af
@ -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
|
||||
|
@ -353,7 +353,6 @@ private:
|
||||
bool doSetProperty(const char *name, const QVariant *lvalue, QVariant *rvalue);
|
||||
|
||||
Q_DISABLE_COPY(QObject)
|
||||
Q_PRIVATE_SLOT(d_func(), void _q_reregisterTimers(void *))
|
||||
|
||||
private:
|
||||
static QMetaObject::Connection connectImpl(const QObject *sender, void **signal,
|
||||
|
@ -140,7 +140,6 @@ public:
|
||||
void setParent_helper(QObject *);
|
||||
void moveToThread_helper();
|
||||
void setThreadData_helper(QThreadData *currentData, QThreadData *targetData, QBindingStatus *status);
|
||||
void _q_reregisterTimers(void *pointer);
|
||||
|
||||
bool isSender(const QObject *receiver, const char *signal) const;
|
||||
QObjectList receiverList(const char *signal) const;
|
||||
|
@ -1589,41 +1589,43 @@ void tst_Moc::specifyMetaTagsFromCmdline() {
|
||||
|
||||
void tst_Moc::invokable()
|
||||
{
|
||||
const int fooIndex = 4;
|
||||
{
|
||||
const QMetaObject &mobj = InvokableBeforeReturnType::staticMetaObject;
|
||||
QCOMPARE(mobj.methodCount(), 6);
|
||||
QCOMPARE(mobj.method(5).methodSignature(), QByteArray("foo()"));
|
||||
QCOMPARE(mobj.methodCount(), 5);
|
||||
QCOMPARE(mobj.method(fooIndex).methodSignature(), QByteArray("foo()"));
|
||||
}
|
||||
|
||||
{
|
||||
const QMetaObject &mobj = InvokableBeforeInline::staticMetaObject;
|
||||
QCOMPARE(mobj.methodCount(), 7);
|
||||
QCOMPARE(mobj.method(5).methodSignature(), QByteArray("foo()"));
|
||||
QCOMPARE(mobj.method(6).methodSignature(), QByteArray("bar()"));
|
||||
QCOMPARE(mobj.methodCount(), 6);
|
||||
QCOMPARE(mobj.method(fooIndex).methodSignature(), QByteArray("foo()"));
|
||||
QCOMPARE(mobj.method(fooIndex + 1).methodSignature(), QByteArray("bar()"));
|
||||
}
|
||||
}
|
||||
|
||||
void tst_Moc::singleFunctionKeywordSignalAndSlot()
|
||||
{
|
||||
const int mySignalIndex = 4;
|
||||
{
|
||||
const QMetaObject &mobj = SingleFunctionKeywordBeforeReturnType::staticMetaObject;
|
||||
QCOMPARE(mobj.methodCount(), 7);
|
||||
QCOMPARE(mobj.method(5).methodSignature(), QByteArray("mySignal()"));
|
||||
QCOMPARE(mobj.method(6).methodSignature(), QByteArray("mySlot()"));
|
||||
QCOMPARE(mobj.methodCount(), 6);
|
||||
QCOMPARE(mobj.method(mySignalIndex).methodSignature(), QByteArray("mySignal()"));
|
||||
QCOMPARE(mobj.method(mySignalIndex + 1).methodSignature(), QByteArray("mySlot()"));
|
||||
}
|
||||
|
||||
{
|
||||
const QMetaObject &mobj = SingleFunctionKeywordBeforeInline::staticMetaObject;
|
||||
QCOMPARE(mobj.methodCount(), 7);
|
||||
QCOMPARE(mobj.method(5).methodSignature(), QByteArray("mySignal()"));
|
||||
QCOMPARE(mobj.method(6).methodSignature(), QByteArray("mySlot()"));
|
||||
QCOMPARE(mobj.methodCount(), 6);
|
||||
QCOMPARE(mobj.method(mySignalIndex).methodSignature(), QByteArray("mySignal()"));
|
||||
QCOMPARE(mobj.method(mySignalIndex + 1).methodSignature(), QByteArray("mySlot()"));
|
||||
}
|
||||
|
||||
{
|
||||
const QMetaObject &mobj = SingleFunctionKeywordAfterInline::staticMetaObject;
|
||||
QCOMPARE(mobj.methodCount(), 7);
|
||||
QCOMPARE(mobj.method(5).methodSignature(), QByteArray("mySignal()"));
|
||||
QCOMPARE(mobj.method(6).methodSignature(), QByteArray("mySlot()"));
|
||||
QCOMPARE(mobj.methodCount(), 6);
|
||||
QCOMPARE(mobj.method(mySignalIndex).methodSignature(), QByteArray("mySignal()"));
|
||||
QCOMPARE(mobj.method(mySignalIndex + 1).methodSignature(), QByteArray("mySlot()"));
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user