From: Joel Rosdahl Date: Fri, 7 Jul 2023 13:44:28 +0000 (+0200) Subject: chore: Remove now unused Hash::HashType distinction X-Git-Tag: v4.9~146 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7b3576b82a84ecd772fa46f0f956f5cc2e2e8f1b;p=thirdparty%2Fccache.git chore: Remove now unused Hash::HashType distinction 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. --- diff --git a/src/Hash.cpp b/src/Hash.cpp index 63a0f76bd..47471a694 100644 --- a/src/Hash.cpp +++ b/src/Hash.cpp @@ -77,20 +77,10 @@ Hash::hash_delimiter(std::string_view type) } Hash& -Hash::hash(nonstd::span data, HashType hash_type) +Hash::hash(nonstd::span 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 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 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)); +} diff --git a/src/Hash.hpp b/src/Hash.hpp index de614d1c1..66d6b2781 100644 --- a/src/Hash.hpp +++ b/src/Hash.hpp @@ -31,8 +31,6 @@ class Hash { public: - enum class HashType { binary, text }; - using Digest = std::array; 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 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 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 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 buffer); void hash_buffer(std::string_view buffer); + + void add_debug_text(nonstd::span text); + void add_debug_text(std::string_view text); };