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 <a.samirh78@gmail.com>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
Marc Mutz 2025-05-23 16:20:13 +02:00
parent 3e98657898
commit e4f8601236

View File

@ -730,6 +730,7 @@ inline int QMetaObjectPrivate::indexOfMethodRelative(const QMetaObject **baseObj
/*! /*!
\fn int QMetaObject::indexOfConstructor(const char *constructor) const
\since 4.5 \since 4.5
Finds \a constructor and returns its index; otherwise returns -1. 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() \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 int QMetaObject::indexOfConstructor(const char *constructor) const
{ {
Q_ASSERT(priv(d.data)->revision >= 7); Q_ASSERT(priv(d.data)->revision >= 7);
QArgumentTypeArray types; int i = indexOfConstructor_helper(this, constructor);
QByteArrayView name = QMetaObjectPrivate::decodeMethodSignature(constructor, types); return i;
return QMetaObjectPrivate::indexOfConstructor(this, name, types.size(), types.constData());
} }
/*! /*!
\fn int QMetaObject::indexOfMethod(const char *method) const
Finds \a method and returns its index; otherwise returns -1. Finds \a method and returns its index; otherwise returns -1.
Note that the \a method has to be in normalized form, as returned 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() \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; int i;
Q_ASSERT(priv(m->d.data)->revision >= 7); Q_ASSERT(priv(m->d.data)->revision >= 7);
QArgumentTypeArray types; QArgumentTypeArray types;
@ -768,6 +778,13 @@ int QMetaObject::indexOfMethod(const char *method) const
return i; 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. // Parses a string of comma-separated types into QArgumentTypes.
// No normalization of the type names is performed. // No normalization of the type names is performed.
static void argumentTypesFromString(const char *str, const char *end, 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. Finds \a signal and returns its index; otherwise returns -1.
This is the same as indexOfMethod(), except that it will return This is the same as indexOfMethod(), except that it will return
@ -820,9 +839,9 @@ QByteArrayView QMetaObjectPrivate::decodeMethodSignature(
\sa indexOfMethod(), normalizedSignature(), method(), methodCount(), methodOffset() \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; int i;
Q_ASSERT(priv(m->d.data)->revision >= 7); Q_ASSERT(priv(m->d.data)->revision >= 7);
QArgumentTypeArray types; QArgumentTypeArray types;
@ -833,6 +852,13 @@ int QMetaObject::indexOfSignal(const char *signal) const
return i; return i;
} }
int QMetaObject::indexOfSignal(const char *signal) const
{
const QMetaObject *m = this;
int i = indexOfSignal_helper(m, signal);
return i;
}
/*! /*!
\internal \internal
Same as QMetaObject::indexOfSignal, but the result is the local offset to the base object. 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. Finds \a slot and returns its index; otherwise returns -1.
This is the same as indexOfMethod(), except that it will return 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() \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; int i;
Q_ASSERT(priv(m->d.data)->revision >= 7); Q_ASSERT(priv(m->d.data)->revision >= 7);
QArgumentTypeArray types; QArgumentTypeArray types;
@ -880,6 +908,13 @@ int QMetaObject::indexOfSlot(const char *slot) const
return i; 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. // same as indexOfSignalRelative but for slots.
int QMetaObjectPrivate::indexOfSlotRelative(const QMetaObject **m, int QMetaObjectPrivate::indexOfSlotRelative(const QMetaObject **m,
QByteArrayView name, int argc, QByteArrayView name, int argc,