From 223f67c2cbf4648c3aaa907ec0edf98e53b574e9 Mon Sep 17 00:00:00 2001 From: Paul Cristian Sarbu Date: Fri, 13 Jun 2025 13:14:27 +0200 Subject: Avoid unnecessary work in accessing container entries - in sequence containers, use operator[] instead of .at() when accessing indices guaranteed to be in bound; - in associative containers, prefer .find() and reusing the returned const iterator to using .contains() and .at(); while there, make any so obtained iterators const if they are read-only. --- .../tree_operations/tree_operations_utils.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'src/buildtool/execution_engine/tree_operations') diff --git a/src/buildtool/execution_engine/tree_operations/tree_operations_utils.cpp b/src/buildtool/execution_engine/tree_operations/tree_operations_utils.cpp index ecf08e8e..fb7d3bf0 100644 --- a/src/buildtool/execution_engine/tree_operations/tree_operations_utils.cpp +++ b/src/buildtool/execution_engine/tree_operations/tree_operations_utils.cpp @@ -221,9 +221,16 @@ auto TreeOperationsUtils::SerializeGitTree( } auto it = git_entries.find(*git_hash); if (it == git_entries.end()) { - git_entries.insert({*git_hash, std::vector{}}); + if (auto res = git_entries.insert( + {*git_hash, std::vector{}}); + res.second) { + it = std::move(res).first; + } + else { + return std::nullopt; + } } - git_entries.at(*git_hash).emplace_back(name, entry.info.type); + it->second.emplace_back(name, entry.info.type); } // Serialize git entries. -- cgit v1.2.3