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/other_tools | |
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/other_tools')
-rw-r--r-- | src/other_tools/just_mr/fetch.cpp | 5 | ||||
-rw-r--r-- | src/other_tools/just_mr/launch.cpp | 20 | ||||
-rw-r--r-- | src/other_tools/just_mr/mirrors.hpp | 2 | ||||
-rw-r--r-- | src/other_tools/just_mr/update.cpp | 6 | ||||
-rw-r--r-- | src/other_tools/repo_map/repos_to_setup_map.cpp | 10 |
5 files changed, 24 insertions, 19 deletions
diff --git a/src/other_tools/just_mr/fetch.cpp b/src/other_tools/just_mr/fetch.cpp index 3585d2f3..a7afc575 100644 --- a/src/other_tools/just_mr/fetch.cpp +++ b/src/other_tools/just_mr/fetch.cpp @@ -223,7 +223,8 @@ auto MultiRepoFetch(std::shared_ptr<Configuration> const& config, return kExitFetchError; } 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::Log(LogLevel::Error, "Config: Unknown repository type {} for {}", nlohmann::json(repo_type_str).dump(), @@ -231,7 +232,7 @@ auto MultiRepoFetch(std::shared_ptr<Configuration> const& config, return kExitFetchError; } // only do work if repo is archive or git tree type - switch (kCheckoutTypeMap.at(repo_type_str)) { + switch (checkout_type_it->second) { case CheckoutType::Archive: { auto logger = std::make_shared<AsyncMapConsumerLogger>( [&repo_name](std::string const& msg, bool fatal) { diff --git a/src/other_tools/just_mr/launch.cpp b/src/other_tools/just_mr/launch.cpp index 0a061031..c085f5be 100644 --- a/src/other_tools/just_mr/launch.cpp +++ b/src/other_tools/just_mr/launch.cpp @@ -93,8 +93,9 @@ auto CallJust(std::optional<std::filesystem::path> const& config_file, std::optional<LockFile> lock{}; if (subcommand and kKnownJustSubcommands.contains(*subcommand)) { + auto const& flags = kKnownJustSubcommands.at(*subcommand); // Read the config file if needed - if (kKnownJustSubcommands.at(*subcommand).config) { + if (flags.config) { auto repo_lock = RepositoryGarbageCollector::SharedLock(storage_config); if (not repo_lock) { @@ -128,15 +129,14 @@ auto CallJust(std::optional<std::filesystem::path> const& config_file, return kExitSetupError; } } - use_build_root = kKnownJustSubcommands.at(*subcommand).build_root; - use_launcher = kKnownJustSubcommands.at(*subcommand).launch; - supports_defines = kKnownJustSubcommands.at(*subcommand).defines; - supports_remote = kKnownJustSubcommands.at(*subcommand).remote; - supports_remote_properties = - kKnownJustSubcommands.at(*subcommand).remote_props; - supports_serve = kKnownJustSubcommands.at(*subcommand).serve; - supports_dispatch = kKnownJustSubcommands.at(*subcommand).dispatch; - does_build = kKnownJustSubcommands.at(*subcommand).does_build; + use_build_root = flags.build_root; + use_launcher = flags.launch; + supports_defines = flags.defines; + supports_remote = flags.remote; + supports_remote_properties = flags.remote_props; + supports_serve = flags.serve; + supports_dispatch = flags.dispatch; + does_build = flags.does_build; } // build just command std::vector<std::string> cmd = {common_args.just_path->string()}; diff --git a/src/other_tools/just_mr/mirrors.hpp b/src/other_tools/just_mr/mirrors.hpp index 7480a839..41351bbb 100644 --- a/src/other_tools/just_mr/mirrors.hpp +++ b/src/other_tools/just_mr/mirrors.hpp @@ -158,7 +158,7 @@ namespace MirrorsUtils { CurlURLHandle::GetHostname(mirror).value_or(std::string{}); auto it = mirrors_by_hostname.find(hostname); if (it != mirrors_by_hostname.end()) { - mirrors_by_hostname.at(hostname).emplace_back(mirror); + it->second.emplace_back(mirror); } else { // add missing or unknown hostnames to fallback list with key "" diff --git a/src/other_tools/just_mr/update.cpp b/src/other_tools/just_mr/update.cpp index e2ed9197..43fd2de6 100644 --- a/src/other_tools/just_mr/update.cpp +++ b/src/other_tools/just_mr/update.cpp @@ -24,6 +24,7 @@ #include <optional> #include <thread> #include <unordered_map> +#include <utility> #include <vector> #include "fmt/core.h" @@ -118,7 +119,8 @@ auto MultiRepoUpdate(std::shared_ptr<Configuration> const& config, return kExitUpdateError; } 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::Log(LogLevel::Error, "Unknown repository type {} for {}", nlohmann::json(repo_type_str).dump(), @@ -126,7 +128,7 @@ auto MultiRepoUpdate(std::shared_ptr<Configuration> const& config, return kExitUpdateError; } // only do work if repo is git type - if (kCheckoutTypeMap.at(repo_type_str) == CheckoutType::Git) { + if (checkout_type_it->second == CheckoutType::Git) { auto repo_desc_repository = (*resolved_repo_desc)->At("repository"); if (not repo_desc_repository) { 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), |