summaryrefslogtreecommitdiff
path: root/src/buildtool/execution_engine/tree_operations
diff options
context:
space:
mode:
authorPaul Cristian Sarbu <paul.cristian.sarbu@huawei.com>2025-06-13 13:14:27 +0200
committerPaul Cristian Sarbu <paul.cristian.sarbu@huawei.com>2025-06-16 17:27:29 +0200
commit223f67c2cbf4648c3aaa907ec0edf98e53b574e9 (patch)
tree7dd1e9aa2dd8a2470984a65d841e222b2226fa59 /src/buildtool/execution_engine/tree_operations
parentfebe0937cf4394bc0f908e13fd0b6ab63b2c29c2 (diff)
downloadjustbuild-223f67c2cbf4648c3aaa907ec0edf98e53b574e9.tar.gz
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.
Diffstat (limited to 'src/buildtool/execution_engine/tree_operations')
-rw-r--r--src/buildtool/execution_engine/tree_operations/tree_operations_utils.cpp11
1 files changed, 9 insertions, 2 deletions
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<GitRepo::TreeEntry>{}});
+ if (auto res = git_entries.insert(
+ {*git_hash, std::vector<GitRepo::TreeEntry>{}});
+ 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.