aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@qt.io>2022-05-06 19:07:42 +0200
committerMarc Mutz <marc.mutz@qt.io>2022-05-07 23:19:15 +0200
commiteff31bf486c2f6b9fcc43e526566cd381aad2d6f (patch)
tree718515f6b785be70afb9e9382859d38ee84f7cf5 /src/qml
parentaf50ec087e44a9102f4e66e7fed4385c108aced3 (diff)
QtDeclarative: replace qSwap with std::swap/member-swap where possible
qSwap() is a monster that looks for ADL overloads of swap() and also detects the noexcept of the wrapped swap() function, so it should only be used when the argument type is unknown. In the vast majority of cases, the type is known to be efficiently std::swap()able or to have a member-swap. Call either of these. For the common case of pointer types, circumvent the expensive trait checks on std::swap() by using our hand-rolled qt_ptr_swap() template, the advantage being that it can be unconditionally noexcept, removing all type traits instantiations. In QQmlPropertyCacheAliasCreator, replace the qSwap() with std::move(). Task-number: QTBUG-97601 Pick-to: 6.3 6.2 5.15 Change-Id: I8b78a3ad287ce8565ca258ff38261e4d2cf0be63 Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io>
Diffstat (limited to 'src/qml')
-rw-r--r--src/qml/jsruntime/qv4persistent_p.h2
-rw-r--r--src/qml/qml/qqmlanybinding_p.h4
-rw-r--r--src/qml/qml/qqmlobjectcreator_p.h36
-rw-r--r--src/qml/qml/qqmlproperty.h2
-rw-r--r--src/qml/qml/qqmlpropertycachecreator_p.h2
5 files changed, 23 insertions, 23 deletions
diff --git a/src/qml/jsruntime/qv4persistent_p.h b/src/qml/jsruntime/qv4persistent_p.h
index 1437736818..a0f2cb6a9d 100644
--- a/src/qml/jsruntime/qv4persistent_p.h
+++ b/src/qml/jsruntime/qv4persistent_p.h
@@ -104,7 +104,7 @@ public:
PersistentValue &operator=(const PersistentValue &other);
PersistentValue(PersistentValue &&other) noexcept : val(std::exchange(other.val, nullptr)) {}
- void swap(PersistentValue &other) noexcept { qSwap(val, other.val); }
+ void swap(PersistentValue &other) noexcept { qt_ptr_swap(val, other.val); }
QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_MOVE_AND_SWAP(PersistentValue);
~PersistentValue() { PersistentValueStorage::free(val); }
diff --git a/src/qml/qml/qqmlanybinding_p.h b/src/qml/qml/qqmlanybinding_p.h
index 116c5b81cc..00b5980000 100644
--- a/src/qml/qml/qqmlanybinding_p.h
+++ b/src/qml/qml/qqmlanybinding_p.h
@@ -415,8 +415,8 @@ public:
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); }
+ void swap(QQmlAnyBinding &other) noexcept { d.swap(other.d); }
+ friend void swap(QQmlAnyBinding &lhs, QQmlAnyBinding &rhs) noexcept { lhs.swap(rhs); }
QQmlAnyBinding &operator=(const QQmlAnyBinding &other) noexcept
{
diff --git a/src/qml/qml/qqmlobjectcreator_p.h b/src/qml/qml/qqmlobjectcreator_p.h
index bdecf563c2..194a071d95 100644
--- a/src/qml/qml/qqmlobjectcreator_p.h
+++ b/src/qml/qml/qqmlobjectcreator_p.h
@@ -248,7 +248,7 @@ private:
QQmlVMEMetaObject *vmeMetaObject = QQmlVMEMetaObject::get(instance);
QObject *scopeObject = instance;
- qSwap(_scopeObject, scopeObject);
+ qt_ptr_swap(_scopeObject, scopeObject);
QV4::Scope valueScope(v4);
QScopedValueRollback<QV4::Value*> jsObjectGuard(sharedState->allJavaScriptObjects,
@@ -257,32 +257,32 @@ private:
Q_ASSERT(topLevelCreator);
QV4::QmlContext *qmlContext = static_cast<QV4::QmlContext *>(valueScope.alloc());
- qSwap(_qmlContext, qmlContext);
+ qt_ptr_swap(_qmlContext, qmlContext);
- qSwap(_propertyCache, cache);
- qSwap(_qobject, instance);
+ _propertyCache.swap(cache);
+ qt_ptr_swap(_qobject, instance);
int objectIndex = deferredIndex;
- qSwap(_compiledObjectIndex, objectIndex);
+ std::swap(_compiledObjectIndex, objectIndex);
const QV4::CompiledData::Object *obj = compilationUnit->objectAt(_compiledObjectIndex);
- qSwap(_compiledObject, obj);
- qSwap(_ddata, declarativeData);
- qSwap(_bindingTarget, bindingTarget);
- qSwap(_vmeMetaObject, vmeMetaObject);
+ qt_ptr_swap(_compiledObject, obj);
+ qt_ptr_swap(_ddata, declarativeData);
+ qt_ptr_swap(_bindingTarget, bindingTarget);
+ qt_ptr_swap(_vmeMetaObject, vmeMetaObject);
f();
- qSwap(_vmeMetaObject, vmeMetaObject);
- qSwap(_bindingTarget, bindingTarget);
- qSwap(_ddata, declarativeData);
- qSwap(_compiledObject, obj);
- qSwap(_compiledObjectIndex, objectIndex);
- qSwap(_qobject, instance);
- qSwap(_propertyCache, cache);
+ qt_ptr_swap(_vmeMetaObject, vmeMetaObject);
+ qt_ptr_swap(_bindingTarget, bindingTarget);
+ qt_ptr_swap(_ddata, declarativeData);
+ qt_ptr_swap(_compiledObject, obj);
+ std::swap(_compiledObjectIndex, objectIndex);
+ qt_ptr_swap(_qobject, instance);
+ _propertyCache.swap(cache);
- qSwap(_qmlContext, qmlContext);
- qSwap(_scopeObject, scopeObject);
+ qt_ptr_swap(_qmlContext, qmlContext);
+ qt_ptr_swap(_scopeObject, scopeObject);
}
};
diff --git a/src/qml/qml/qqmlproperty.h b/src/qml/qml/qqmlproperty.h
index dbffce9437..0dfdb6c759 100644
--- a/src/qml/qml/qqmlproperty.h
+++ b/src/qml/qml/qqmlproperty.h
@@ -94,7 +94,7 @@ public:
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); }
+ void swap(QQmlProperty &other) noexcept { qt_ptr_swap(d, other.d); }
bool operator==(const QQmlProperty &) const;
Type type() const;
diff --git a/src/qml/qml/qqmlpropertycachecreator_p.h b/src/qml/qml/qqmlpropertycachecreator_p.h
index 5aa1abcbe7..f683dc208c 100644
--- a/src/qml/qml/qqmlpropertycachecreator_p.h
+++ b/src/qml/qml/qqmlpropertycachecreator_p.h
@@ -871,7 +871,7 @@ inline void QQmlPropertyCacheAliasCreator<ObjectContainer>::appendAliasPropertie
}
}
- qSwap(objectsWithAliases, pendingObjects);
+ objectsWithAliases = std::move(pendingObjects);
} while (!objectsWithAliases.isEmpty());
}