From 7f640aa2ebf02951abc0b5fb874c91b48b0e307f Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Fri, 15 Jul 2022 13:42:23 -0700 Subject: [PATCH] QMetaObject: merge the findMethodCandidates() into the warning function It's only used there anyway. Change-Id: I36b24183fbd041179f2ffffd17021b6768055bfa Reviewed-by: Fabian Kosmale --- src/corelib/kernel/qmetaobject.cpp | 26 ++++++++------------------ 1 file changed, 8 insertions(+), 18 deletions(-) diff --git a/src/corelib/kernel/qmetaobject.cpp b/src/corelib/kernel/qmetaobject.cpp index 5c436b805af..555e49206a5 100644 --- a/src/corelib/kernel/qmetaobject.cpp +++ b/src/corelib/kernel/qmetaobject.cpp @@ -1340,31 +1340,22 @@ QByteArray QMetaObject::normalizedSignature(const char *method) return result; } -/* - Returns the signatures of all methods whose name matches \a nonExistentMember, - or an empty QByteArray if there are no matches. -*/ -static inline QByteArray findMethodCandidates(const QMetaObject *metaObject, const char *nonExistentMember) +Q_DECL_COLD_FUNCTION static inline bool +printMethodNotFoundWarning(const QMetaObject *meta, QLatin1StringView name, qsizetype paramCount, + const char *const *names) { + // now find the candidates we couldn't use QByteArray candidateMessage; - // Prevent full string comparison in every iteration. - const QByteArray memberByteArray = nonExistentMember; - for (int i = 0; i < metaObject->methodCount(); ++i) { - const QMetaMethod method = metaObject->method(i); - if (method.name() == memberByteArray) + for (int i = 0; i < meta->methodCount(); ++i) { + const QMetaMethod method = meta->method(i); + if (method.name() == QByteArrayView(name)) candidateMessage += " " + method.methodSignature() + '\n'; } if (!candidateMessage.isEmpty()) { candidateMessage.prepend("\nCandidates are:\n"); candidateMessage.chop(1); } - return candidateMessage; -} -Q_DECL_COLD_FUNCTION static inline bool -printMethodNotFoundWarning(const QMetaObject *meta, QLatin1StringView name, qsizetype paramCount, - const char *const *names) -{ QVarLengthArray sig; sig.append(name.data(), name.size()); sig.append('('); @@ -1379,8 +1370,7 @@ printMethodNotFoundWarning(const QMetaObject *meta, QLatin1StringView name, qsiz sig.append('\0'); qWarning("QMetaObject::invokeMethod: No such method %s::%s%s", - meta->className(), sig.constData(), - findMethodCandidates(meta, name.data()).constData()); + meta->className(), sig.constData(), candidateMessage.constData()); return false; }