]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
refactor: Add more Hash::hash overloads
authorJoel Rosdahl <joel@rosdahl.net>
Mon, 6 May 2024 18:35:22 +0000 (20:35 +0200)
committerJoel Rosdahl <joel@rosdahl.net>
Mon, 6 May 2024 18:35:22 +0000 (20:35 +0200)
src/ccache/Hash.cpp
src/ccache/Hash.hpp
src/ccache/ccache.cpp

index 97db62f07fa3c2f2c1e31710e1101e7a616400d6..45320d1c1918ff107d6bb716af8a3a32a74daf3d 100644 (file)
@@ -84,20 +84,6 @@ Hash::hash(nonstd::span<const uint8_t> 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)
 {
index df95b66c2014dbaa525cda90a882fbac37e5aa55..4ac7503f723ead8cd925f8a4fa58e8ec859e166c 100644 (file)
@@ -18,6 +18,9 @@
 
 #pragma once
 
+#include <ccache/util/PathString.hpp>
+#include <ccache/util/conversion.hpp>
+
 #include <blake3/blake3.h>
 #include <nonstd/span.hpp>
 #include <tl/expected.hpp>
@@ -25,6 +28,7 @@
 #include <array>
 #include <cstdint>
 #include <cstdio>
+#include <filesystem>
 #include <string>
 #include <string_view>
 
@@ -63,7 +67,10 @@ public:
   // input file, plus a final newline character.
   Hash& hash(nonstd::span<const uint8_t> 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<const uint8_t> 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;
+}
index 6baf8bdd7dcc5c92dcb218d205cbf2a317e82fc8..05dcbc4f0d7bcbad207beb02e688232d267a969c 100644 (file)
@@ -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.