diff options
author | Maksim Denisov <denisov.maksim@huawei.com> | 2024-09-16 11:19:11 +0200 |
---|---|---|
committer | Maksim Denisov <denisov.maksim@huawei.com> | 2024-09-18 16:47:40 +0200 |
commit | 10d97aee7d2cdf4c5ea425491786fe9e59360299 (patch) | |
tree | 8a97ea8870815ab542bd636896e6f4819813b85f /src | |
parent | 1d748c1808e17998b4183574e3706ef1f7b6a5db (diff) | |
download | justbuild-10d97aee7d2cdf4c5ea425491786fe9e59360299.tar.gz |
TreeReaderUtils: change InfoStoreFunc interface
...passing constructed Artifact::ObjectInfo by rvalue, to avoid additional copies.
Diffstat (limited to 'src')
4 files changed, 22 insertions, 15 deletions
diff --git a/src/buildtool/execution_api/common/tree_reader.hpp b/src/buildtool/execution_api/common/tree_reader.hpp index de1e2edf..857573df 100644 --- a/src/buildtool/execution_api/common/tree_reader.hpp +++ b/src/buildtool/execution_api/common/tree_reader.hpp @@ -53,9 +53,9 @@ class TreeReader final { TreeReaderUtils::InfoStoreFunc store_info = [&result, &parent](std::filesystem::path const& path, - Artifact::ObjectInfo const& info) { + Artifact::ObjectInfo&& info) { result.paths.emplace_back(parent / path); - result.infos.emplace_back(info); + result.infos.emplace_back(std::move(info)); return true; }; @@ -125,11 +125,11 @@ class TreeReader final { TreeReaderUtils::InfoStoreFunc internal_store = [this, &store, &parent, include_trees]( std::filesystem::path const& path, - Artifact::ObjectInfo const& info) -> bool { + Artifact::ObjectInfo&& info) -> bool { return IsTreeObject(info.type) ? ReadObjectInfosRecursively( store, parent / path, info.digest, include_trees) - : store(parent / path, info); + : store(parent / path, std::move(info)); }; if (not impl_.IsNativeProtocol()) { diff --git a/src/buildtool/execution_api/common/tree_reader_utils.cpp b/src/buildtool/execution_api/common/tree_reader_utils.cpp index 13775201..a04b9300 100644 --- a/src/buildtool/execution_api/common/tree_reader_utils.cpp +++ b/src/buildtool/execution_api/common/tree_reader_utils.cpp @@ -16,6 +16,7 @@ #include <exception> #include <type_traits> +#include <utility> #include "nlohmann/json.hpp" #include "src/buildtool/common/artifact_digest.hpp" @@ -68,11 +69,11 @@ template <typename TTree> auto json = nlohmann::json::object(); TreeReaderUtils::InfoStoreFunc store_infos = [&json](std::filesystem::path const& path, - Artifact::ObjectInfo const& info) -> bool { + Artifact::ObjectInfo&& info) -> bool { static constexpr bool kSizeUnknown = std::is_same_v<TTree, GitRepo::tree_entries_t>; - json[path.string()] = info.ToString(kSizeUnknown); + json[path.string()] = std::move(info).ToString(kSizeUnknown); return true; }; @@ -99,8 +100,8 @@ auto TreeReaderUtils::ReadObjectInfos(bazel_re::Directory const& dir, HashFunction const hash_function{HashFunction::Type::PlainSHA256}; try { for (auto const& f : dir.files()) { - auto const info = CreateObjectInfo(hash_function, f); - if (not info or not store_info(f.name(), *info)) { + auto info = CreateObjectInfo(hash_function, f); + if (not info or not store_info(f.name(), *std::move(info))) { return false; } } @@ -117,8 +118,8 @@ auto TreeReaderUtils::ReadObjectInfos(bazel_re::Directory const& dir, } } for (auto const& d : dir.directories()) { - auto const info = CreateObjectInfo(hash_function, d); - if (not store_info(d.name(), *info)) { + auto info = CreateObjectInfo(hash_function, d); + if (not info or not store_info(d.name(), *std::move(info))) { return false; } } diff --git a/src/buildtool/execution_api/common/tree_reader_utils.hpp b/src/buildtool/execution_api/common/tree_reader_utils.hpp index ed151899..ab0aab5d 100644 --- a/src/buildtool/execution_api/common/tree_reader_utils.hpp +++ b/src/buildtool/execution_api/common/tree_reader_utils.hpp @@ -27,7 +27,7 @@ class TreeReaderUtils final { public: using InfoStoreFunc = std::function<bool(std::filesystem::path const&, - Artifact::ObjectInfo const&)>; + Artifact::ObjectInfo&&)>; /// \brief Read object infos from directory. /// \returns true on success. diff --git a/src/buildtool/execution_api/utils/subobject.cpp b/src/buildtool/execution_api/utils/subobject.cpp index 0029a9f3..912e2d4f 100644 --- a/src/buildtool/execution_api/utils/subobject.cpp +++ b/src/buildtool/execution_api/utils/subobject.cpp @@ -15,6 +15,8 @@ #include "src/buildtool/execution_api/utils/subobject.hpp" #ifndef BOOTSTRAP_BUILD_TOOL +#include <utility> + #include "src/buildtool/common/protocol_traits.hpp" #include "src/buildtool/crypto/hash_function.hpp" #include "src/buildtool/execution_api/bazel_msg/bazel_msg_factory.hpp" @@ -56,9 +58,11 @@ auto RetrieveSubPathId(Artifact::ObjectInfo object_info, std::optional<Artifact::ObjectInfo> new_object_info{}; if (not TreeReaderUtils::ReadObjectInfos( *directory, - [&new_object_info, &segment](auto path, auto info) { + [&new_object_info, &segment]( + std::filesystem::path const& path, + Artifact::ObjectInfo&& info) { if (path == segment) { - new_object_info = info; + new_object_info = std::move(info); } return true; })) { @@ -95,9 +99,11 @@ auto RetrieveSubPathId(Artifact::ObjectInfo object_info, std::optional<Artifact::ObjectInfo> new_object_info{}; if (not TreeReaderUtils::ReadObjectInfos( *entries, - [&new_object_info, &segment](auto path, auto info) { + [&new_object_info, &segment]( + std::filesystem::path const& path, + Artifact::ObjectInfo&& info) { if (path == segment) { - new_object_info = info; + new_object_info = std::move(info); } return true; })) { |