diff options
author | Marco Bubke <marco.bubke@qt.io> | 2023-05-27 03:34:01 +0200 |
---|---|---|
committer | Marco Bubke <marco.bubke@qt.io> | 2023-05-30 11:11:18 +0000 |
commit | 9773e523ced8410f20ffc17427983904fae5a028 (patch) | |
tree | a51f5aec00b2dfe59903ec8d70a042edd3be84b4 /src | |
parent | 2981feefd718123dcbecbb3183e77fb1d3f29129 (diff) |
QmlDesigner: Fix flacky StorageCache tests
A id with value zero is now invalid. So we offset the id value by minus
one. We had to check if the id is valid before adding it too.
Change-Id: I433772da0358ec48970313d89ea0b56e21f635e4
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
Diffstat (limited to 'src')
-rw-r--r-- | src/plugins/qmldesigner/designercore/projectstorage/storagecache.h | 34 |
1 files changed, 21 insertions, 13 deletions
diff --git a/src/plugins/qmldesigner/designercore/projectstorage/storagecache.h b/src/plugins/qmldesigner/designercore/projectstorage/storagecache.h index 945a6e38e56..691a8a698a1 100644 --- a/src/plugins/qmldesigner/designercore/projectstorage/storagecache.h +++ b/src/plugins/qmldesigner/designercore/projectstorage/storagecache.h @@ -47,12 +47,12 @@ class StorageCache template<typename IntegerType> constexpr explicit StorageCacheIndex(IntegerType id) noexcept - : id{static_cast<int>(id)} + : id{static_cast<std::size_t>(id)} {} constexpr StorageCacheIndex operator=(std::ptrdiff_t newId) noexcept { - id = static_cast<int>(newId); + id = static_cast<std::size_t>(newId); return *this; } @@ -77,12 +77,15 @@ class StorageCache return first.id >= second.id; } - constexpr bool isValid() const noexcept { return id >= 0; } + constexpr bool isValid() const noexcept + { + return id != std::numeric_limits<std::size_t>::max(); + } explicit operator std::size_t() const noexcept { return static_cast<std::size_t>(id); } public: - int id = -1; + std::size_t id = std::numeric_limits<std::size_t>::max(); }; public: @@ -149,7 +152,7 @@ public: }); if (found != m_entries.end()) - max_id = static_cast<std::size_t>(found->id) + 1; + max_id = static_cast<std::size_t>(found->id); m_indices.resize(max_id); @@ -184,7 +187,7 @@ public: return first.id < second.id; }); - auto max_id = static_cast<std::size_t>(found->id) + 1; + auto max_id = static_cast<std::size_t>(found->id); if (max_id > m_indices.size()) m_indices.resize(max_id); @@ -247,10 +250,11 @@ public: { std::shared_lock<Mutex> sharedLock(m_mutex); - if (IndexType::create(static_cast<IndexDatabaseType>(m_indices.size())) > id) { - if (auto indirectionIndex = m_indices.at(static_cast<std::size_t>(id)); - indirectionIndex.isValid()) + if (IndexType::create(static_cast<IndexDatabaseType>(m_indices.size()) + 1) > id) { + if (StorageCacheIndex indirectionIndex = m_indices.at(static_cast<std::size_t>(id) - 1); + indirectionIndex.isValid()) { return m_entries.at(static_cast<std::size_t>(indirectionIndex)).value; + } } sharedLock.unlock(); @@ -271,7 +275,9 @@ public: for (IndexType id : ids) { values.emplace_back( - m_entries.at(static_cast<std::size_t>(m_indices.at(static_cast<std::size_t>(id)))).value); + m_entries + .at(static_cast<std::size_t>(m_indices.at(static_cast<std::size_t>(id) - 1))) + .value); } return values; } @@ -284,8 +290,10 @@ private: void updateIndices() { auto begin = m_entries.cbegin(); - for (auto current = begin; current != m_entries.cend(); ++current) - m_indices[static_cast<std::size_t>(current->id)] = std::distance(begin, current); + for (auto current = begin; current != m_entries.cend(); ++current) { + if (current->id) + m_indices[static_cast<std::size_t>(current->id) - 1] = std::distance(begin, current); + } } auto find(ViewType view) @@ -322,7 +330,7 @@ private: incrementLargerOrEqualIndicesByOne(newIndirectionIndex); - auto indirectionIndex = static_cast<std::size_t>(id); + auto indirectionIndex = static_cast<std::size_t>(id) - 1; ensureSize(indirectionIndex); m_indices.at(indirectionIndex) = newIndirectionIndex; |