From 3270c41c1e1f78b403a4d587d726203520eb707b Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Thu, 6 Aug 2009 15:50:49 +1000 Subject: Add a QmlMetaType::typeCategory() method QmlMetaProperty was calling isObject(), isList() and isQmlList() to determine its property category, resulting in acquiring and releasing three locks (one for each call). This call allows QmlMetaProperty to do the same with only one lock. --- src/declarative/qml/qmlmetaproperty.cpp | 25 +++++++++++++++++-------- src/declarative/qml/qmlmetatype.cpp | 16 ++++++++++++++++ src/declarative/qml/qmlmetatype.h | 3 +++ 3 files changed, 36 insertions(+), 8 deletions(-) diff --git a/src/declarative/qml/qmlmetaproperty.cpp b/src/declarative/qml/qmlmetaproperty.cpp index c445599..09ca872 100644 --- a/src/declarative/qml/qmlmetaproperty.cpp +++ b/src/declarative/qml/qmlmetaproperty.cpp @@ -310,14 +310,23 @@ QmlMetaPropertyPrivate::propertyCategory() const category = QmlMetaProperty::Normal; else if (type == qMetaTypeId()) category = QmlMetaProperty::Bindable; - else if (QmlMetaType::isList(type)) - category = QmlMetaProperty::List; - else if (QmlMetaType::isQmlList(type)) - category = QmlMetaProperty::QmlList; - else if (QmlMetaType::isObject(type)) - category = QmlMetaProperty::Object; - else - category = QmlMetaProperty::Normal; + else { + QmlMetaType::TypeCategory tc = QmlMetaType::typeCategory(type); + switch(tc) { + case QmlMetaType::Object: + category = QmlMetaProperty::Object; + break; + case QmlMetaType::QmlList: + category = QmlMetaProperty::QmlList; + break; + case QmlMetaType::List: + category = QmlMetaProperty::List; + break; + case QmlMetaType::Unknown: + category = QmlMetaProperty::Normal; + break; + } + } } return category; } diff --git a/src/declarative/qml/qmlmetatype.cpp b/src/declarative/qml/qmlmetatype.cpp index 29fe026..50bc676 100644 --- a/src/declarative/qml/qmlmetatype.cpp +++ b/src/declarative/qml/qmlmetatype.cpp @@ -794,6 +794,22 @@ QMetaProperty QmlMetaType::property(QObject *obj, const char *name) return metaObject->property(idx); } +QmlMetaType::TypeCategory QmlMetaType::typeCategory(int userType) +{ + if (userType < 0) + return Unknown; + QReadLocker lock(metaTypeDataLock()); + QmlMetaTypeData *data = metaTypeData(); + if (userType < data->objects.size() && data->objects.testBit(userType)) + return Object; + else if (userType < data->qmllists.size() && data->qmllists.testBit(userType)) + return QmlList; + else if (userType < data->lists.size() && data->lists.testBit(userType)) + return List; + else + return Unknown; +} + bool QmlMetaType::isObject(int userType) { QReadLocker lock(metaTypeDataLock()); diff --git a/src/declarative/qml/qmlmetatype.h b/src/declarative/qml/qmlmetatype.h index e023e83..9cbf7f3 100644 --- a/src/declarative/qml/qmlmetatype.h +++ b/src/declarative/qml/qmlmetatype.h @@ -94,6 +94,9 @@ public: static QmlAttachedPropertiesFunc attachedPropertiesFuncById(int); static QmlAttachedPropertiesFunc attachedPropertiesFunc(const QByteArray &); + enum TypeCategory { Unknown, Object, List, QmlList }; + static TypeCategory typeCategory(int); + static bool isInterface(int); static const char *interfaceIId(int); static bool isObject(int); -- cgit v0.12