diff options
author | Alexander Golubev <fatzer2@gmail.com> | 2024-03-11 13:47:16 +0300 |
---|---|---|
committer | Alexander Golubev <fatzer2@gmail.com> | 2024-03-16 02:45:44 +0300 |
commit | 3eb9061b6344a1de8973fc14085618b0c46909ae (patch) | |
tree | 1ffd17fa89c50dd1fc338bd1f8af0d2f4dac6294 /src/kernel | |
parent | b930cec6013b9609c4345268171763c2c5936ae4 (diff) | |
download | tqt3-3eb9061b6344a1de8973fc14085618b0c46909ae.tar.gz tqt3-3eb9061b6344a1de8973fc14085618b0c46909ae.zip |
Deduplicate code in TQObject::activate_signal()
According to a benchmark the while() loop with direct use of iterators
were ~10% slower than the current one which handled case when there is
only one connection to a signal separately.
But use of a range-based for loop sped up even this case for ~1.5%.
Closes: https://mirror.git.trinitydesktop.org/gitea/TDE/tqt3/issues/121
Signed-off-by: Alexander Golubev <fatzer2@gmail.com>
Diffstat (limited to 'src/kernel')
-rw-r--r-- | src/kernel/qobject.cpp | 133 |
1 files changed, 30 insertions, 103 deletions
diff --git a/src/kernel/qobject.cpp b/src/kernel/qobject.cpp index 3ab2d9b9..44971cfe 100644 --- a/src/kernel/qobject.cpp +++ b/src/kernel/qobject.cpp @@ -2785,14 +2785,15 @@ void TQObject::activate_signal( TQConnectionList *clist, TQUObject *o ) const TQThread *currentThread = TQThread::currentThreadObject(); #endif // TQT_THREAD_SUPPORT - TQObject *object; - TQSenderObjectList* sol; - TQObject* oldSender = 0; - TQConnection *c; - if ( clist->count() == 1 ) { // save iterator - c = clist->first(); - object = c->object(); - sol = object->senderObjects; + const TQConnection *cd = 0; + for(const TQConnection *c: *clist) { + Q_ASSERT( c ); + if ( c == cd ) + continue; + cd = c; + TQObject *object = c->object(); + TQObject *oldSender; + TQSenderObjectList* sol = object->senderObjects; #ifdef TQT_THREAD_SUPPORT sol->listMutex->lock(); #endif // TQT_THREAD_SUPPORT @@ -2802,13 +2803,12 @@ void TQObject::activate_signal( TQConnectionList *clist, TQUObject *o ) sol->currentSender = this; } if ( c->memberType() == TQ_SIGNAL_CODE ) { -#if !defined(TQT_THREAD_SUPPORT) - object->tqt_emit( c->member(), o ); -#else // defined(TQT_THREAD_SUPPORT) - if ((d->disableThreadPostedEvents) || - (object->d->disableThreadPostedEvents) || - (currentThread && currentThread->threadPostedEventsDisabled()) || - (currentThread && object->d->ownThread == currentThread)) { +#ifdef TQT_THREAD_SUPPORT + if ((d->disableThreadPostedEvents) || + (object->d->disableThreadPostedEvents) || + (currentThread && currentThread->threadPostedEventsDisabled()) || + (currentThread && object->d->ownThread == currentThread) + ) { sol->listMutex->unlock(); object->tqt_emit( c->member(), o ); sol->listMutex->lock(); @@ -2816,21 +2816,22 @@ void TQObject::activate_signal( TQConnectionList *clist, TQUObject *o ) else { if (object->d->ownThread && !object->d->ownThread->finished()) { #ifdef QT_DEBUG - tqDebug("TQObject::activate_signal: Emitting cross-thread signal from object %p (member %d receiver %p) (1)\n", this, c->member(), object); + tqDebug("TQObject::activate_signal: Emitting cross-thread signal from object %p (member %d receiver %p)\n", this, c->member(), object); #endif // QT_DEBUG TQApplication::postEvent(object, new TQMetaCallEvent(c->member(), this, deepCopyTQUObjectArray(o), TQMetaCallEvent::MetaCallEmit)); } } -#endif // !defined(TQT_THREAD_SUPPORT) +#else // !TQT_THREAD_SUPPORT + object->tqt_emit( c->member(), o ); +#endif // TQT_THREAD_SUPPORT } else { -#if !defined(TQT_THREAD_SUPPORT) - object->tqt_invoke( c->member(), o ); -#else // defined(TQT_THREAD_SUPPORT) - if ((d->disableThreadPostedEvents) || - (object->d->disableThreadPostedEvents) || - (currentThread && currentThread->threadPostedEventsDisabled()) || - (currentThread && object->d->ownThread == currentThread)) { +#ifdef TQT_THREAD_SUPPORT + if ((d->disableThreadPostedEvents) || + (object->d->disableThreadPostedEvents) || + (currentThread && currentThread->threadPostedEventsDisabled()) || + (currentThread && object->d->ownThread == currentThread) + ) { sol->listMutex->unlock(); object->tqt_invoke( c->member(), o ); sol->listMutex->lock(); @@ -2838,18 +2839,20 @@ void TQObject::activate_signal( TQConnectionList *clist, TQUObject *o ) else { if (object->d->ownThread && !object->d->ownThread->finished()) { #ifdef QT_DEBUG - tqDebug("TQObject::activate_signal: Invoking cross-thread method from object %p (member %d receiver %p) (1)\n", this, c->member(), object); + tqDebug("TQObject::activate_signal: Invoking cross-thread method from object %p (member %d receiver %p)\n", this, c->member(), object); #endif // QT_DEBUG TQApplication::postEvent(object, new TQMetaCallEvent(c->member(), this, deepCopyTQUObjectArray(o), TQMetaCallEvent::MetaCallInvoke)); } } -#endif // !defined(TQT_THREAD_SUPPORT) +#else // !TQT_THREAD_SUPPORT + object->tqt_invoke( c->member(), o ); +#endif // TQT_THREAD_SUPPORT } if ( sol ) { sol->currentSender = oldSender; if ( sol->deref() ) { #ifdef TQT_THREAD_SUPPORT - sol->listMutex->unlock(); + sol->listMutex->unlock(); #endif // TQT_THREAD_SUPPORT delete sol; sol = NULL; @@ -2858,82 +2861,6 @@ void TQObject::activate_signal( TQConnectionList *clist, TQUObject *o ) #ifdef TQT_THREAD_SUPPORT if (sol) sol->listMutex->unlock(); #endif // TQT_THREAD_SUPPORT - } else { - TQConnection *cd = 0; - TQConnectionListIt it(*clist); - while ( (c=it.current()) ) { - ++it; - if ( c == cd ) - continue; - cd = c; - object = c->object(); - sol = object->senderObjects; -#ifdef TQT_THREAD_SUPPORT - sol->listMutex->lock(); -#endif // TQT_THREAD_SUPPORT - if ( sol ) { - oldSender = sol->currentSender; - sol->ref(); - sol->currentSender = this; - } - if ( c->memberType() == TQ_SIGNAL_CODE ) { -#if !defined(TQT_THREAD_SUPPORT) - object->tqt_emit( c->member(), o ); -#else // defined(TQT_THREAD_SUPPORT) - if ((d->disableThreadPostedEvents) || - (object->d->disableThreadPostedEvents) || - (currentThread && currentThread->threadPostedEventsDisabled()) || - (currentThread && object->d->ownThread == currentThread)) { - sol->listMutex->unlock(); - object->tqt_emit( c->member(), o ); - sol->listMutex->lock(); - } - else { - if (object->d->ownThread && !object->d->ownThread->finished()) { -#ifdef QT_DEBUG - tqDebug("TQObject::activate_signal: Emitting cross-thread signal from object %p (member %d receiver %p) (2)\n", this, c->member(), object); -#endif // QT_DEBUG - TQApplication::postEvent(object, new TQMetaCallEvent(c->member(), this, deepCopyTQUObjectArray(o), TQMetaCallEvent::MetaCallEmit)); - } - } -#endif // !defined(TQT_THREAD_SUPPORT) - } - else { -#if !defined(TQT_THREAD_SUPPORT) - object->tqt_invoke( c->member(), o ); -#else // defined(TQT_THREAD_SUPPORT) - if ((d->disableThreadPostedEvents) || - (object->d->disableThreadPostedEvents) || - (currentThread && currentThread->threadPostedEventsDisabled()) || - (currentThread && object->d->ownThread == currentThread)) { - sol->listMutex->unlock(); - object->tqt_invoke( c->member(), o ); - sol->listMutex->lock(); - } - else { - if (object->d->ownThread && !object->d->ownThread->finished()) { -#ifdef QT_DEBUG - tqDebug("TQObject::activate_signal: Invoking cross-thread method from object %p (member %d receiver %p) (2)\n", this, c->member(), object); -#endif // QT_DEBUG - TQApplication::postEvent(object, new TQMetaCallEvent(c->member(), this, deepCopyTQUObjectArray(o), TQMetaCallEvent::MetaCallInvoke)); - } - } -#endif // !defined(TQT_THREAD_SUPPORT) - } - if (sol ) { - sol->currentSender = oldSender; - if ( sol->deref() ) { -#ifdef TQT_THREAD_SUPPORT - sol->listMutex->unlock(); -#endif // TQT_THREAD_SUPPORT - delete sol; - sol = NULL; - } - } -#ifdef TQT_THREAD_SUPPORT - if (sol) sol->listMutex->unlock(); -#endif // TQT_THREAD_SUPPORT - } } } |