aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFabian Kosmale <fabian.kosmale@qt.io>2022-02-15 10:25:45 +0100
committerFabian Kosmale <fabian.kosmale@qt.io>2022-02-21 18:20:56 +0100
commitac4c09ba63f24f78148864f7685301cf304db925 (patch)
treede0f8b8c7e67010dcb90e52e0cd4ade1dac0c6f7
parent214b92b00a2f9c1527401a1a20bfcc2b30e8efab (diff)
Space optimize QQmlStrongJSQObjectReference
We can get rid of the boolean member by reusing the objectDestroyed function pointer. Change-Id: Idb9e4d0ddfb04b109126378a6c18799018c74785 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io> Reviewed-by: Andrei Golubev <andrei.golubev@qt.io> Reviewed-by: Marc Mutz <marc.mutz@qt.io>
-rw-r--r--src/qml/qml/qqmlengine.cpp2
-rw-r--r--src/qml/qml/qqmlguard_p.h22
2 files changed, 20 insertions, 4 deletions
diff --git a/src/qml/qml/qqmlengine.cpp b/src/qml/qml/qqmlengine.cpp
index 54f0698f79..99697f8e1a 100644
--- a/src/qml/qml/qqmlengine.cpp
+++ b/src/qml/qml/qqmlengine.cpp
@@ -1959,6 +1959,8 @@ bool QQml_isFileCaseCorrect(const QString &fileName, int lengthIn /* = -1 */)
\sa {QQmlEngine::contextForObject()}{contextForObject()}, qmlEngine()
*/
+void hasJsOwnershipIndicator(QQmlGuardImpl *) {};
+
QT_END_NAMESPACE
#include "moc_qqmlengine.cpp"
diff --git a/src/qml/qml/qqmlguard_p.h b/src/qml/qml/qqmlguard_p.h
index 4286414bba..9c167b684b 100644
--- a/src/qml/qml/qqmlguard_p.h
+++ b/src/qml/qml/qqmlguard_p.h
@@ -103,6 +103,13 @@ public:
T *data() const noexcept { return object(); }
};
+/* used in QQmlStrongJSQObjectReference to indicate that the
+ * object has JS ownership
+ * We save it in objectDestroyFn to save space
+ * (implemented in qqmlengine.cpp)
+ */
+void Q_QML_PRIVATE_EXPORT hasJsOwnershipIndicator(QQmlGuardImpl *);
+
template <typename T>
class QQmlStrongJSQObjectReference : protected QQmlGuardImpl
{
@@ -115,26 +122,33 @@ public:
T &operator*() const { return *object(); }
operator T *() const noexcept { return object(); }
T *data() const noexcept { return object(); }
+
void setObject(T *obj, QObject *parent) {
T *old = object();
if (obj == old)
return;
- if (m_jsOwnership && old && old->parent() == parent)
+ if (hasJsOwnership() && old && old->parent() == parent)
QQml_setParent_noEvent(old, nullptr);
QQmlGuardImpl::setObject(obj);
if (obj && !obj->parent() && !QQmlData::keepAliveDuringGarbageCollection(obj)) {
- m_jsOwnership = true;
+ setJsOwnership(true);
QQml_setParent_noEvent(obj, parent);
} else {
- m_jsOwnership = false;
+ setJsOwnership(false);
}
}
private:
- bool m_jsOwnership = false;
+ bool hasJsOwnership() {
+ return objectDestroyed == hasJsOwnershipIndicator;
+ }
+
+ void setJsOwnership(bool itHasOwnership) {
+ objectDestroyed = itHasOwnership ? hasJsOwnershipIndicator : nullptr;
+ }
};
QT_END_NAMESPACE