diff options
author | Paul Cristian Sarbu <paul.cristian.sarbu@huawei.com> | 2025-06-13 13:14:27 +0200 |
---|---|---|
committer | Paul Cristian Sarbu <paul.cristian.sarbu@huawei.com> | 2025-06-16 17:27:29 +0200 |
commit | 223f67c2cbf4648c3aaa907ec0edf98e53b574e9 (patch) | |
tree | 7dd1e9aa2dd8a2470984a65d841e222b2226fa59 /src/buildtool/main/build_utils.cpp | |
parent | febe0937cf4394bc0f908e13fd0b6ab63b2c29c2 (diff) | |
download | justbuild-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/main/build_utils.cpp')
-rw-r--r-- | src/buildtool/main/build_utils.cpp | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/src/buildtool/main/build_utils.cpp b/src/buildtool/main/build_utils.cpp index 684d2dd1..17b26d80 100644 --- a/src/buildtool/main/build_utils.cpp +++ b/src/buildtool/main/build_utils.cpp @@ -92,7 +92,8 @@ auto CreateTargetCacheWriterMap( // get the TaretCacheKey corresponding to this Id TargetCacheKey tc_key{key}; // check if entry actually needs storing - if (not cache_targets.contains(tc_key)) { + auto const tc_key_it = cache_targets.find(tc_key); + if (tc_key_it == cache_targets.end()) { if (tc.Read(tc_key)) { // entry already in target-cache, so nothing to be done (*setter)(nullptr); @@ -104,9 +105,8 @@ auto CreateTargetCacheWriterMap( true); return; } - auto const& target = cache_targets.at(tc_key); auto entry = TargetCacheEntry::FromTarget( - apis->remote->GetHashType(), target, extra_infos); + apis->remote->GetHashType(), tc_key_it->second, extra_infos); if (not entry) { (*logger)( fmt::format("Failed creating target cache entry for key {}", |