summaryrefslogtreecommitdiff
path: root/src/buildtool/common/tree.hpp
diff options
context:
space:
mode:
authorKlaus Aehlig <klaus.aehlig@huawei.com>2022-02-28 13:24:26 +0100
committerKlaus Aehlig <klaus.aehlig@huawei.com>2022-03-01 10:46:54 +0100
commit1ef03a1c7043d617885d319b0803d69907c3c9cc (patch)
treeacfcd33dab8e2355863356af88d14ac6e3578b2d /src/buildtool/common/tree.hpp
parentfffee539ec37e9e68189e71994aa2c901d30c9fb (diff)
downloadjustbuild-1ef03a1c7043d617885d319b0803d69907c3c9cc.tar.gz
Pass actions and trees in analysis result as shared pointer
... to avoid unnecessary copying and moving of larger objects.
Diffstat (limited to 'src/buildtool/common/tree.hpp')
-rw-r--r--src/buildtool/common/tree.hpp12
1 files changed, 7 insertions, 5 deletions
diff --git a/src/buildtool/common/tree.hpp b/src/buildtool/common/tree.hpp
index 512eda86..6b76f8f1 100644
--- a/src/buildtool/common/tree.hpp
+++ b/src/buildtool/common/tree.hpp
@@ -1,6 +1,7 @@
#ifndef INCLUDED_SRC_BUILDTOOL_COMMON_TREE_HPP
#define INCLUDED_SRC_BUILDTOOL_COMMON_TREE_HPP
+#include <memory>
#include <string>
#include <unordered_map>
@@ -13,6 +14,7 @@ class Tree {
using inputs_t = ActionDescription::inputs_t;
public:
+ using Ptr = std::shared_ptr<Tree>;
explicit Tree(inputs_t&& inputs)
: id_{ComputeId(inputs)}, inputs_{std::move(inputs)} {}
@@ -36,7 +38,7 @@ class Tree {
[[nodiscard]] static auto FromJson(std::string const& id,
nlohmann::json const& json)
- -> std::optional<Tree> {
+ -> std::optional<Tree::Ptr> {
auto inputs = inputs_t{};
inputs.reserve(json.size());
for (auto const& [path, artifact] : json.items()) {
@@ -46,16 +48,16 @@ class Tree {
}
inputs.emplace(path, std::move(*artifact_desc));
}
- return Tree{id, std::move(inputs)};
+ return std::make_shared<Tree>(id, std::move(inputs));
}
+ Tree(std::string id, inputs_t&& inputs)
+ : id_{std::move(id)}, inputs_{std::move(inputs)} {}
+
private:
std::string id_;
inputs_t inputs_;
- Tree(std::string id, inputs_t&& inputs)
- : id_{std::move(id)}, inputs_{std::move(inputs)} {}
-
static auto ComputeDescription(inputs_t const& inputs) -> nlohmann::json {
auto json = nlohmann::json::object();
for (auto const& [path, artifact] : inputs) {