From 4d5a048d96f1161e2059315d0fe350fdcebb2e05 Mon Sep 17 00:00:00 2001 From: Fabian Kosmale Date: Tue, 18 Aug 2020 16:36:53 +0200 Subject: Improve connect: Use existing metatypes if possible As there is now a chance that a QMetaMethod already contains the metatypes for its arguments, we can just query it directly (and use the fallback to name lookup logic that already exists there). This also allows us to avoid creating a QList of names, and only requires us to do a name lookup in case the connection actually fails. Change-Id: Idda30bc4b538a94476ae6c533776c22340f0030d Reviewed-by: Thiago Macieira --- src/corelib/kernel/qmetaobject.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'src/corelib/kernel/qmetaobject.cpp') diff --git a/src/corelib/kernel/qmetaobject.cpp b/src/corelib/kernel/qmetaobject.cpp index e584fbba8e..f0cef22b6f 100644 --- a/src/corelib/kernel/qmetaobject.cpp +++ b/src/corelib/kernel/qmetaobject.cpp @@ -207,6 +207,7 @@ public: inline uint parameterTypeInfo(int index) const; inline int parameterType(int index) const; inline void getParameterTypes(int *types) const; + inline QByteArray parameterTypeName(int index) const; inline QList parameterTypes() const; inline QList parameterNames() const; inline QByteArray tag() const; @@ -1780,6 +1781,12 @@ void QMetaMethodPrivate::getParameterTypes(int *types) const } } +QByteArray QMetaMethodPrivate::parameterTypeName(int index) const +{ + int paramsIndex = parametersDataIndex(); + return typeNameFromTypeInfo(mobj, mobj->d.data[paramsIndex + index]); +} + QList QMetaMethodPrivate::parameterTypes() const { Q_ASSERT(priv(mobj->d.data)->revision >= 7); @@ -1960,6 +1967,20 @@ QList QMetaMethod::parameterTypes() const return QMetaMethodPrivate::get(this)->parameterTypes(); } +/*! + \since 6.0 + Returns the name of the type at position \a index + If there is no parameter at \a index, returns an empty QByteArray + + \sa parameterNames() + */ +QByteArray QMetaMethod::parameterTypeName(int index) const +{ + if (!mobj || index < 0 || index >= parameterCount()) + return {}; + return QMetaMethodPrivate::get(this)->parameterTypeName(index); +} + /*! Returns a list of parameter names. -- cgit v1.2.3