aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/memory/qv4heap_p.h
diff options
context:
space:
mode:
authorErik Verbruggen <erik.verbruggen@digia.com>2016-09-07 13:31:14 +0200
committerErik Verbruggen <erik.verbruggen@qt.io>2016-09-27 08:37:39 +0000
commitc08423ac01be53a40226b30e62d2d50d1fca9fd5 (patch)
treebf5803dcfd215b3f53f18e0479971cb2a4d3b5ad /src/qml/memory/qv4heap_p.h
parent480037f2988f5b3010bd6a444cda8e28a24571fd (diff)
QML: Replace QPointer with a QQmlQPointer (which is trivial)
One of the steps needed to make QV4::Heap::structs trivial. Change-Id: Ic4d73f15035af21c8a682aaad1ee68cdd91f8e7d Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Diffstat (limited to 'src/qml/memory/qv4heap_p.h')
-rw-r--r--src/qml/memory/qv4heap_p.h56
1 files changed, 56 insertions, 0 deletions
diff --git a/src/qml/memory/qv4heap_p.h b/src/qml/memory/qv4heap_p.h
index ed7a531766..584e8293e5 100644
--- a/src/qml/memory/qv4heap_p.h
+++ b/src/qml/memory/qv4heap_p.h
@@ -52,6 +52,7 @@
#include <QtCore/QString>
#include <private/qv4global_p.h>
+#include <QSharedPointer>
QT_BEGIN_NAMESPACE
@@ -139,6 +140,61 @@ struct Pointer {
}
+#ifdef QT_NO_QOBJECT
+template <class T>
+struct QQmlQPointer {
+};
+#else
+template <class T>
+struct QQmlQPointer {
+ void init()
+ {
+ d = nullptr;
+ qObject = nullptr;
+ }
+
+ void init(T *o)
+ {
+ Q_ASSERT(d == nullptr);
+ Q_ASSERT(qObject == nullptr);
+ if (o) {
+ d = QtSharedPointer::ExternalRefCountData::getAndRef(o);
+ qObject = o;
+ }
+ }
+
+ void destroy()
+ {
+ if (d && !d->weakref.deref())
+ delete d;
+ d = nullptr;
+ qObject = nullptr;
+ }
+
+ T *data() const {
+ return d == nullptr || d->strongref.load() == 0 ? nullptr : qObject;
+ }
+ operator T*() const { return data(); }
+ inline T* operator->() const { return data(); }
+ QQmlQPointer &operator=(T *o)
+ {
+ if (d)
+ destroy();
+ init(o);
+ return *this;
+ }
+ bool isNull() const Q_DECL_NOTHROW
+ {
+ return d == nullptr || qObject == nullptr || d->strongref.load() == 0;
+ }
+
+private:
+ QtSharedPointer::ExternalRefCountData *d;
+ QObject *qObject;
+};
+Q_STATIC_ASSERT(std::is_trivial<QQmlQPointer<QObject>>::value);
+#endif
+
}
QT_END_NAMESPACE