aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2021-11-10 09:42:13 +0100
committerUlf Hermann <ulf.hermann@qt.io>2021-11-12 12:24:29 +0100
commitbdbc91cb90e9858cddc23da90ddd659262faa068 (patch)
treeb166c2b9df84bf99393baa5bfacf14d25c469cb0
parent21237e40565c1331aab531ae2c262fdc2c96fc53 (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>
-rw-r--r--src/qml/jsruntime/qv4persistent.cpp11
-rw-r--r--src/qml/jsruntime/qv4persistent_p.h16
-rw-r--r--src/qml/qml/ftw/qbipointer_p.h30
-rw-r--r--src/qml/qml/qqmlanybinding_p.h41
-rw-r--r--src/qml/qml/qqmlproperty.cpp5
-rw-r--r--src/qml/qml/qqmlproperty.h6
-rw-r--r--src/qml/types/qqmlbind.cpp8
7 files changed, 51 insertions, 66 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);
diff --git a/src/qml/qml/ftw/qbipointer_p.h b/src/qml/qml/ftw/qbipointer_p.h
index 009f371846..781b0a24d5 100644
--- a/src/qml/qml/ftw/qbipointer_p.h
+++ b/src/qml/qml/ftw/qbipointer_p.h
@@ -79,10 +79,15 @@ template <> struct QFlagPointerAlignment<void>
template<typename T, typename T2>
class QBiPointer {
public:
- inline QBiPointer();
+ constexpr QBiPointer() noexcept = default;
+ ~QBiPointer() noexcept = default;
+ QBiPointer(const QBiPointer &o) noexcept = default;
+ QBiPointer(QBiPointer &&o) noexcept = default;
+ QBiPointer<T, T2> &operator=(const QBiPointer<T, T2> &o) noexcept = default;
+ QBiPointer<T, T2> &operator=(QBiPointer<T, T2> &&o) noexcept = default;
+
inline QBiPointer(T *);
inline QBiPointer(T2 *);
- inline QBiPointer(const QBiPointer<T, T2> &o);
inline bool isNull() const;
inline bool isT1() const;
@@ -93,7 +98,6 @@ public:
inline void clearFlag();
inline void setFlagValue(bool);
- inline QBiPointer<T, T2> &operator=(const QBiPointer<T, T2> &o);
inline QBiPointer<T, T2> &operator=(T *);
inline QBiPointer<T, T2> &operator=(T2 *);
@@ -112,7 +116,7 @@ public:
return !(ptr1 == ptr2);
}
- friend inline void swap(QBiPointer<T, T2> ptr1, QBiPointer<T, T2> ptr2)
+ friend inline void swap(QBiPointer<T, T2> &ptr1, QBiPointer<T, T2> &ptr2) noexcept
{
qSwap(ptr1.ptr_value, ptr2.ptr_value);
}
@@ -129,11 +133,6 @@ private:
};
template<typename T, typename T2>
-QBiPointer<T, T2>::QBiPointer()
-{
-}
-
-template<typename T, typename T2>
QBiPointer<T, T2>::QBiPointer(T *v)
: ptr_value(quintptr(v))
{
@@ -152,12 +151,6 @@ QBiPointer<T, T2>::QBiPointer(T2 *v)
}
template<typename T, typename T2>
-QBiPointer<T, T2>::QBiPointer(const QBiPointer<T, T2> &o)
-: ptr_value(o.ptr_value)
-{
-}
-
-template<typename T, typename T2>
bool QBiPointer<T, T2>::isNull() const
{
return 0 == (ptr_value & (~FlagsMask));
@@ -201,13 +194,6 @@ void QBiPointer<T, T2>::setFlagValue(bool v)
}
template<typename T, typename T2>
-QBiPointer<T, T2> &QBiPointer<T, T2>::operator=(const QBiPointer<T, T2> &o)
-{
- ptr_value = o.ptr_value;
- return *this;
-}
-
-template<typename T, typename T2>
QBiPointer<T, T2> &QBiPointer<T, T2>::operator=(T *o)
{
Q_ASSERT((quintptr(o) & FlagsMask) == 0);
diff --git a/src/qml/qml/qqmlanybinding_p.h b/src/qml/qml/qqmlanybinding_p.h
index a83d4f3752..6e5d35b4b3 100644
--- a/src/qml/qml/qqmlanybinding_p.h
+++ b/src/qml/qml/qqmlanybinding_p.h
@@ -78,10 +78,9 @@
class QQmlAnyBinding {
public:
- QQmlAnyBinding() = default;
+ constexpr QQmlAnyBinding() noexcept = default;
QQmlAnyBinding(std::nullptr_t) : d(static_cast<QQmlAbstractBinding *>(nullptr)) {}
-
/*!
\internal
Returns the binding of the property \a prop as a QQmlAnyBinding.
@@ -286,7 +285,7 @@ public:
Stores a null binding. For purpose of classification, the null bindings is
treated as a QQmlAbstractPropertyBindings.
*/
- QQmlAnyBinding& operator=(std::nullptr_t )
+ QQmlAnyBinding &operator=(std::nullptr_t)
{
clear();
return *this;
@@ -341,7 +340,7 @@ public:
\internal
Stores \a binding and keeps a reference to it.
*/
- QQmlAnyBinding& operator=(QQmlAbstractBinding *binding)
+ QQmlAnyBinding &operator=(QQmlAbstractBinding *binding)
{
clear();
if (binding) {
@@ -355,7 +354,7 @@ public:
\internal
Stores the binding stored in \a binding and keeps a reference to it.
*/
- QQmlAnyBinding& operator=(const QQmlAbstractBinding::Ptr &binding)
+ QQmlAnyBinding &operator=(const QQmlAbstractBinding::Ptr &binding)
{
clear();
if (binding) {
@@ -369,7 +368,7 @@ public:
\internal
Stores \a binding's binding, taking ownership from \a binding.
*/
- QQmlAnyBinding& operator=(QQmlAbstractBinding::Ptr &&binding)
+ QQmlAnyBinding &operator=(QQmlAbstractBinding::Ptr &&binding)
{
clear();
if (binding) {
@@ -382,7 +381,7 @@ public:
\internal
Stores the binding stored in \a untypedBinding and keeps a reference to it.
*/
- QQmlAnyBinding& operator=(const QUntypedPropertyBinding &untypedBinding)
+ QQmlAnyBinding &operator=(const QUntypedPropertyBinding &untypedBinding)
{
clear();
auto binding = QPropertyBindingPrivate::get(untypedBinding);
@@ -398,7 +397,7 @@ public:
\overload
Stores the binding stored in \a untypedBinding, taking ownership from it.
*/
- QQmlAnyBinding& operator=(const QUntypedPropertyBinding &&untypedBinding)
+ QQmlAnyBinding &operator=(QUntypedPropertyBinding &&untypedBinding)
{
clear();
auto binding = QPropertyBindingPrivate::get(untypedBinding);
@@ -409,17 +408,17 @@ public:
return *this;
}
- QQmlAnyBinding(const QQmlAnyBinding &other)
- {
- *this = other;
- }
+ QQmlAnyBinding(QQmlAnyBinding &&other) noexcept
+ : d(std::exchange(other.d, QBiPointer<QQmlAbstractBinding, QPropertyBindingPrivate>()))
+ {}
- friend void swap(const QQmlAnyBinding &a, const QQmlAnyBinding &b)
- {
- qSwap(a.d, b.d);
- }
+ QQmlAnyBinding(const QQmlAnyBinding &other) noexcept { *this = other; }
+ QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_MOVE_AND_SWAP(QQmlAnyBinding)
+
+ friend void swap(QQmlAnyBinding &a, QQmlAnyBinding &b) noexcept { qSwap(a.d, b.d); }
+ void swap(QQmlAnyBinding &other) noexcept { qSwap(d, other.d); }
- QQmlAnyBinding& operator=(const QQmlAnyBinding &other)
+ QQmlAnyBinding &operator=(const QQmlAnyBinding &other) noexcept
{
clear();
if (auto abstractBinding = other.asAbstractBinding())
@@ -439,11 +438,9 @@ public:
return p1.d != p2.d;
}
- ~QQmlAnyBinding() {
- clear();
- }
+ ~QQmlAnyBinding() noexcept { clear(); }
private:
- void clear() {
+ void clear() noexcept {
if (d.isNull())
return;
if (d.isT1()) {
@@ -458,7 +455,7 @@ private:
}
d = static_cast<QQmlAbstractBinding *>(nullptr);
}
- QBiPointer<QQmlAbstractBinding, QPropertyBindingPrivate> d = static_cast<QQmlAbstractBinding *>(nullptr);
+ QBiPointer<QQmlAbstractBinding, QPropertyBindingPrivate> d;
};
diff --git a/src/qml/qml/qqmlproperty.cpp b/src/qml/qml/qqmlproperty.cpp
index b271876ac1..9b2c02d4be 100644
--- a/src/qml/qml/qqmlproperty.cpp
+++ b/src/qml/qml/qqmlproperty.cpp
@@ -123,10 +123,7 @@ qWarning() << "Pixel size should now be 24:" << property.read().toInt();
/*!
Create an invalid QQmlProperty.
*/
-QQmlProperty::QQmlProperty()
-: d(nullptr)
-{
-}
+QQmlProperty::QQmlProperty() = default;
/*! \internal */
QQmlProperty::~QQmlProperty()
diff --git a/src/qml/qml/qqmlproperty.h b/src/qml/qml/qqmlproperty.h
index 696c0f7136..4ab84eb940 100644
--- a/src/qml/qml/qqmlproperty.h
+++ b/src/qml/qml/qqmlproperty.h
@@ -89,6 +89,10 @@ public:
QQmlProperty(const QQmlProperty &);
QQmlProperty &operator=(const QQmlProperty &);
+ QQmlProperty(QQmlProperty &&other) noexcept : d(std::exchange(other.d, nullptr)) {}
+ QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_MOVE_AND_SWAP(QQmlProperty);
+
+ void swap(QQmlProperty &other) noexcept { qSwap(d, other.d); }
bool operator==(const QQmlProperty &) const;
Type type() const;
@@ -132,7 +136,7 @@ public:
private:
friend class QQmlPropertyPrivate;
- QQmlPropertyPrivate *d;
+ QQmlPropertyPrivate *d = nullptr;
};
typedef QList<QQmlProperty> QQmlProperties;
diff --git a/src/qml/types/qqmlbind.cpp b/src/qml/types/qqmlbind.cpp
index a714c0285b..c474128553 100644
--- a/src/qml/types/qqmlbind.cpp
+++ b/src/qml/types/qqmlbind.cpp
@@ -81,6 +81,7 @@ enum class QQmlBindEntryKind: quint8 {
* and the new kind is returned.
*/
union QQmlBindEntryContent {
+ Q_DISABLE_COPY_MOVE(QQmlBindEntryContent)
public:
QQmlBindEntryContent() {}
~QQmlBindEntryContent() {}
@@ -175,9 +176,6 @@ private:
Q_ASSERT(dead == QQmlBindEntryKind::None);
Q_UNUSED(dead);
}
-
- QQmlBindEntryContent &operator=(const QQmlBindEntryContent &) = delete;
- QQmlBindEntryContent &operator=(QQmlBindEntryContent &&) = delete;
};
/*!
@@ -191,7 +189,7 @@ private:
struct QQmlBindEntry
{
QQmlBindEntry() = default;
- QQmlBindEntry(QQmlBindEntry &&other) : prop(std::move(other.prop))
+ QQmlBindEntry(QQmlBindEntry &&other) noexcept : prop(std::move(other.prop))
{
currentKind = current.set(std::move(other.current), other.currentKind, currentKind);
previousKind = previous.set(std::move(other.previous), other.previousKind, previousKind);
@@ -210,7 +208,7 @@ struct QQmlBindEntry
previousKind = previous.destroy(previousKind);
}
- QQmlBindEntry &operator=(QQmlBindEntry &&other)
+ QQmlBindEntry &operator=(QQmlBindEntry &&other) noexcept
{
if (this == &other)
return *this;