diff options
Diffstat (limited to 'src/qml/qml/qqmlpropertycachevector_p.h')
-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 |