summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAlexander Golubev <fatzer2@gmail.com>2024-03-11 13:47:16 +0300
committerAlexander Golubev <fatzer2@gmail.com>2024-03-11 18:41:57 +0300
commit5a662b671d7e3a891df7dfb17556d309e77e327b (patch)
tree1d153658ff97435c5b350afcfa5884290ba0fb85 /src
parentd8738f551be832cd69b8b382a550819d9b747ad7 (diff)
downloadtqt3-5a662b671d7e3a891df7dfb17556d309e77e327b.tar.gz
tqt3-5a662b671d7e3a891df7dfb17556d309e77e327b.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')
-rw-r--r--src/kernel/qobject.cpp133
1 files changed, 30 insertions, 103 deletions
diff --git a/src/kernel/qobject.cpp b/src/kernel/qobject.cpp
index 3ab2d9b97..44971cfe6 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
- }
}
}