From bbb4987cc087eabb8e5fdb8979d92c29e604a7d9 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sat, 2 Dec 2017 09:47:15 -0800 Subject: [PATCH] Hashmaps: Reset state when growing. std::move() is by no means guaranteed to clear. --- Common/Hashmaps.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/Common/Hashmaps.h b/Common/Hashmaps.h index aae0c0a809..d505afbff9 100644 --- a/Common/Hashmaps.h +++ b/Common/Hashmaps.h @@ -150,6 +150,11 @@ private: // This is extremely non-atomic and will need synchronization. std::vector old = std::move(map); std::vector oldState = std::move(state); + // Can't assume move will clear, it just may clear. + map.clear(); + state.clear(); + + int oldCount = count_; capacity_ *= factor; map.resize(capacity_); state.resize(capacity_); @@ -160,6 +165,7 @@ private: Insert(old[i].key, old[i].value); } } + _assert_msg_(SYSTEM, oldCount == count_, "DenseHashMap: count should not change in Grow()"); } struct Pair { Key key; @@ -289,6 +295,11 @@ private: // This is extremely non-atomic and will need synchronization. std::vector old = std::move(map); std::vector oldState = std::move(state); + // Can't assume move will clear, it just may clear. + map.clear(); + state.clear(); + + int oldCount = count_; capacity_ *= factor; map.resize(capacity_); state.resize(capacity_); @@ -299,6 +310,7 @@ private: Insert(old[i].hash, old[i].value); } } + _assert_msg_(SYSTEM, oldCount == count_, "PrehashMap: count should not change in Grow()"); } struct Pair { uint32_t hash;