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/execution_api/remote/bazel | |
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/execution_api/remote/bazel')
6 files changed, 28 insertions, 25 deletions
diff --git a/src/buildtool/execution_api/remote/bazel/bazel_api.cpp b/src/buildtool/execution_api/remote/bazel/bazel_api.cpp index e42c32e7..c5d77194 100644 --- a/src/buildtool/execution_api/remote/bazel/bazel_api.cpp +++ b/src/buildtool/execution_api/remote/bazel/bazel_api.cpp @@ -184,13 +184,14 @@ namespace { } // namespace -BazelApi::BazelApi(std::string const& instance_name, - std::string const& host, - Port port, - gsl::not_null<Auth const*> const& auth, - gsl::not_null<RetryConfig const*> const& retry_config, - ExecutionConfiguration const& exec_config, - HashFunction hash_function) noexcept { +BazelApi::BazelApi( + std::string const& instance_name, + std::string const& host, + Port port, + gsl::not_null<Auth const*> const& auth, + gsl::not_null<RetryConfig const*> const& retry_config, + ExecutionConfiguration const& exec_config, + gsl::not_null<HashFunction const*> const& hash_function) noexcept { network_ = std::make_shared<BazelNetwork>(instance_name, host, port, diff --git a/src/buildtool/execution_api/remote/bazel/bazel_api.hpp b/src/buildtool/execution_api/remote/bazel/bazel_api.hpp index 6b2a6f17..b829529c 100644 --- a/src/buildtool/execution_api/remote/bazel/bazel_api.hpp +++ b/src/buildtool/execution_api/remote/bazel/bazel_api.hpp @@ -48,7 +48,7 @@ class BazelApi final : public IExecutionApi { gsl::not_null<Auth const*> const& auth, gsl::not_null<RetryConfig const*> const& retry_config, ExecutionConfiguration const& exec_config, - HashFunction hash_function) noexcept; + gsl::not_null<HashFunction const*> const& hash_function) noexcept; BazelApi(BazelApi const&) = delete; BazelApi(BazelApi&& other) noexcept; auto operator=(BazelApi const&) -> BazelApi& = delete; diff --git a/src/buildtool/execution_api/remote/bazel/bazel_network.cpp b/src/buildtool/execution_api/remote/bazel/bazel_network.cpp index edf18249..6cb7e905 100644 --- a/src/buildtool/execution_api/remote/bazel/bazel_network.cpp +++ b/src/buildtool/execution_api/remote/bazel/bazel_network.cpp @@ -28,7 +28,7 @@ BazelNetwork::BazelNetwork( gsl::not_null<Auth const*> const& auth, gsl::not_null<RetryConfig const*> const& retry_config, ExecutionConfiguration const& exec_config, - HashFunction hash_function) noexcept + gsl::not_null<HashFunction const*> const& hash_function) noexcept : instance_name_{std::move(instance_name)}, cas_{std::make_unique<BazelCasClient>(host, port, auth, retry_config)}, ac_{std::make_unique<BazelAcClient>(host, port, auth, retry_config)}, @@ -37,7 +37,7 @@ BazelNetwork::BazelNetwork( auth, retry_config)}, exec_config_{exec_config}, - hash_function_{hash_function} {} + hash_function_{*hash_function} {} auto BazelNetwork::IsAvailable(bazel_re::Digest const& digest) const noexcept -> bool { @@ -144,7 +144,7 @@ auto BazelNetwork::ExecuteBazelActionSync( } auto BazelNetwork::CreateReader() const noexcept -> BazelNetworkReader { - return BazelNetworkReader{instance_name_, cas_.get(), hash_function_}; + return BazelNetworkReader{instance_name_, cas_.get(), &hash_function_}; } auto BazelNetwork::GetCachedActionResult( diff --git a/src/buildtool/execution_api/remote/bazel/bazel_network.hpp b/src/buildtool/execution_api/remote/bazel/bazel_network.hpp index 645b403d..a744daaf 100644 --- a/src/buildtool/execution_api/remote/bazel/bazel_network.hpp +++ b/src/buildtool/execution_api/remote/bazel/bazel_network.hpp @@ -39,13 +39,14 @@ /// \brief Contains all network clients and is responsible for all network IO. class BazelNetwork { public: - explicit BazelNetwork(std::string instance_name, - std::string const& host, - Port port, - gsl::not_null<Auth const*> const& auth, - gsl::not_null<RetryConfig const*> const& retry_config, - ExecutionConfiguration const& exec_config, - HashFunction hash_function) noexcept; + explicit BazelNetwork( + std::string instance_name, + std::string const& host, + Port port, + gsl::not_null<Auth const*> const& auth, + gsl::not_null<RetryConfig const*> const& retry_config, + ExecutionConfiguration const& exec_config, + gsl::not_null<HashFunction const*> const& hash_function) noexcept; /// \brief Check if digest exists in CAS /// \param[in] digest The digest to look up @@ -96,7 +97,7 @@ class BazelNetwork { std::unique_ptr<BazelAcClient> ac_{}; std::unique_ptr<BazelExecutionClient> exec_{}; ExecutionConfiguration exec_config_{}; - HashFunction const hash_function_; + HashFunction const& hash_function_; template <class T_Iter> [[nodiscard]] auto DoUploadBlobs(T_Iter const& first, diff --git a/src/buildtool/execution_api/remote/bazel/bazel_network_reader.cpp b/src/buildtool/execution_api/remote/bazel/bazel_network_reader.cpp index 5dac053b..d5f2f3f8 100644 --- a/src/buildtool/execution_api/remote/bazel/bazel_network_reader.cpp +++ b/src/buildtool/execution_api/remote/bazel/bazel_network_reader.cpp @@ -30,10 +30,10 @@ BazelNetworkReader::BazelNetworkReader( std::string instance_name, gsl::not_null<BazelCasClient const*> const& cas, - HashFunction hash_function) noexcept + gsl::not_null<HashFunction const*> const& hash_function) noexcept : instance_name_{std::move(instance_name)}, cas_{*cas}, - hash_function_{hash_function} {} + hash_function_{*hash_function} {} BazelNetworkReader::BazelNetworkReader( BazelNetworkReader&& other, diff --git a/src/buildtool/execution_api/remote/bazel/bazel_network_reader.hpp b/src/buildtool/execution_api/remote/bazel/bazel_network_reader.hpp index 5c6cdbf9..e3e283c7 100644 --- a/src/buildtool/execution_api/remote/bazel/bazel_network_reader.hpp +++ b/src/buildtool/execution_api/remote/bazel/bazel_network_reader.hpp @@ -41,9 +41,10 @@ class BazelNetworkReader final { public: using DumpCallback = std::function<bool(std::string const&)>; - explicit BazelNetworkReader(std::string instance_name, - gsl::not_null<BazelCasClient const*> const& cas, - HashFunction hash_function) noexcept; + explicit BazelNetworkReader( + std::string instance_name, + gsl::not_null<BazelCasClient const*> const& cas, + gsl::not_null<HashFunction const*> const& hash_function) noexcept; BazelNetworkReader( BazelNetworkReader&& other, @@ -84,7 +85,7 @@ class BazelNetworkReader final { std::string const instance_name_; BazelCasClient const& cas_; - HashFunction const hash_function_; + HashFunction const& hash_function_; std::optional<DirectoryMap> auxiliary_map_; [[nodiscard]] auto MakeAuxiliaryMap( |