diff options
| author | Ahmad Samir <a.samirh78@gmail.com> | 2025-08-18 23:33:49 +0300 |
|---|---|---|
| committer | Ahmad Samir <a.samirh78@gmail.com> | 2025-09-30 21:56:49 +0300 |
| commit | 612009956459cc907c90707889f6e496ad1af7da (patch) | |
| tree | 5a66e2f3a9382987ce159a15b0c053ac6929b4b9 /src/corelib/kernel/qobject.cpp | |
| parent | e49ad95bb6e668aabf25f2bec3ab58afd7379bca (diff) | |
QObject: disconnect(): optimize finding the index of `method`
If `method` is wrapped in the SLOT() macro, we can skip searching
signals by using indexOfSlot().
Note that the string-based connect() overload uses the same technique.
In disconnect() there is one more usage of indexOfMethod(), but the
whole `try` block containing it will be refactored in a subsequent
commit.
Use a named-lambda, because it'll be re-used in later commits.
Task-number: QTBUG-139128
Change-Id: I7ac8417bf90e7f15c121163e4167af5ec2e00c9f
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/kernel/qobject.cpp')
| -rw-r--r-- | src/corelib/kernel/qobject.cpp | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/src/corelib/kernel/qobject.cpp b/src/corelib/kernel/qobject.cpp index 374741cb754..0c84b53fe88 100644 --- a/src/corelib/kernel/qobject.cpp +++ b/src/corelib/kernel/qobject.cpp @@ -3350,6 +3350,17 @@ bool QObject::disconnect(const QObject *sender, const char *signal, } } + auto getMethodIndex = [](int code, const QMetaObject *mo, QByteArrayView name, + const QArgumentTypeArray &types) { + switch (code) { + case QSLOT_CODE: + return QMetaObjectPrivate::indexOfSlot(mo, name, types); + case QSIGNAL_CODE: + return QMetaObjectPrivate::indexOfSignal(mo, name, types); + } + return -1; + }; + QByteArray pinnedMethod; bool method_found = false; if (method) { @@ -3396,8 +3407,7 @@ bool QObject::disconnect(const QObject *sender, const char *signal, } else { const QMetaObject *rmeta = receiver->metaObject(); do { - int method_index = QMetaObjectPrivate::indexOfMethod( - rmeta, methodName, methodTypes); + int method_index = getMethodIndex(membcode, rmeta, methodName, methodTypes); if (method_index >= 0) while (method_index < rmeta->methodOffset()) rmeta = rmeta->superClass(); |
