From: Joel Rosdahl Date: Mon, 6 May 2024 18:35:22 +0000 (+0200) Subject: refactor: Add more Hash::hash overloads X-Git-Tag: v4.10~26 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a717579df0a09c5ccd0c31566d1459396e0963eb;p=thirdparty%2Fccache.git refactor: Add more Hash::hash overloads --- diff --git a/src/ccache/Hash.cpp b/src/ccache/Hash.cpp index 97db62f0..45320d1c 100644 --- a/src/ccache/Hash.cpp +++ b/src/ccache/Hash.cpp @@ -84,20 +84,6 @@ Hash::hash(nonstd::span data) return *this; } -Hash& -Hash::hash(const char* data, size_t size) -{ - hash(util::to_span({data, size})); - return *this; -} - -Hash& -Hash::hash(std::string_view data) -{ - hash(util::to_span(data)); - return *this; -} - Hash& Hash::hash(int64_t x) { diff --git a/src/ccache/Hash.hpp b/src/ccache/Hash.hpp index df95b66c..4ac7503f 100644 --- a/src/ccache/Hash.hpp +++ b/src/ccache/Hash.hpp @@ -18,6 +18,9 @@ #pragma once +#include +#include + #include #include #include @@ -25,6 +28,7 @@ #include #include #include +#include #include #include @@ -63,7 +67,10 @@ public: // input file, plus a final newline character. Hash& hash(nonstd::span data); Hash& hash(const char* data, size_t size); + Hash& hash(const char* data); Hash& hash(std::string_view data); + Hash& hash(const std::string& data); + Hash& hash(const std::filesystem::path& data); // Add an integer to the hash. // @@ -94,3 +101,38 @@ private: void add_debug_text(nonstd::span text); void add_debug_text(std::string_view text); }; + +inline Hash& +Hash::hash(const char* data, size_t size) +{ + hash(util::to_span({data, size})); + return *this; +} + +inline Hash& +Hash::hash(const char* data) +{ + hash(std::string_view(data)); + return *this; +} + +inline Hash& +Hash::hash(std::string_view data) +{ + hash(util::to_span(data)); + return *this; +} + +inline Hash& +Hash::hash(const std::string& data) +{ + hash(std::string_view(data)); + return *this; +} + +inline Hash& +Hash::hash(const std::filesystem::path& path) +{ + hash(util::PathString(path).str()); + return *this; +} diff --git a/src/ccache/ccache.cpp b/src/ccache/ccache.cpp index 6baf8bdd..05dcbc4f 100644 --- a/src/ccache/ccache.cpp +++ b/src/ccache/ccache.cpp @@ -565,7 +565,7 @@ process_preprocessed_file(Context& ctx, Hash& hash, const std::string& path) } if (inc_path != ctx.apparent_cwd || ctx.config.hash_dir()) { - hash.hash(pstr(inc_path).str()); + hash.hash(inc_path); } TRY(remember_include_file(ctx, inc_path, hash, system, nullptr)); @@ -669,7 +669,7 @@ result_key_from_depfile(Context& ctx, Hash& hash) && !ctx.args_info.generating_pch) { fs::path pch_path = core::make_relative_path(ctx, ctx.args_info.included_pch_file); - hash.hash(pstr(pch_path).str()); + hash.hash(pch_path); TRY(remember_include_file(ctx, pstr(pch_path), hash, false, nullptr)); } @@ -728,7 +728,7 @@ result_key_from_includes(Context& ctx, Hash& hash, std::string_view stdout_data) && !ctx.args_info.generating_pch) { fs::path pch_path = core::make_relative_path(ctx, ctx.args_info.included_pch_file); - hash.hash(pstr(pch_path).str()); + hash.hash(pch_path); TRY(remember_include_file(ctx, pstr(pch_path), hash, false, nullptr)); } @@ -1446,7 +1446,7 @@ hash_common_info(const Context& ctx, // Also hash the compiler name as some compilers use hard links and behave // differently depending on the real name. hash.hash_delimiter("cc_name"); - hash.hash(pstr(fs::path(args[0]).filename()).str()); + hash.hash(fs::path(args[0]).filename()); // Hash variables that may affect the compilation. const char* always_hash_env_vars[] = { @@ -1545,7 +1545,7 @@ hash_common_info(const Context& ctx, // the directory in the hash for now. LOG_RAW("Hashing apparent CWD due to generating a .gcno file"); hash.hash_delimiter("CWD in .gcno"); - hash.hash(pstr(ctx.apparent_cwd).str()); + hash.hash(ctx.apparent_cwd); } // Possibly hash the coverage data file path. @@ -2586,7 +2586,7 @@ do_cache_compilation(Context& ctx) if (processed.hash_actual_cwd) { common_hash.hash_delimiter("actual_cwd"); - common_hash.hash(pstr(ctx.actual_cwd).str()); + common_hash.hash(ctx.actual_cwd); } // Try to find the hash using the manifest.