]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
refactor: Use structured binding declarations
authorJoel Rosdahl <joel@rosdahl.net>
Sun, 19 Jun 2022 11:52:56 +0000 (13:52 +0200)
committerJoel Rosdahl <joel@rosdahl.net>
Sun, 19 Jun 2022 19:29:02 +0000 (21:29 +0200)
src/Config.cpp
src/ccache.cpp
src/core/Manifest.cpp
src/core/Statistics.cpp
src/storage/Storage.cpp
src/storage/secondary/HttpStorage.cpp
src/storage/secondary/RedisStorage.cpp

index dae998fc0c3bece67221c6c8a6e42e7502d14bc4..9ac91a1d95bd078f3212ed9bd7089676f8c14675 100644 (file)
@@ -806,8 +806,8 @@ Config::visit_items(const ItemVisitor& item_visitor) const
   std::vector<std::string> keys;
   keys.reserve(k_config_key_table.size());
 
-  for (const auto& item : k_config_key_table) {
-    keys.emplace_back(item.first);
+  for (const auto& [key, value] : k_config_key_table) {
+    keys.emplace_back(key);
   }
   std::sort(keys.begin(), keys.end());
   for (const auto& key : keys) {
@@ -1014,21 +1014,21 @@ Config::set_item(const std::string& key,
     break;
   }
 
-  auto result = m_origins.emplace(key, origin);
-  if (!result.second) {
-    result.first->second = origin;
+  const auto& [element, inserted] = m_origins.emplace(key, origin);
+  if (!inserted) {
+    element->second = origin;
   }
 }
 
 void
 Config::check_key_tables_consistency()
 {
-  for (const auto& item : k_env_variable_table) {
-    if (k_config_key_table.find(item.second) == k_config_key_table.end()) {
+  for (const auto& [key, value] : k_env_variable_table) {
+    if (k_config_key_table.find(value) == k_config_key_table.end()) {
       throw core::Error(
         "env var {} mapped to {} which is missing from k_config_key_table",
-        item.first,
-        item.second);
+        key,
+        value);
     }
   }
 }
index 1bc34eba5a96e440b7b6c8866c69316658e20095..5f95849d064e03cf099c6a33fe4a4c8a7a00aac8 100644 (file)
@@ -441,8 +441,8 @@ remember_include_file(Context& ctx,
 static void
 print_included_files(const Context& ctx, FILE* fp)
 {
-  for (const auto& item : ctx.included_files) {
-    PRINT(fp, "{}\n", item.first);
+  for (const auto& [path, digest] : ctx.included_files) {
+    PRINT(fp, "{}\n", path);
   }
 }
 
index 003e54cfdaafbc9ae8938fe9e75e988333b62fe5..01adf50fc7963848d4b82ca9a1123b065c0c588e 100644 (file)
@@ -179,9 +179,9 @@ Manifest::add_result(
   std::vector<uint32_t> file_info_indexes;
   file_info_indexes.reserve(included_files.size());
 
-  for (const auto& item : included_files) {
-    file_info_indexes.push_back(get_file_info_index(item.first,
-                                                    item.second,
+  for (const auto& [path, digest] : included_files) {
+    file_info_indexes.push_back(get_file_info_index(path,
+                                                    digest,
                                                     mf_files,
                                                     mf_file_infos,
                                                     time_of_compilation,
index 70c685aa153a364a06f9a9330ea434efd9b0f624..06c5438e9f6ad47912d82c64feee1fafaf9d604a 100644 (file)
@@ -270,11 +270,8 @@ Statistics::format_human_readable(const Config& config,
     if (verbosity > 0) {
       auto uncacheable_stats = get_stats(FLAG_UNCACHEABLE, verbosity > 1);
       std::sort(uncacheable_stats.begin(), uncacheable_stats.end(), cmp_fn);
-      for (const auto& descr_count : uncacheable_stats) {
-        add_ratio_row(table,
-                      FMT("  {}:", descr_count.first),
-                      descr_count.second,
-                      uncacheable);
+      for (const auto& [name, value] : uncacheable_stats) {
+        add_ratio_row(table, FMT("  {}:", name), value, uncacheable);
       }
     }
   }
@@ -284,9 +281,8 @@ Statistics::format_human_readable(const Config& config,
     if (verbosity > 0) {
       auto error_stats = get_stats(FLAG_ERROR, verbosity > 1);
       std::sort(error_stats.begin(), error_stats.end(), cmp_fn);
-      for (const auto& descr_count : error_stats) {
-        add_ratio_row(
-          table, FMT("  {}:", descr_count.first), descr_count.second, errors);
+      for (const auto& [name, value] : error_stats) {
+        add_ratio_row(table, FMT("  {}:", name), value, errors);
       }
     }
   }
index b6ea1e19acb0a9192f0f837db409d85f0bc4daeb..2fafad7b9d57845d195c5cfb1a8cd7d338c0600f 100644 (file)
@@ -137,9 +137,8 @@ parse_storage_config(const std::string_view entry)
     if (parts[i].empty()) {
       continue;
     }
-    const auto kv_pair = util::split_once(parts[i], '=');
-    const auto& key = kv_pair.first;
-    const auto& raw_value = kv_pair.second.value_or("true");
+    const auto [key, right_hand_side] = util::split_once(parts[i], '=');
+    const auto& raw_value = right_hand_side.value_or("true");
     const auto value =
       util::value_or_throw<core::Error>(util::percent_decode(raw_value));
     if (key == "read-only") {
index d95ba62c14cb8257a977ccc420e991a9b6c2ed41..2276ce49a68ee1b6c72c136c8675763ba991ea53 100644 (file)
@@ -98,13 +98,13 @@ HttpStorageBackend::HttpStorageBackend(const Params& params)
     m_http_client(get_url(params.url))
 {
   if (!params.url.user_info().empty()) {
-    const auto pair = util::split_once(params.url.user_info(), ':');
-    if (!pair.second) {
+    const auto [user, password] = util::split_once(params.url.user_info(), ':');
+    if (!password) {
       throw core::Fatal("Expected username:password in URL but got \"{}\"",
                         params.url.user_info());
     }
-    m_http_client.set_basic_auth(std::string(pair.first).c_str(),
-                                 std::string(*pair.second).c_str());
+    m_http_client.set_basic_auth(std::string(user).c_str(),
+                                 std::string(*password).c_str());
   }
 
   m_http_client.set_default_headers({
@@ -278,9 +278,9 @@ void
 HttpStorage::redact_secrets(Backend::Params& params) const
 {
   auto& url = params.url;
-  const auto user_info = util::split_once(url.user_info(), ':');
-  if (user_info.second) {
-    url.user_info(FMT("{}:{}", user_info.first, k_redacted_password));
+  const auto [user, password] = util::split_once(url.user_info(), ':');
+  if (password) {
+    url.user_info(FMT("{}:{}", user, k_redacted_password));
   }
 
   auto bearer_token_attribute =
index dcc98b5796ff72f79c9a06dffdb373d865e7ed8b..cd5c100fa7f5eb6e035773318d90094050f04ba8 100644 (file)
@@ -92,16 +92,16 @@ to_timeval(const uint32_t ms)
 std::pair<std::optional<std::string>, std::optional<std::string>>
 split_user_info(const std::string& user_info)
 {
-  const auto pair = util::split_once(user_info, ':');
-  if (pair.first.empty()) {
+  const auto [left, right] = util::split_once(user_info, ':');
+  if (left.empty()) {
     // redis://HOST
     return {std::nullopt, std::nullopt};
-  } else if (pair.second) {
+  } else if (right) {
     // redis://USERNAME:PASSWORD@HOST
-    return {std::string(*pair.second), std::string(pair.first)};
+    return {std::string(left), std::string(*right)};
   } else {
     // redis://PASSWORD@HOST
-    return {std::string(pair.first), std::nullopt};
+    return {std::nullopt, std::string(left)};
   }
 }
 
@@ -274,15 +274,15 @@ RedisStorageBackend::select_database(const Url& url)
 void
 RedisStorageBackend::authenticate(const Url& url)
 {
-  const auto password_username_pair = split_user_info(url.user_info());
-  const auto& password = password_username_pair.first;
+  const auto [user, password] = split_user_info(url.user_info());
   if (password) {
-    const auto& username = password_username_pair.second;
-    if (username) {
-      LOG("Redis AUTH {} {}", *username, k_redacted_password);
+    if (user) {
+      // redis://user:password@host
+      LOG("Redis AUTH {} {}", *user, k_redacted_password);
       util::value_or_throw<Failed>(
-        redis_command("AUTH %s %s", username->c_str(), password->c_str()));
+        redis_command("AUTH %s %s", user->c_str(), password->c_str()));
     } else {
+      // redis://password@host
       LOG("Redis AUTH {}", k_redacted_password);
       util::value_or_throw<Failed>(redis_command("AUTH %s", password->c_str()));
     }
@@ -327,13 +327,15 @@ void
 RedisStorage::redact_secrets(Backend::Params& params) const
 {
   auto& url = params.url;
-  const auto user_info = util::split_once(url.user_info(), ':');
-  if (user_info.second) {
-    // redis://username:password@host
-    url.user_info(FMT("{}:{}", user_info.first, k_redacted_password));
-  } else if (!user_info.first.empty()) {
-    // redis://password@host
-    url.user_info(k_redacted_password);
+  const auto [user, password] = split_user_info(url.user_info());
+  if (password) {
+    if (user) {
+      // redis://user:password@host
+      url.user_info(FMT("{}:{}", *user, k_redacted_password));
+    } else {
+      // redis://password@host
+      url.user_info(k_redacted_password);
+    }
   }
 }