Optimize QObject::senderSignalIndex to only iterate the d->senders once.
QObject::senderSignalIndex is, combined with ::sender(), the current hotspot in the QWebChannel which makes heavy use of it in its 1-to-many QSignalSpy implementation. This patch optimizes the senderSignalIndex by only iterating over the linked senders list once, instead of twice. I.e. it first iterated over it to find the signal index, then again to find the sender to convert to a method-offset. Change-Id: Ic86aed0dce891b87b953a6ec2364a81695bd4876 Reviewed-by: Olivier Goffart <ogoffart@woboq.com> Reviewed-by: Frederik Gladhorn <frederik.gladhorn@digia.com>bb10
parent
955d0df873
commit
9a789a965a
|
|
@ -2327,11 +2327,19 @@ QObject *QObject::sender() const
|
|||
int QObject::senderSignalIndex() const
|
||||
{
|
||||
Q_D(const QObject);
|
||||
int signal_index = d->senderSignalIndex();
|
||||
if (signal_index < 0)
|
||||
return signal_index;
|
||||
// Convert from signal range to method range
|
||||
return QMetaObjectPrivate::signal(sender()->metaObject(), signal_index).methodIndex();
|
||||
|
||||
QMutexLocker locker(signalSlotLock(this));
|
||||
if (!d->currentSender)
|
||||
return -1;
|
||||
|
||||
for (QObjectPrivate::Connection *c = d->senders; c; c = c->next) {
|
||||
if (c->sender == d->currentSender->sender) {
|
||||
// Convert from signal range to method range
|
||||
return QMetaObjectPrivate::signal(c->sender->metaObject(), d->currentSender->signal).methodIndex();
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
/*!
|
||||
|
|
@ -3712,25 +3720,6 @@ void QMetaObject::activate(QObject *sender, int signal_index, void **argv)
|
|||
activate(sender, mo, signal_index - mo->methodOffset(), argv);
|
||||
}
|
||||
|
||||
/*!
|
||||
\internal
|
||||
Implementation of QObject::senderSignalIndex()
|
||||
*/
|
||||
int QObjectPrivate::senderSignalIndex() const
|
||||
{
|
||||
Q_Q(const QObject);
|
||||
QMutexLocker locker(signalSlotLock(q));
|
||||
if (!currentSender)
|
||||
return -1;
|
||||
|
||||
for (QObjectPrivate::Connection *c = senders; c; c = c->next) {
|
||||
if (c->sender == currentSender->sender)
|
||||
return currentSender->signal;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
/*!
|
||||
\internal
|
||||
Returns the signal index used in the internal connectionLists vector.
|
||||
|
|
|
|||
|
|
@ -199,7 +199,6 @@ public:
|
|||
return o->d_func();
|
||||
}
|
||||
|
||||
int senderSignalIndex() const;
|
||||
int signalIndex(const char *signalName, const QMetaObject **meta = 0) const;
|
||||
inline bool isSignalConnected(uint signalIdx) const;
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue