From bdbc91cb90e9858cddc23da90ddd659262faa068 Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Wed, 10 Nov 2021 09:42:13 +0100 Subject: 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 --- src/qml/jsruntime/qv4persistent.cpp | 11 ++--------- src/qml/jsruntime/qv4persistent_p.h | 16 +++++++++++++--- 2 files changed, 15 insertions(+), 12 deletions(-) (limited to 'src/qml/jsruntime') 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); -- cgit v1.2.3