diff options
Diffstat (limited to 'src/qml/qml/qqmlpropertycache.cpp')
-rw-r--r-- | src/qml/qml/qqmlpropertycache.cpp | 79 |
1 files changed, 37 insertions, 42 deletions
diff --git a/src/qml/qml/qqmlpropertycache.cpp b/src/qml/qml/qqmlpropertycache.cpp index 93c6aa1f00..af6cd9285b 100644 --- a/src/qml/qml/qqmlpropertycache.cpp +++ b/src/qml/qml/qqmlpropertycache.cpp @@ -176,19 +176,11 @@ void QQmlPropertyData::load(const QMetaMethod &m) flags |= IsFunction; if (m.methodType() == QMetaMethod::Signal) flags |= IsSignal; - propType = QVariant::Invalid; - - const char *returnType = m.typeName(); - if (returnType) - propType = QMetaType::type(returnType); + propType = m.returnType(); - const char *signature = m.signature(); - while (*signature != '(') { Q_ASSERT(*signature != 0); ++signature; } - - ++signature; - if (*signature != ')') { + if (m.parameterCount()) { flags |= HasArguments; - if (0 == ::strcmp(signature, "QQmlV8Function*)")) { + if ((m.parameterCount() == 1) && (m.parameterTypes().first() == "QQmlV8Function*")) { flags |= IsV8Function; } } @@ -212,13 +204,9 @@ void QQmlPropertyData::lazyLoad(const QMetaMethod &m) flags |= NotFullyResolved; } - const char *signature = m.signature(); - while (*signature != '(') { Q_ASSERT(*signature != 0); ++signature; } - - ++signature; - if (*signature != ')') { + if (m.parameterCount()) { flags |= HasArguments; - if (0 == ::strcmp(signature, "QQmlV8Function*)")) { + if ((m.parameterCount() == 1) && (m.parameterTypes().first() == "QQmlV8Function*")) { flags |= IsV8Function; } } @@ -414,10 +402,17 @@ void QQmlPropertyCache::append(QQmlEngine *engine, const QMetaObject *metaObject continue; // Extract method name - const char *signature = m.signature(); + const char *signature; + if (QMetaObjectPrivate::get(metaObject)->revision >= 7) { + // Safe to use the raw name pointer + signature = m.name().constData(); + } else { + // Safe to use the raw signature pointer + signature = m.methodSignature().constData(); + } const char *cptr = signature; char utf8 = 0; - while (*cptr != '(') { + while (*cptr && *cptr != '(') { Q_ASSERT(*cptr != 0); utf8 |= *cptr & 0x80; ++cptr; @@ -663,11 +658,7 @@ QString QQmlPropertyData::name(const QMetaObject *metaObject) if (flags & IsFunction) { QMetaMethod m = metaObject->method(coreIndex); - QString name = QString::fromUtf8(m.signature()); - int parenIdx = name.indexOf(QLatin1Char('(')); - if (parenIdx != -1) - name = name.left(parenIdx); - return name; + return QString::fromUtf8(m.name().constData()); } else { QMetaProperty p = metaObject->property(coreIndex); return QString::fromUtf8(p.name()); @@ -727,15 +718,19 @@ int *QQmlPropertyCache::methodParameterTypes(QObject *object, int index, const QMetaObject *metaObject = object->metaObject(); QMetaMethod m = metaObject->method(index); - QList<QByteArray> argTypeNames = m.parameterTypes(); - A *args = static_cast<A *>(malloc(sizeof(A) + (argTypeNames.count() + 1) * sizeof(int))); - args->arguments[0] = argTypeNames.count(); + int argc = m.parameterCount(); + A *args = static_cast<A *>(malloc(sizeof(A) + (argc + 1) * sizeof(int))); + args->arguments[0] = argc; + QList<QByteArray> argTypeNames; // Only loaded if needed - for (int ii = 0; ii < argTypeNames.count(); ++ii) { - int type = QMetaType::type(argTypeNames.at(ii)); - if (type == QVariant::Invalid) + for (int ii = 0; ii < argc; ++ii) { + int type = m.parameterType(ii); + if (type == QVariant::Invalid) { + if (argTypeNames.isEmpty()) + argTypeNames = m.parameterTypes(); type = EnumType(object->metaObject(), argTypeNames.at(ii)); + } if (type == QVariant::Invalid) { if (unknownTypeError) *unknownTypeError = argTypeNames.at(ii); free(args); @@ -751,14 +746,18 @@ int *QQmlPropertyCache::methodParameterTypes(QObject *object, int index, } else { QMetaMethod m = object->metaObject()->method(index); - QList<QByteArray> argTypeNames = m.parameterTypes(); - dummy.resize(argTypeNames.count() + 1); - dummy[0] = argTypeNames.count(); + int argc = m.parameterCount(); + dummy.resize(argc + 1); + dummy[0] = argc; + QList<QByteArray> argTypeNames; // Only loaded if needed - for (int ii = 0; ii < argTypeNames.count(); ++ii) { - int type = QMetaType::type(argTypeNames.at(ii)); - if (type == QVariant::Invalid) + for (int ii = 0; ii < argc; ++ii) { + int type = m.parameterType(ii); + if (type == QVariant::Invalid) { + if (argTypeNames.isEmpty()) + argTypeNames = m.parameterTypes(); type = EnumType(object->metaObject(), argTypeNames.at(ii)); + } if (type == QVariant::Invalid) { if (unknownTypeError) *unknownTypeError = argTypeNames.at(ii); return 0; @@ -804,13 +803,9 @@ QQmlPropertyData qQmlPropertyCacheCreate(const QMetaObject *metaObject, QMetaMethod m = metaObject->method(ii); if (m.access() == QMetaMethod::Private) continue; - QString methodName = QString::fromUtf8(m.signature()); - - int parenIdx = methodName.indexOf(QLatin1Char('(')); - Q_ASSERT(parenIdx != -1); - QStringRef methodNameRef = methodName.leftRef(parenIdx); + QString methodName = QString::fromUtf8(m.name().constData()); - if (methodNameRef == property) { + if (methodName == property) { rv.load(m); return rv; } |