diff options
author | Fabian Kosmale <fabian.kosmale@qt.io> | 2020-08-18 16:36:53 +0200 |
---|---|---|
committer | Fabian Kosmale <fabian.kosmale@qt.io> | 2020-08-28 00:41:00 +0200 |
commit | 4d5a048d96f1161e2059315d0fe350fdcebb2e05 (patch) | |
tree | af326c4ac72a449d9a168d657a68c96567fe2ca3 /src/corelib/kernel/qobject.cpp | |
parent | 462b36c3dee591bd964670dc614b995ece335331 (diff) |
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 <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/kernel/qobject.cpp')
-rw-r--r-- | src/corelib/kernel/qobject.cpp | 31 |
1 files changed, 16 insertions, 15 deletions
diff --git a/src/corelib/kernel/qobject.cpp b/src/corelib/kernel/qobject.cpp index 1b8646947e..54229a9f71 100644 --- a/src/corelib/kernel/qobject.cpp +++ b/src/corelib/kernel/qobject.cpp @@ -95,28 +95,29 @@ QAbstractDynamicMetaObject::~QAbstractDynamicMetaObject() { } -static int *queuedConnectionTypes(const QList<QByteArray> &typeNames) +static int *queuedConnectionTypes(const QMetaMethod& method) { - int *types = new int [typeNames.count() + 1]; - Q_CHECK_PTR(types); - for (int i = 0; i < typeNames.count(); ++i) { - const QByteArray typeName = typeNames.at(i); - if (typeName.endsWith('*')) - types[i] = QMetaType::VoidStar; + const auto parameterCount = method.parameterCount(); + int *typeIds = new int [parameterCount + 1]; + Q_CHECK_PTR(typeIds); + for (int i = 0; i < parameterCount; ++i) { + const QMetaType metaType = method.parameterMetaType(i); + if (metaType.flags() & QMetaType::IsPointer) + typeIds[i] = QMetaType::VoidStar; else - types[i] = QMetaType::fromName(typeName).id(); - - if (!types[i]) { + typeIds[i] = metaType.id(); + if (!typeIds[i]) { + const QByteArray typeName = method.parameterTypeName(i); qWarning("QObject::connect: Cannot queue arguments of type '%s'\n" "(Make sure '%s' is registered using qRegisterMetaType().)", typeName.constData(), typeName.constData()); - delete [] types; + delete [] typeIds; return nullptr; } } - types[typeNames.count()] = 0; + typeIds[parameterCount] = 0; - return types; + return typeIds; } static int *queuedConnectionTypes(const QArgumentType *argumentTypes, int argc) @@ -2871,7 +2872,7 @@ QMetaObject::Connection QObject::connect(const QObject *sender, const QMetaMetho int *types = nullptr; if ((type == Qt::QueuedConnection) - && !(types = queuedConnectionTypes(signal.parameterTypes()))) + && !(types = queuedConnectionTypes(signal))) return QMetaObject::Connection(nullptr); #ifndef QT_NO_DEBUG @@ -3615,7 +3616,7 @@ static void queued_activate(QObject *sender, int signal, QObjectPrivate::Connect const int *argumentTypes = c->argumentTypes.loadRelaxed(); if (!argumentTypes) { QMetaMethod m = QMetaObjectPrivate::signal(sender->metaObject(), signal); - argumentTypes = queuedConnectionTypes(m.parameterTypes()); + argumentTypes = queuedConnectionTypes(m); if (!argumentTypes) // cannot queue arguments argumentTypes = &DIRECT_CONNECTION_ONLY; if (!c->argumentTypes.testAndSetOrdered(nullptr, argumentTypes)) { |