diff options
author | Fabian Kosmale <fabian.kosmale@qt.io> | 2023-03-29 08:45:34 +0200 |
---|---|---|
committer | Fabian Kosmale <fabian.kosmale@qt.io> | 2023-03-29 16:31:59 +0200 |
commit | a163fa3171e4fb8a95da5d64910fa7c7c8c13a37 (patch) | |
tree | 8411c1d0cd690cfe3dbadbc719f391751b7f8ee4 /src/qml/qml/qqmlglobal_p.h | |
parent | 2f56e243b0ae49afb2ff1653f7ad0e2e047f322c (diff) |
qmlobject_cast: Optimize for QQuickItem
Before this change, qmlobject_cast was actually slower than qobject_cast
for the QQuickItem case.
Fix this by basically doing the same check (but using reinterpret_cast
instead of static_cast, as we can only forward declare QQuickItem in
qqmlgobal_p.h.
Change-Id: If98c3047d897671af7d73640e0d523ad7dd3d27a
Reviewed-by: Semih Yavuz <semih.yavuz@qt.io>
Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Diffstat (limited to 'src/qml/qml/qqmlglobal_p.h')
-rw-r--r-- | src/qml/qml/qqmlglobal_p.h | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/src/qml/qml/qqmlglobal_p.h b/src/qml/qml/qqmlglobal_p.h index c3dbc697a3..172ae28e8c 100644 --- a/src/qml/qml/qqmlglobal_p.h +++ b/src/qml/qml/qqmlglobal_p.h @@ -147,6 +147,17 @@ T qmlobject_cast(QObject *object) return nullptr; } +class QQuickItem; +template<> +inline QQuickItem *qmlobject_cast<QQuickItem *>(QObject *object) +{ + if (!object || !object->isQuickItemType()) + return nullptr; + // QQuickItem is incomplete here -> can't use static_cast + // but we don't need any pointer adjustment, so reinterpret is safe + return reinterpret_cast<QQuickItem *>(object); +} + #define IS_SIGNAL_CONNECTED(Sender, SenderType, Name, Arguments) \ do { \ QObject *sender = (Sender); \ |