diff options
author | Maksim Denisov <denisov.maksim@huawei.com> | 2024-09-18 17:51:41 +0200 |
---|---|---|
committer | Maksim Denisov <denisov.maksim@huawei.com> | 2024-09-23 10:54:50 +0200 |
commit | dc1db0e8b43f5e907a3ded2e39da8b58fa50a04b (patch) | |
tree | 7ca1dd20806fd71c42f875adc1c653df45b147b1 /src/buildtool/file_system/object_cas.hpp | |
parent | 6453a846e788887b6cd74d71c1873a5e3270434d (diff) | |
download | justbuild-dc1db0e8b43f5e907a3ded2e39da8b58fa50a04b.tar.gz |
Store HashFunction by const reference.
Despite the fact that HashFunction is a small type, it still makes sense to store it by reference to reflect the ownership. StorageConfig becomes the main holder.
Reference holders store HashFunction by const ref and aren't allowed to change it. However, they are free to return HashFunction by value since this doesn't benefit readability anyhow.
Diffstat (limited to 'src/buildtool/file_system/object_cas.hpp')
-rw-r--r-- | src/buildtool/file_system/object_cas.hpp | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/src/buildtool/file_system/object_cas.hpp b/src/buildtool/file_system/object_cas.hpp index edf43854..2616814c 100644 --- a/src/buildtool/file_system/object_cas.hpp +++ b/src/buildtool/file_system/object_cas.hpp @@ -53,13 +53,13 @@ class ObjectCAS { /// \param store_path The path to use for storing blobs. /// \param exists (optional) Function for checking blob existence. explicit ObjectCAS( - HashFunction hash_function, + gsl::not_null<HashFunction const*> const& hash_function, std::filesystem::path const& store_path, std::optional<gsl::not_null<ExistsFunc>> exists = std::nullopt) : file_store_{store_path}, exists_{exists.has_value() ? std::move(exists)->get() : kDefaultExists}, - hash_function_{hash_function} {} + hash_function_{*hash_function} {} ObjectCAS(ObjectCAS const&) = delete; ObjectCAS(ObjectCAS&&) = delete; @@ -115,7 +115,7 @@ class ObjectCAS { FileStorage<kStorageType, StoreMode::FirstWins, /*kSetEpochTime=*/true> file_store_; gsl::not_null<ExistsFunc> exists_; - HashFunction const hash_function_; + HashFunction const& hash_function_; /// Default callback for checking blob existence. static inline ExistsFunc const kDefaultExists = [](auto const& /*digest*/, |