aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/qml/qqml.h
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2019-05-16 14:15:06 +0200
committerUlf Hermann <ulf.hermann@qt.io>2019-05-16 13:34:40 +0000
commit1ee7afa50fe5fe995008dee5d00638b894145d12 (patch)
tree57ac72567cfb3ded8605affa8e82dfc59837bc43 /src/qml/qml/qqml.h
parentacc3d31f7069a244c32fca01f8a2873e0798c785 (diff)
Re-add cache for looking up attached properties objects
c018df5b4075ae962966d4df7653d476dab02840 removed an optimization in qmlAttachedPropertiesObject. The attached properties ID was implicitly cached as it was static in a method templated by the type the attached properties were registered for. We don't actually need the ID for this, as we can also cache the function pointer. Fixes: QTBUG-75609 Change-Id: I15e728ce4bbb89062a84ee6f113b1188faa32b92 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Diffstat (limited to 'src/qml/qml/qqml.h')
-rw-r--r--src/qml/qml/qqml.h9
1 files changed, 6 insertions, 3 deletions
diff --git a/src/qml/qml/qqml.h b/src/qml/qml/qqml.h
index 9eacc5bc22..ebf4817b4a 100644
--- a/src/qml/qml/qqml.h
+++ b/src/qml/qml/qqml.h
@@ -605,9 +605,12 @@ Q_QML_EXPORT void qmlRegisterModule(const char *uri, int versionMajor, int versi
template<typename T>
QObject *qmlAttachedPropertiesObject(const QObject *obj, bool create = true)
{
- QObject *mutableObj = const_cast<QObject *>(obj);
- return qmlAttachedPropertiesObject(
- mutableObj, qmlAttachedPropertiesFunction(mutableObj, &T::staticMetaObject), create);
+ // We don't need a concrete object to resolve the function. As T is a C++ type, it and all its
+ // super types should be registered as CppType (or not at all). We only need the object and its
+ // QML engine to resolve composite types. Therefore, the function is actually a static property
+ // of the C++ type system and we can cache it here for improved performance on further lookups.
+ static const auto func = qmlAttachedPropertiesFunction(nullptr, &T::staticMetaObject);
+ return qmlAttachedPropertiesObject(const_cast<QObject *>(obj), func, create);
}
Q_QML_EXPORT void qmlRegisterBaseTypes(const char *uri, int versionMajor, int versionMinor);