]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
chore: Remove now unused Hash::HashType distinction
authorJoel Rosdahl <joel@rosdahl.net>
Fri, 7 Jul 2023 13:44:28 +0000 (15:44 +0200)
committerJoel Rosdahl <joel@rosdahl.net>
Wed, 12 Jul 2023 09:07:42 +0000 (11:07 +0200)
After 561be2085df94b3c35dd803e56668e6feafc93b7 hash debugging will never
be enabled for a Hash instance that hashes binary data, so remove the
now unused Hash::HashType enum and related code.

src/Hash.cpp
src/Hash.hpp

index 63a0f76bd88f63c7dbf65e7637a50dc7b358b759..47471a694f79115dc36fe5015291e85d794cf275 100644 (file)
@@ -77,20 +77,10 @@ Hash::hash_delimiter(std::string_view type)
 }
 
 Hash&
-Hash::hash(nonstd::span<const uint8_t> data, HashType hash_type)
+Hash::hash(nonstd::span<const uint8_t> data)
 {
   hash_buffer(data);
-
-  switch (hash_type) {
-  case HashType::binary:
-    add_debug_text(util::format_base16(data));
-    break;
-
-  case HashType::text:
-    add_debug_text(util::to_string_view(data));
-    break;
-  }
-
+  add_debug_text(data);
   add_debug_text("\n");
   return *this;
 }
@@ -98,14 +88,14 @@ Hash::hash(nonstd::span<const uint8_t> data, HashType hash_type)
 Hash&
 Hash::hash(const char* data, size_t size)
 {
-  hash(util::to_span({data, size}), HashType::text);
+  hash(util::to_span({data, size}));
   return *this;
 }
 
 Hash&
 Hash::hash(std::string_view data)
 {
-  hash(util::to_span(data), HashType::text);
+  hash(util::to_span(data));
   return *this;
 }
 
@@ -152,9 +142,15 @@ Hash::hash_buffer(std::string_view buffer)
 }
 
 void
-Hash::add_debug_text(std::string_view text)
+Hash::add_debug_text(nonstd::span<const uint8_t> text)
 {
   if (!text.empty() && m_debug_text) {
-    (void)fwrite(text.data(), 1, text.length(), m_debug_text);
+    (void)fwrite(text.data(), 1, text.size(), m_debug_text);
   }
 }
+
+void
+Hash::add_debug_text(std::string_view text)
+{
+  add_debug_text(util::to_span(text));
+}
index de614d1c179b4c88ce289cd427a4fd7815934bff..66d6b2781340c20cffcf3747ab4d172a201f8b35 100644 (file)
@@ -31,8 +31,6 @@
 class Hash
 {
 public:
-  enum class HashType { binary, text };
-
   using Digest = std::array<uint8_t, 20>;
 
   Hash();
@@ -58,29 +56,12 @@ public:
   //   set, there should never be a hash collision risk).
   Hash& hash_delimiter(std::string_view type);
 
-  // Add bytes to the hash.
-  //
-  // If hash debugging is enabled:
-  //
-  // - If `hash_type` is `HashType::binary`, the buffer content is written in
-  //   hex format to the text input file.
-  // - If `hash_type` is `HashType::text`, the buffer content is written
-  //   verbatim to the text input file.
-  //
-  // In both cases a newline character is added as well.
-  Hash& hash(nonstd::span<const uint8_t> data,
-             HashType hash_type = HashType::text);
-
-  // Add string data to the hash.
+  // Add data to the hash.
   //
-  // If hash debugging is enabled, the string is written to the text input file
-  // followed by a newline.
+  // If hash debugging is enabled the bytes will be written verbatim to the text
+  // input file, plus a final newline character.
+  Hash& hash(nonstd::span<const uint8_t> data);
   Hash& hash(const char* data, size_t size);
-
-  // Add string data to the hash.
-  //
-  // If hash debugging is enabled, the string is written to the text input file
-  // followed by a newline.
   Hash& hash(std::string_view data);
 
   // Add an integer to the hash.
@@ -101,9 +82,6 @@ public:
   // input file.
   nonstd::expected<void, std::string> hash_fd(int fd);
 
-  // Add `text` to the text debug file.
-  void add_debug_text(std::string_view text);
-
 private:
   blake3_hasher m_hasher;
   FILE* m_debug_binary = nullptr;
@@ -111,4 +89,7 @@ private:
 
   void hash_buffer(nonstd::span<const uint8_t> buffer);
   void hash_buffer(std::string_view buffer);
+
+  void add_debug_text(nonstd::span<const uint8_t> text);
+  void add_debug_text(std::string_view text);
 };