From e4f86012360b20938be8f34e6966a577dae6c049 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Fri, 23 May 2025 16:20:13 +0200 Subject: [PATCH] QMetaObject: extract helpers from indexOf*() methods This makes the different functions more similar to each other, thus facilitating adding a warning about non-normalized arguments to them in the next step. Task-number: QTBUG-135572 Pick-to: 6.9 6.8 6.5 Change-Id: Ia2b82928e9a24fb9d43b43933b9a9c5308fa2835 Reviewed-by: Ahmad Samir Reviewed-by: Thiago Macieira --- src/corelib/kernel/qmetaobject.cpp | 53 +++++++++++++++++++++++++----- 1 file changed, 44 insertions(+), 9 deletions(-) diff --git a/src/corelib/kernel/qmetaobject.cpp b/src/corelib/kernel/qmetaobject.cpp index 0201ea56400..4da62b73586 100644 --- a/src/corelib/kernel/qmetaobject.cpp +++ b/src/corelib/kernel/qmetaobject.cpp @@ -730,6 +730,7 @@ inline int QMetaObjectPrivate::indexOfMethodRelative(const QMetaObject **baseObj /*! + \fn int QMetaObject::indexOfConstructor(const char *constructor) const \since 4.5 Finds \a constructor and returns its index; otherwise returns -1. @@ -739,15 +740,24 @@ inline int QMetaObjectPrivate::indexOfMethodRelative(const QMetaObject **baseObj \sa constructor(), constructorCount(), normalizedSignature() */ + +static int indexOfConstructor_helper(const QMetaObject *mo, const char *constructor) +{ + QArgumentTypeArray types; + QByteArrayView name = QMetaObjectPrivate::decodeMethodSignature(constructor, types); + return QMetaObjectPrivate::indexOfConstructor(mo, name, types.size(), types.constData()); +} + int QMetaObject::indexOfConstructor(const char *constructor) const { Q_ASSERT(priv(d.data)->revision >= 7); - QArgumentTypeArray types; - QByteArrayView name = QMetaObjectPrivate::decodeMethodSignature(constructor, types); - return QMetaObjectPrivate::indexOfConstructor(this, name, types.size(), types.constData()); + int i = indexOfConstructor_helper(this, constructor); + return i; } /*! + \fn int QMetaObject::indexOfMethod(const char *method) const + Finds \a method and returns its index; otherwise returns -1. Note that the \a method has to be in normalized form, as returned @@ -755,9 +765,9 @@ int QMetaObject::indexOfConstructor(const char *constructor) const \sa method(), methodCount(), methodOffset(), normalizedSignature() */ -int QMetaObject::indexOfMethod(const char *method) const + +static int indexOfMethod_helper(const QMetaObject *m, const char *method) { - const QMetaObject *m = this; int i; Q_ASSERT(priv(m->d.data)->revision >= 7); QArgumentTypeArray types; @@ -768,6 +778,13 @@ int QMetaObject::indexOfMethod(const char *method) const return i; } +int QMetaObject::indexOfMethod(const char *method) const +{ + const QMetaObject *m = this; + int i = indexOfMethod_helper(m, method); + return i; +} + // Parses a string of comma-separated types into QArgumentTypes. // No normalization of the type names is performed. static void argumentTypesFromString(const char *str, const char *end, @@ -810,6 +827,8 @@ QByteArrayView QMetaObjectPrivate::decodeMethodSignature( } /*! + \fn int QMetaObject::indexOfSignal(const char *signal) const + Finds \a signal and returns its index; otherwise returns -1. This is the same as indexOfMethod(), except that it will return @@ -820,9 +839,9 @@ QByteArrayView QMetaObjectPrivate::decodeMethodSignature( \sa indexOfMethod(), normalizedSignature(), method(), methodCount(), methodOffset() */ -int QMetaObject::indexOfSignal(const char *signal) const + +static int indexOfSignal_helper(const QMetaObject *m, const char *signal) { - const QMetaObject *m = this; int i; Q_ASSERT(priv(m->d.data)->revision >= 7); QArgumentTypeArray types; @@ -833,6 +852,13 @@ int QMetaObject::indexOfSignal(const char *signal) const return i; } +int QMetaObject::indexOfSignal(const char *signal) const +{ + const QMetaObject *m = this; + int i = indexOfSignal_helper(m, signal); + return i; +} + /*! \internal Same as QMetaObject::indexOfSignal, but the result is the local offset to the base object. @@ -860,6 +886,8 @@ int QMetaObjectPrivate::indexOfSignalRelative(const QMetaObject **baseObject, } /*! + \fn int QMetaObject::indexOfSlot(const char *slot) const + Finds \a slot and returns its index; otherwise returns -1. This is the same as indexOfMethod(), except that it will return @@ -867,9 +895,9 @@ int QMetaObjectPrivate::indexOfSignalRelative(const QMetaObject **baseObject, \sa indexOfMethod(), method(), methodCount(), methodOffset() */ -int QMetaObject::indexOfSlot(const char *slot) const + +static int indexOfSlot_helper(const QMetaObject *m, const char *slot) { - const QMetaObject *m = this; int i; Q_ASSERT(priv(m->d.data)->revision >= 7); QArgumentTypeArray types; @@ -880,6 +908,13 @@ int QMetaObject::indexOfSlot(const char *slot) const return i; } +int QMetaObject::indexOfSlot(const char *slot) const +{ + const QMetaObject *m = this; + int i = indexOfSlot_helper(m, slot); + return i; +} + // same as indexOfSignalRelative but for slots. int QMetaObjectPrivate::indexOfSlotRelative(const QMetaObject **m, QByteArrayView name, int argc,