diff options
author | Ulf Hermann <ulf.hermann@qt.io> | 2023-05-24 15:07:34 +0200 |
---|---|---|
committer | Ulf Hermann <ulf.hermann@qt.io> | 2023-05-26 14:45:21 +0200 |
commit | 58e601e13a207cbab392ef1bd7c075c62331deed (patch) | |
tree | 26ff2c7440254684ddce2a632d56634f87c1f1e3 | |
parent | be813b9955aad4628dba4a270ba1de226a7c9496 (diff) |
QQmlPropertyCache: Allow property cache vector to be size-reset
This drops all the property caches and resizes the storage. We'll need
this when we retain property caches after unlinking.
Change-Id: Ieb88cea770f5771cab03d8f8d2feef7bc2fb7c52
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
-rw-r--r-- | src/qml/qml/qqmlpropertycachevector_p.h | 36 |
1 files changed, 25 insertions, 11 deletions
diff --git a/src/qml/qml/qqmlpropertycachevector_p.h b/src/qml/qml/qqmlpropertycachevector_p.h index a208b3fa6e..1cee914220 100644 --- a/src/qml/qml/qqmlpropertycachevector_p.h +++ b/src/qml/qml/qqmlpropertycachevector_p.h @@ -42,28 +42,30 @@ public: } void clear() { + for (int i = 0; i < data.size(); ++i) + releaseElement(i); + data.clear(); + } + + void resetAndResize(int size) + { for (int i = 0; i < data.size(); ++i) { - const auto &cache = data.at(i); - if (cache.isT2()) { - if (QQmlPropertyCache *data = cache.asT2()) - data->release(); - } else if (const QQmlPropertyCache *data = cache.asT1()) { - data->release(); - } + releaseElement(i); + data[i] = BiPointer(); } - data.clear(); + data.resize(size); } void append(const QQmlPropertyCache::ConstPtr &cache) { cache->addref(); - data.append(QBiPointer<const QQmlPropertyCache, QQmlPropertyCache>(cache.data())); + data.append(BiPointer(cache.data())); Q_ASSERT(data.last().isT1()); Q_ASSERT(data.size() <= std::numeric_limits<int>::max()); } void appendOwn(const QQmlPropertyCache::Ptr &cache) { cache->addref(); - data.append(QBiPointer<const QQmlPropertyCache, QQmlPropertyCache>(cache.data())); + data.append(BiPointer(cache.data())); Q_ASSERT(data.last().isT2()); Q_ASSERT(data.size() <= std::numeric_limits<int>::max()); } @@ -122,8 +124,20 @@ public: } private: + void releaseElement(int i) + { + const auto &cache = data.at(i); + if (cache.isT2()) { + if (QQmlPropertyCache *data = cache.asT2()) + data->release(); + } else if (const QQmlPropertyCache *data = cache.asT1()) { + data->release(); + } + } + Q_DISABLE_COPY(QQmlPropertyCacheVector) - QVector<QBiPointer<const QQmlPropertyCache, QQmlPropertyCache>> data; + using BiPointer = QBiPointer<const QQmlPropertyCache, QQmlPropertyCache>; + QVector<BiPointer> data; }; QT_END_NAMESPACE |