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. --- src/other_tools/repo_map/repos_to_setup_map.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'src/other_tools/repo_map') diff --git a/src/other_tools/repo_map/repos_to_setup_map.cpp b/src/other_tools/repo_map/repos_to_setup_map.cpp index 4e29ffc2..7aeb69f7 100644 --- a/src/other_tools/repo_map/repos_to_setup_map.cpp +++ b/src/other_tools/repo_map/repos_to_setup_map.cpp @@ -502,7 +502,8 @@ void DistdirCheckout(ExpressionPtr const& repo_desc, } // get repo_type auto repo_type_str = repo_type->get()->String(); - if (not kCheckoutTypeMap.contains(repo_type_str)) { + auto const checkout_type_it = kCheckoutTypeMap.find(repo_type_str); + if (checkout_type_it == kCheckoutTypeMap.end()) { (*logger)(fmt::format("DistdirCheckout: Unknown type {} for " "repository {}", nlohmann::json(repo_type_str).dump(), @@ -511,7 +512,7 @@ void DistdirCheckout(ExpressionPtr const& repo_desc, return; } // only do work if repo is archive type - if (kCheckoutTypeMap.at(repo_type_str) == CheckoutType::Archive) { + if (checkout_type_it->second == CheckoutType::Archive) { auto const archive = ParseArchiveContent(*resolved_repo_desc, dist_repo_name); if (not archive) { @@ -794,7 +795,8 @@ auto CreateReposToSetupMap( } // get repo_type auto repo_type_str = repo_type->get()->String(); - if (not kCheckoutTypeMap.contains(repo_type_str)) { + auto const checkout_type_it = kCheckoutTypeMap.find(repo_type_str); + if (checkout_type_it == kCheckoutTypeMap.end()) { (*logger)( fmt::format("Config: Unknown type {} for repository {}", nlohmann::json(repo_type_str).dump(), @@ -811,7 +813,7 @@ auto CreateReposToSetupMap( fatal); }); // do checkout - switch (kCheckoutTypeMap.at(repo_type_str)) { + switch (checkout_type_it->second) { case CheckoutType::Git: { GitCheckout(*resolved_repo_desc, std::move(repos), -- cgit v1.2.3