aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/memory/qv4mm.cpp
diff options
context:
space:
mode:
authorFabian Kosmale <fabian.kosmale@qt.io>2023-12-12 23:14:29 +0100
committerFabian Kosmale <fabian.kosmale@qt.io>2024-01-22 19:25:20 +0100
commitb9132634928f810f6628c8836807c49d0c15ccc3 (patch)
tree9932594e5e272b48206c8d4d614a2017829169ef /src/qml/memory/qv4mm.cpp
parent09d7e7d91566142c656b6f6ba8bba11185451d8a (diff)
gc: sweep: simplify iteration over weak maps/sets
Change-Id: I855975debce001e9d84ec21449a54e7739f43d2a Reviewed-by: Olivier De Cannière <olivier.decanniere@qt.io> Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Diffstat (limited to 'src/qml/memory/qv4mm.cpp')
-rw-r--r--src/qml/memory/qv4mm.cpp35
1 files changed, 13 insertions, 22 deletions
diff --git a/src/qml/memory/qv4mm.cpp b/src/qml/memory/qv4mm.cpp
index c09e20f0a0..a5ad658dd9 100644
--- a/src/qml/memory/qv4mm.cpp
+++ b/src/qml/memory/qv4mm.cpp
@@ -1020,10 +1020,6 @@ void MemoryManager::setGCTimeLimit(int timeMs)
void MemoryManager::sweep(bool lastSweep, ClassDestroyStatsCallback classCountPtr)
{
- Heap::MapObject *map = nullptr;
- Heap::MapObject **lastMap = nullptr;
- Heap::SetObject *set = nullptr;
- Heap::SetObject **lastSet = nullptr;
for (PersistentValueStorage::Iterator it = m_weakValues->begin(); it != m_weakValues->end(); ++it) {
Managed *m = (*it).managed();
@@ -1036,26 +1032,21 @@ void MemoryManager::sweep(bool lastSweep, ClassDestroyStatsCallback classCountPt
}
}
- map = weakMaps;
- lastMap = &weakMaps;
- while (map) {
- if (map->isMarked()) {
- map->removeUnmarkedKeys();
- *lastMap = map;
- lastMap = &map->nextWeakMap;
- }
- map = map->nextWeakMap;
+ for (auto [map, lastMap] = std::tuple {weakMaps, &weakMaps }; map; map = map->nextWeakMap) {
+ if (!map->isMarked())
+ continue;
+ map->removeUnmarkedKeys();
+ *lastMap = map;
+ lastMap = &map->nextWeakMap;
}
- set = weakSets;
- lastSet = &weakSets;
- while (set) {
- if (set->isMarked()) {
- set->removeUnmarkedKeys();
- *lastSet = set;
- lastSet = &set->nextWeakSet;
- }
- set = set->nextWeakSet;
+ for (auto [set, lastSet] = std::tuple {weakSets, &weakSets}; set; set = set->nextWeakSet) {
+
+ if (!set->isMarked())
+ continue;
+ set->removeUnmarkedKeys();
+ *lastSet = set;
+ lastSet = &set->nextWeakSet;
}
// onDestruction handlers may have accessed other QObject wrappers and reset their value, so ensure