diff options
author | Ulf Hermann <ulf.hermann@qt.io> | 2021-11-10 09:42:13 +0100 |
---|---|---|
committer | Ulf Hermann <ulf.hermann@qt.io> | 2021-11-12 12:24:29 +0100 |
commit | bdbc91cb90e9858cddc23da90ddd659262faa068 (patch) | |
tree | b166c2b9df84bf99393baa5bfacf14d25c469cb0 /src/qml/jsruntime | |
parent | 21237e40565c1331aab531ae2c262fdc2c96fc53 (diff) |
Fix life cycle methods of various types related to QQmlBind
Code checker complains about the absence of move ctors and operators.
While we're at it, make ctors default where possible, do not use const
rvalue refs, add noexcept where possible, properly disable moving and
copying of QQmlBindEntryContent, and inline the null check of
QV4::PersistentValueStorage::free().
Change-Id: I11b6511f39f3d84479dbacee7f3e3552a5fb2b5a
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'src/qml/jsruntime')
-rw-r--r-- | src/qml/jsruntime/qv4persistent.cpp | 11 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4persistent_p.h | 16 |
2 files changed, 15 insertions, 12 deletions
diff --git a/src/qml/jsruntime/qv4persistent.cpp b/src/qml/jsruntime/qv4persistent.cpp index dea3019ef4..290a1d91c9 100644 --- a/src/qml/jsruntime/qv4persistent.cpp +++ b/src/qml/jsruntime/qv4persistent.cpp @@ -219,11 +219,9 @@ Value *PersistentValueStorage::allocate() return v; } -void PersistentValueStorage::free(Value *v) +void PersistentValueStorage::freeUnchecked(Value *v) { - if (!v) - return; - + Q_ASSERT(v); Page *p = getPage(v); *v = Encode(p->header.freeList); @@ -289,11 +287,6 @@ PersistentValue::PersistentValue(ExecutionEngine *engine, Object *object) *val = object; } -PersistentValue::~PersistentValue() -{ - PersistentValueStorage::free(val); -} - PersistentValue &PersistentValue::operator=(const PersistentValue &other) { if (!val) { diff --git a/src/qml/jsruntime/qv4persistent_p.h b/src/qml/jsruntime/qv4persistent_p.h index 79e8e50790..1437736818 100644 --- a/src/qml/jsruntime/qv4persistent_p.h +++ b/src/qml/jsruntime/qv4persistent_p.h @@ -63,7 +63,11 @@ struct Q_QML_EXPORT PersistentValueStorage ~PersistentValueStorage(); Value *allocate(); - static void free(Value *e); + static void free(Value *v) + { + if (v) + freeUnchecked(v); + } void mark(MarkStack *markStack); @@ -88,18 +92,24 @@ struct Q_QML_EXPORT PersistentValueStorage ExecutionEngine *engine; void *firstPage; private: + static void freeUnchecked(Value *v); static void freePage(void *page); }; class Q_QML_EXPORT PersistentValue { public: - PersistentValue() {} + constexpr PersistentValue() noexcept = default; PersistentValue(const PersistentValue &other); PersistentValue &operator=(const PersistentValue &other); + + PersistentValue(PersistentValue &&other) noexcept : val(std::exchange(other.val, nullptr)) {} + void swap(PersistentValue &other) noexcept { qSwap(val, other.val); } + QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_MOVE_AND_SWAP(PersistentValue); + ~PersistentValue() { PersistentValueStorage::free(val); } + PersistentValue &operator=(const WeakValue &other); PersistentValue &operator=(Object *object); - ~PersistentValue(); PersistentValue(ExecutionEngine *engine, const Value &value); PersistentValue(ExecutionEngine *engine, ReturnedValue value); |