diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/buildtool/compatibility/compatibility.hpp | 3 | ||||
-rw-r--r-- | src/buildtool/crypto/hash_function.hpp | 20 | ||||
-rw-r--r-- | src/buildtool/main/main.cpp | 7 | ||||
-rw-r--r-- | src/buildtool/storage/config.hpp | 7 |
4 files changed, 11 insertions, 26 deletions
diff --git a/src/buildtool/compatibility/compatibility.hpp b/src/buildtool/compatibility/compatibility.hpp index e2eecb11..2073ad52 100644 --- a/src/buildtool/compatibility/compatibility.hpp +++ b/src/buildtool/compatibility/compatibility.hpp @@ -39,9 +39,6 @@ class Compatibility { } static void SetCompatible(bool value = true) noexcept { Instance().compatible_ = value; - auto const hasher_type = value ? HashFunction::JustHash::Compatible - : HashFunction::JustHash::Native; - HashFunction::Instance().SetHashType(hasher_type); } [[nodiscard]] static auto RegisterGitEntry(std::string const& git_hash, diff --git a/src/buildtool/crypto/hash_function.hpp b/src/buildtool/crypto/hash_function.hpp index 6932a077..8d932016 100644 --- a/src/buildtool/crypto/hash_function.hpp +++ b/src/buildtool/crypto/hash_function.hpp @@ -33,22 +33,18 @@ class HashFunction { Compatible ///< SHA256 for all hashes. }; - static constexpr auto kDefaultType = JustHash::Native; - - explicit HashFunction(JustHash type) noexcept : type_{type} {} + explicit HashFunction(JustHash type) noexcept : type_{type} { + static_assert( + sizeof(HashFunction) <= sizeof(void*), + "HashFunction is passed and stored by value. If the " + "class is extended so that its size exceeds the size of a pointer, " + "the way how HashFunction is passed and stored must be changed."); + } [[nodiscard]] auto GetHashType() const noexcept -> JustHash { return type_; } - [[nodiscard]] static auto Instance() noexcept -> HashFunction& { - static HashFunction instance{kDefaultType}; - return instance; - } - - /// \brief Set globally used hash type. - void SetHashType(JustHash type) noexcept { type_ = type; } - /// \brief Compute a plain hash. [[nodiscard]] auto ComputeHash(std::string const& data) const noexcept -> Hasher::HashDigest { @@ -92,7 +88,7 @@ class HashFunction { } private: - JustHash type_ = kDefaultType; + JustHash const type_; [[nodiscard]] auto ComputeTaggedHash( std::string const& data, diff --git a/src/buildtool/main/main.cpp b/src/buildtool/main/main.cpp index 9f10b8bc..b089e321 100644 --- a/src/buildtool/main/main.cpp +++ b/src/buildtool/main/main.cpp @@ -259,12 +259,6 @@ void SetupExecutionServiceConfig(ServiceArguments const& args) { } } -void SetupHashFunction() { - HashFunction::Instance().SetHashType( - Compatibility::IsCompatible() ? HashFunction::JustHash::Compatible - : HashFunction::JustHash::Native); -} - void SetupFileChunker() { FileChunker::Initialize(); } @@ -797,7 +791,6 @@ auto main(int argc, char* argv[]) -> int { */ GitContext::Create(); - SetupHashFunction(); SetupFileChunker(); if (arguments.cmd == SubCommand::kGc) { diff --git a/src/buildtool/storage/config.hpp b/src/buildtool/storage/config.hpp index 5861977e..56274c02 100644 --- a/src/buildtool/storage/config.hpp +++ b/src/buildtool/storage/config.hpp @@ -222,10 +222,9 @@ class StorageConfig::Builder final { } } - auto hash_function = default_config.hash_function; - if (hash_type_.has_value()) { - hash_function = HashFunction{*hash_type_}; - } + auto const hash_function = hash_type_.has_value() + ? HashFunction{*hash_type_} + : default_config.hash_function; // Hash the execution backend description auto backend_description_id = default_config.backend_description_id; |