Avoid double traversal of maps

The typical find/if-not-exists-insert pattern can be achieved with 1
lookup instead of 2 using emplace with a sentinel value. Also maps value
initialize their values when inserted with the [] operator, this is
defined and so there is no need to explicitly insert zeroes for integer
values.
This commit is contained in:
Geza Lore
2023-10-28 13:41:43 +01:00
parent 30318a6654
commit d60f180f43
25 changed files with 240 additions and 311 deletions
+1 -1
View File
@@ -310,7 +310,7 @@ private:
UASSERT_OBJ(varp->attrSplitVar(), varp, " no split_var metacomment");
const MapIt it = m_map.find(varp);
if (it == m_map.end()) return false; // Not registered
const bool ok = m_map[varp].insert(ref).second;
const bool ok = it->second.insert(ref).second;
return ok;
}