aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/qml/qqmlpropertycachevector_p.h
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2021-12-07 17:41:33 +0100
committerUlf Hermann <ulf.hermann@qt.io>2022-01-03 15:58:37 +0100
commit7db241834aa9c5070a0f13914cf6cd46b453d0ff (patch)
tree2548197c9e27d63f008218f72e986f10539f727e /src/qml/qml/qqmlpropertycachevector_p.h
parentd74e931f3fc2587ac6d1e2930acbbe54ea5be2b5 (diff)
Unify PropertyCache refcounting
We should not keep plain QQmlPropertyCache pointers around. Also optimize self-assignment of QQmlRefPointer. Change-Id: I0e30b4ce29bb6b7acf288a9dc7b515d0e8f4ddfe Reviewed-by: Andrei Golubev <andrei.golubev@qt.io> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'src/qml/qml/qqmlpropertycachevector_p.h')
-rw-r--r--src/qml/qml/qqmlpropertycachevector_p.h25
1 files changed, 14 insertions, 11 deletions
diff --git a/src/qml/qml/qqmlpropertycachevector_p.h b/src/qml/qml/qqmlpropertycachevector_p.h
index 45fc2364df..5e4b84aec0 100644
--- a/src/qml/qml/qqmlpropertycachevector_p.h
+++ b/src/qml/qml/qqmlpropertycachevector_p.h
@@ -65,17 +65,17 @@ public:
CacheNeedsVMEMetaObject
};
- QQmlPropertyCacheVector() {}
- QQmlPropertyCacheVector(QQmlPropertyCacheVector &&other)
- : data(std::move(other.data)) {}
- QQmlPropertyCacheVector &operator=(QQmlPropertyCacheVector &&other) {
- QVector<QTaggedPointer<QQmlPropertyCache, Tag>> moved(std::move(other.data));
- data.swap(moved);
- return *this;
- }
+ QQmlPropertyCacheVector() = default;
+ QQmlPropertyCacheVector(QQmlPropertyCacheVector &&) = default;
+ QQmlPropertyCacheVector &operator=(QQmlPropertyCacheVector &&) = default;
~QQmlPropertyCacheVector() { clear(); }
- void resize(int size) { return data.resize(size); }
+ void resize(int size)
+ {
+ Q_ASSERT(size >= data.size());
+ return data.resize(size);
+ }
+
int count() const { return data.count(); }
void clear()
{
@@ -86,8 +86,11 @@ public:
data.clear();
}
- void append(QQmlPropertyCache *cache) { cache->addref(); data.append(QTaggedPointer<QQmlPropertyCache, Tag>(cache)); }
- QQmlPropertyCache *at(int index) const { return data.at(index).data(); }
+ void append(const QQmlRefPointer<QQmlPropertyCache> &cache) {
+ cache->addref();
+ data.append(QTaggedPointer<QQmlPropertyCache, Tag>(cache.data()));
+ }
+ QQmlRefPointer<QQmlPropertyCache> at(int index) const { return data.at(index).data(); }
void set(int index, const QQmlRefPointer<QQmlPropertyCache> &replacement) {
if (QQmlPropertyCache *oldCache = data.at(index).data()) {
if (replacement.data() == oldCache)