]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
refactor: Improve calculate_result_and_manifest_key parameters
authorJoel Rosdahl <joel@rosdahl.net>
Wed, 19 Apr 2023 20:02:00 +0000 (22:02 +0200)
committerJoel Rosdahl <joel@rosdahl.net>
Wed, 19 Apr 2023 20:03:17 +0000 (22:03 +0200)
As suggested by clang-tidy
(readability-suspicious-call-argument,-warnings-as-errors).

src/ccache.cpp

index 71ea532e090fa0f59558db63a8d16b84614083d1..c06715868ffd3d258933e7cf4bf18cc6e2caf677 100644 (file)
@@ -1973,10 +1973,10 @@ static nonstd::expected<std::pair<std::optional<Digest>, std::optional<Digest>>,
                         Failure>
 calculate_result_and_manifest_key(Context& ctx,
                                   const Args& args,
-                                  Args& preprocessor_args,
                                   Hash& hash,
-                                  bool direct_mode)
+                                  Args* preprocessor_args)
 {
+  bool direct_mode = !preprocessor_args;
   bool found_ccbin = false;
 
   hash.hash_delimiter("cache entry version");
@@ -2033,17 +2033,18 @@ calculate_result_and_manifest_key(Context& ctx,
       result_key = get_result_key_from_manifest(ctx, *manifest_key);
     }
   } else if (ctx.args_info.arch_args.empty()) {
-    const auto digest = get_result_key_from_cpp(ctx, preprocessor_args, hash);
+    const auto digest = get_result_key_from_cpp(ctx, *preprocessor_args, hash);
     if (!digest) {
       return nonstd::make_unexpected(digest.error());
     }
     result_key = *digest;
     LOG_RAW("Got result key from preprocessor");
   } else {
-    preprocessor_args.push_back("-arch");
+    preprocessor_args->push_back("-arch");
     for (size_t i = 0; i < ctx.args_info.arch_args.size(); ++i) {
-      preprocessor_args.push_back(ctx.args_info.arch_args[i]);
-      const auto digest = get_result_key_from_cpp(ctx, preprocessor_args, hash);
+      preprocessor_args->push_back(ctx.args_info.arch_args[i]);
+      const auto digest =
+        get_result_key_from_cpp(ctx, *preprocessor_args, hash);
       if (!digest) {
         return nonstd::make_unexpected(digest.error());
       }
@@ -2053,9 +2054,9 @@ calculate_result_and_manifest_key(Context& ctx,
       if (i != ctx.args_info.arch_args.size() - 1) {
         result_key = std::nullopt;
       }
-      preprocessor_args.pop_back();
+      preprocessor_args->pop_back();
     }
-    preprocessor_args.pop_back();
+    preprocessor_args->pop_back();
   }
 
   if (result_key) {
@@ -2538,10 +2539,9 @@ do_cache_compilation(Context& ctx)
 
   if (ctx.config.direct_mode()) {
     LOG_RAW("Trying direct lookup");
-    Args dummy_args;
     MTR_BEGIN("hash", "direct_hash");
     const auto result_and_manifest_key = calculate_result_and_manifest_key(
-      ctx, args_to_hash, dummy_args, direct_hash, true);
+      ctx, args_to_hash, direct_hash, nullptr);
     MTR_END("hash", "direct_hash");
     if (!result_and_manifest_key) {
       return nonstd::make_unexpected(result_and_manifest_key.error());
@@ -2585,7 +2585,7 @@ do_cache_compilation(Context& ctx)
 
     MTR_BEGIN("hash", "cpp_hash");
     const auto result_and_manifest_key = calculate_result_and_manifest_key(
-      ctx, args_to_hash, processed.preprocessor_args, cpp_hash, false);
+      ctx, args_to_hash, cpp_hash, &processed.preprocessor_args);
     MTR_END("hash", "cpp_hash");
     if (!result_and_manifest_key) {
       return nonstd::make_unexpected(result_and_manifest_key.error());
@@ -2593,7 +2593,7 @@ do_cache_compilation(Context& ctx)
     result_key = result_and_manifest_key->first;
 
     // calculate_result_and_manifest_key always returns a non-nullopt result_key
-    // if the last argument (direct_mode) is false.
+    // in preprocessor mode (non-nullptr last argument).
     ASSERT(result_key);
 
     if (result_key_from_manifest && result_key_from_manifest != result_key) {