diff options
author | Maksim Denisov <denisov.maksim@huawei.com> | 2024-09-16 11:36:45 +0200 |
---|---|---|
committer | Maksim Denisov <denisov.maksim@huawei.com> | 2024-09-18 16:47:40 +0200 |
commit | bf66b1cc04a0b1e13d53e6c52e44188753b932c4 (patch) | |
tree | 7a192871955a016988caa5276ea2ac1607725b52 | |
parent | aa1dc95cbc45ed7dbb1fee8ba11ba7010dfe11af (diff) | |
download | justbuild-bf66b1cc04a0b1e13d53e6c52e44188753b932c4.tar.gz |
Avoid additional memory allocations when working with protobuf's types.
Although this change doesn't benefit performance anyhow (protobuf's mutable_*() methods allocate memory lazily), it is better to let protobuf do this on its own.
4 files changed, 6 insertions, 12 deletions
diff --git a/src/buildtool/execution_api/remote/bazel/bazel_ac_client.cpp b/src/buildtool/execution_api/remote/bazel/bazel_ac_client.cpp index c5025358..51ccfeeb 100644 --- a/src/buildtool/execution_api/remote/bazel/bazel_ac_client.cpp +++ b/src/buildtool/execution_api/remote/bazel/bazel_ac_client.cpp @@ -39,8 +39,7 @@ auto BazelAcClient::GetActionResult( -> std::optional<bazel_re::ActionResult> { bazel_re::GetActionResultRequest request{}; request.set_instance_name(instance_name); - request.set_allocated_action_digest( - gsl::owner<bazel_re::Digest*>{new bazel_re::Digest{action_digest}}); + (*request.mutable_action_digest()) = action_digest; request.set_inline_stdout(inline_stdout); request.set_inline_stderr(inline_stderr); std::copy(inline_output_files.begin(), diff --git a/src/buildtool/execution_api/remote/bazel/bazel_cas_client.cpp b/src/buildtool/execution_api/remote/bazel/bazel_cas_client.cpp index 155bbc89..91498b22 100644 --- a/src/buildtool/execution_api/remote/bazel/bazel_cas_client.cpp +++ b/src/buildtool/execution_api/remote/bazel/bazel_cas_client.cpp @@ -688,8 +688,7 @@ auto BazelCasClient::CreateBatchRequestsMaxSize( auto BazelCasClient::CreateUpdateBlobsSingleRequest(BazelBlob const& b) noexcept -> bazel_re::BatchUpdateBlobsRequest_Request { bazel_re::BatchUpdateBlobsRequest_Request r{}; - r.set_allocated_digest( - gsl::owner<bazel_re::Digest*>{new bazel_re::Digest{b.digest}}); + (*r.mutable_digest()) = b.digest; r.set_data(*b.data); return r; } @@ -701,8 +700,7 @@ auto BazelCasClient::CreateGetTreeRequest( std::string const& page_token) noexcept -> bazel_re::GetTreeRequest { bazel_re::GetTreeRequest request; request.set_instance_name(instance_name); - request.set_allocated_root_digest( - gsl::owner<bazel_re::Digest*>{new bazel_re::Digest{root_digest}}); + (*request.mutable_root_digest()) = root_digest; request.set_page_size(page_size); request.set_page_token(page_token); return request; diff --git a/src/buildtool/execution_api/remote/bazel/bazel_execution_client.cpp b/src/buildtool/execution_api/remote/bazel/bazel_execution_client.cpp index c9b1ffe1..a2b29d75 100644 --- a/src/buildtool/execution_api/remote/bazel/bazel_execution_client.cpp +++ b/src/buildtool/execution_api/remote/bazel/bazel_execution_client.cpp @@ -80,8 +80,7 @@ auto BazelExecutionClient::Execute(std::string const& instance_name, bazel_re::ExecuteRequest request; request.set_instance_name(instance_name); request.set_skip_cache_lookup(config.skip_cache_lookup); - request.set_allocated_action_digest( - gsl::owner<bazel_re::Digest*>{new bazel_re::Digest(action_digest)}); + (*request.mutable_action_digest()) = action_digest; request.set_allocated_execution_policy(execution_policy.release()); request.set_allocated_results_cache_policy(results_cache_policy.release()); BazelExecutionClient::ExecutionResponse response; diff --git a/test/utils/remote_execution/bazel_action_creator.hpp b/test/utils/remote_execution/bazel_action_creator.hpp index ad9b3fbc..b7185121 100644 --- a/test/utils/remote_execution/bazel_action_creator.hpp +++ b/test/utils/remote_execution/bazel_action_creator.hpp @@ -76,11 +76,9 @@ blobs.emplace_back(dir_id, dir_data, /*is_exec=*/false); bazel_re::Action action; - action.set_allocated_command_digest( - gsl::owner<bazel_re::Digest*>{new bazel_re::Digest{cmd_id}}); + (*action.mutable_command_digest()) = cmd_id; action.set_do_not_cache(false); - action.set_allocated_input_root_digest( - gsl::owner<bazel_re::Digest*>{new bazel_re::Digest{dir_id}}); + (*action.mutable_input_root_digest()) = dir_id; auto action_data = action.SerializeAsString(); auto action_id = BazelDigestFactory::HashDataAs<ObjectType::File>( |