diff options
author | Maksim Denisov <denisov.maksim@huawei.com> | 2024-07-08 10:13:30 +0200 |
---|---|---|
committer | Maksim Denisov <denisov.maksim@huawei.com> | 2024-07-22 17:01:13 +0200 |
commit | e190c9e7900b7c5146c4670672009e202a3a2cc5 (patch) | |
tree | f3fa6a37fbc8bbcccc1c6be6a24b0aabe11df5db | |
parent | fecf8b5436a8012dc5fdf7f01192e7a6d99530bb (diff) | |
download | justbuild-e190c9e7900b7c5146c4670672009e202a3a2cc5.tar.gz |
Use a fixed HashFunction in expressions
-rw-r--r-- | src/buildtool/build_engine/expression/expression.cpp | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/src/buildtool/build_engine/expression/expression.cpp b/src/buildtool/build_engine/expression/expression.cpp index e155f749..d84c3b0a 100644 --- a/src/buildtool/build_engine/expression/expression.cpp +++ b/src/buildtool/build_engine/expression/expression.cpp @@ -238,6 +238,10 @@ auto Expression::TypeString() const noexcept -> std::string { // NOLINTNEXTLINE(misc-no-recursion) auto Expression::ComputeHash() const noexcept -> std::string { auto hash = std::string{}; + + // The type of HashFunction is irrelevant here. It is used for + // identification and quick comparison of expressions. SHA256 is used. + HashFunction const hash_function{HashFunction::JustHash::Compatible}; if (IsNone() or IsBool() or IsNumber() or IsString() or IsArtifact() or IsResult() or IsNode() or IsName()) { // just hash the JSON representation, but prepend "@" for artifact, @@ -247,11 +251,10 @@ auto Expression::ComputeHash() const noexcept -> std::string { : IsNode() ? "#" : IsName() ? "$" : ""}; - hash = - HashFunction::Instance().ComputeHash(prefix + ToString()).Bytes(); + hash = hash_function.ComputeHash(prefix + ToString()).Bytes(); } else { - auto hasher = HashFunction::Instance().Hasher(); + auto hasher = hash_function.Hasher(); if (IsList()) { auto list = Value<Expression::list_t>(); hasher.Update("["); @@ -263,8 +266,7 @@ auto Expression::ComputeHash() const noexcept -> std::string { auto map = Value<Expression::map_t>(); hasher.Update("{"); for (auto const& el : map->get()) { - hasher.Update( - HashFunction::Instance().ComputeHash(el.first).Bytes()); + hasher.Update(hash_function.ComputeHash(el.first).Bytes()); hasher.Update(el.second->ToHash()); } } |