From dc1db0e8b43f5e907a3ded2e39da8b58fa50a04b Mon Sep 17 00:00:00 2001 From: Maksim Denisov Date: Wed, 18 Sep 2024 17:51:41 +0200 Subject: 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. --- src/buildtool/execution_api/remote/bazel/bazel_api.cpp | 15 ++++++++------- src/buildtool/execution_api/remote/bazel/bazel_api.hpp | 2 +- .../execution_api/remote/bazel/bazel_network.cpp | 6 +++--- .../execution_api/remote/bazel/bazel_network.hpp | 17 +++++++++-------- .../execution_api/remote/bazel/bazel_network_reader.cpp | 4 ++-- .../execution_api/remote/bazel/bazel_network_reader.hpp | 9 +++++---- 6 files changed, 28 insertions(+), 25 deletions(-) (limited to 'src/buildtool/execution_api/remote') 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 const& auth, - gsl::not_null 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 const& auth, + gsl::not_null const& retry_config, + ExecutionConfiguration const& exec_config, + gsl::not_null const& hash_function) noexcept { network_ = std::make_shared(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 const& auth, gsl::not_null const& retry_config, ExecutionConfiguration const& exec_config, - HashFunction hash_function) noexcept; + gsl::not_null 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 const& auth, gsl::not_null const& retry_config, ExecutionConfiguration const& exec_config, - HashFunction hash_function) noexcept + gsl::not_null const& hash_function) noexcept : instance_name_{std::move(instance_name)}, cas_{std::make_unique(host, port, auth, retry_config)}, ac_{std::make_unique(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 const& auth, - gsl::not_null 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 const& auth, + gsl::not_null const& retry_config, + ExecutionConfiguration const& exec_config, + gsl::not_null 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 ac_{}; std::unique_ptr exec_{}; ExecutionConfiguration exec_config_{}; - HashFunction const hash_function_; + HashFunction const& hash_function_; template [[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 const& cas, - HashFunction hash_function) noexcept + gsl::not_null 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; - explicit BazelNetworkReader(std::string instance_name, - gsl::not_null const& cas, - HashFunction hash_function) noexcept; + explicit BazelNetworkReader( + std::string instance_name, + gsl::not_null const& cas, + gsl::not_null 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 auxiliary_map_; [[nodiscard]] auto MakeAuxiliaryMap( -- cgit v1.2.3