diff options
author | Maksim Denisov <denisov.maksim@huawei.com> | 2024-08-05 09:33:44 +0200 |
---|---|---|
committer | Maksim Denisov <denisov.maksim@huawei.com> | 2024-08-07 14:43:19 +0200 |
commit | c1edc2e21ecf381470d71767dc38a83c85f57d23 (patch) | |
tree | cf14c408ee080df389c9f79d3be95eb253285839 /test/buildtool/execution_engine | |
parent | 7012f6c0762cf11e7b1c22304f8fb0b3b330cd0a (diff) | |
download | justbuild-c1edc2e21ecf381470d71767dc38a83c85f57d23.tar.gz |
Avoid deep copies of containers in responses.
Diffstat (limited to 'test/buildtool/execution_engine')
-rw-r--r-- | test/buildtool/execution_engine/executor/executor.test.cpp | 47 |
1 files changed, 32 insertions, 15 deletions
diff --git a/test/buildtool/execution_engine/executor/executor.test.cpp b/test/buildtool/execution_engine/executor/executor.test.cpp index 6a32a497..84bf7ade 100644 --- a/test/buildtool/execution_engine/executor/executor.test.cpp +++ b/test/buildtool/execution_engine/executor/executor.test.cpp @@ -83,10 +83,37 @@ class TestResponse : public IExecutionResponse { [[nodiscard]] auto HasStdOut() const noexcept -> bool final { return true; } [[nodiscard]] auto StdErr() noexcept -> std::string final { return {}; } [[nodiscard]] auto StdOut() noexcept -> std::string final { return {}; } - [[nodiscard]] auto ActionDigest() const noexcept -> std::string final { - return {}; + [[nodiscard]] auto ActionDigest() const noexcept + -> std::string const& final { + static const std::string kEmptyHash; + return kEmptyHash; } - [[nodiscard]] auto Artifacts() noexcept -> ArtifactInfos final { + [[nodiscard]] auto Artifacts() noexcept -> ArtifactInfos const& final { + if (not populated_) { + Populate(); + } + return artifacts_; + } + [[nodiscard]] auto DirectorySymlinks() noexcept + -> DirSymlinks const& final { + static const DirSymlinks kEmptySymlinks{}; + return kEmptySymlinks; + } + + private: + TestApiConfig config_{}; + ArtifactInfos artifacts_; + bool populated_ = false; + + explicit TestResponse(TestApiConfig config) noexcept + : config_{std::move(config)} {} + + void Populate() noexcept { + if (populated_) { + return; + } + populated_ = true; + ArtifactInfos artifacts{}; artifacts.reserve(config_.execution.outputs.size()); @@ -99,21 +126,11 @@ class TestResponse : public IExecutionResponse { .digest = ArtifactDigest{path, 0, /*is_tree=*/false}, .type = ObjectType::File}); } catch (...) { - return {}; + return; } } - - return artifacts; + artifacts_ = std::move(artifacts); } - [[nodiscard]] auto ArtifactsWithDirSymlinks() noexcept - -> std::pair<ArtifactInfos, DirSymlinks> final { - return {}; - } - - private: - TestApiConfig config_{}; - explicit TestResponse(TestApiConfig config) noexcept - : config_{std::move(config)} {} }; /// \brief Mockup Action, stores only config |