summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoel Rosdahl <joel@rosdahl.net>2023-04-19 22:02:00 +0200
committerJoel Rosdahl <joel@rosdahl.net>2023-04-19 22:03:17 +0200
commitdda86ed94707107fa83fddf4c3f583229ea20a86 (patch)
treed4aaff9556f5c1b088c7e49628120786a743f743
parent4d7c6f7d5a73a15d6e6e2cad2ce2907dde14c049 (diff)
downloadccache-dda86ed94707107fa83fddf4c3f583229ea20a86.tar.gz
refactor: Improve calculate_result_and_manifest_key parameters
As suggested by clang-tidy (readability-suspicious-call-argument,-warnings-as-errors).
-rw-r--r--src/ccache.cpp24
1 files changed, 12 insertions, 12 deletions
diff --git a/src/ccache.cpp b/src/ccache.cpp
index 71ea532e..c0671586 100644
--- a/src/ccache.cpp
+++ b/src/ccache.cpp
@@ -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) {