diff --git a/src/dbzero/object_model/LangCache.cpp b/src/dbzero/object_model/LangCache.cpp index 771bac3f..bde17780 100644 --- a/src/dbzero/object_model/LangCache.cpp +++ b/src/dbzero/object_model/LangCache.cpp @@ -297,32 +297,23 @@ namespace db0 void LangCacheView::clear(bool expired_only, bool as_defunct) { + // copy for erase safety + auto objects = std::move(m_objects); + m_objects = {}; + // erase expired objects only if (expired_only) { - // optimized clear when lang cache view size >> cache size - if (m_objects.size() > m_cache.size() * 4) { - std::unordered_set
non_expired_objects; - for (auto addr: m_objects) { - if (!m_cache.erase(m_fixture_id, addr, true, as_defunct)) { - non_expired_objects.insert(addr); - } - } - m_objects = std::move(non_expired_objects); - } else { - auto it = m_objects.begin(); - while (it != m_objects.end()) { - if (m_cache.erase(m_fixture_id, *it, true, as_defunct)) { - it = m_objects.erase(it); - } else { - ++it; - } + std::unordered_set
non_expired_objects; + for (auto addr: objects) { + if (!m_cache.erase(m_fixture_id, addr, true, as_defunct)) { + non_expired_objects.insert(addr); } } + m_objects = std::move(non_expired_objects); } else { - for (auto addr: m_objects) { + for (auto addr: objects) { m_cache.erase(m_fixture_id, addr, false, as_defunct); - } - m_objects.clear(); + } } } diff --git a/src/dbzero/object_model/tags/ObjectIterable.hpp b/src/dbzero/object_model/tags/ObjectIterable.hpp index 38173f1a..07550777 100644 --- a/src/dbzero/object_model/tags/ObjectIterable.hpp +++ b/src/dbzero/object_model/tags/ObjectIterable.hpp @@ -128,7 +128,7 @@ namespace db0::object_model TypeObjectPtr getLangType() const; // NOTE: ObjectIterable might be related with a specific context / scope (e.g. snapshot) - // to prevend context deletion before the query, it's important to attach it + // to prevent context deletion before the query, it's important to attach it // otherwise a segfault might happen when query iterated over, after closing the context void attachContext(ObjectPtr) const; diff --git a/src/dbzero/workspace/Fixture.cpp b/src/dbzero/workspace/Fixture.cpp index e95657ef..239e7a68 100644 --- a/src/dbzero/workspace/Fixture.cpp +++ b/src/dbzero/workspace/Fixture.cpp @@ -387,7 +387,7 @@ namespace db0 // Flush using registered flush handlers for (auto &handler: m_flush_handlers) { handler(); - } + } m_lang_cache.clear(true); // lock for exclusive access { diff --git a/src/dbzero/workspace/GC0.cpp b/src/dbzero/workspace/GC0.cpp index 4d0c727a..f1202745 100644 --- a/src/dbzero/workspace/GC0.cpp +++ b/src/dbzero/workspace/GC0.cpp @@ -283,5 +283,6 @@ namespace db0 std::unique_ptr GC0::beginCommit() { return std::make_unique(*this); - } + } + } \ No newline at end of file