diff options
author | Maksim Denisov <denisov.maksim@huawei.com> | 2025-01-28 10:25:07 +0100 |
---|---|---|
committer | Maksim Denisov <denisov.maksim@huawei.com> | 2025-02-07 14:58:04 +0100 |
commit | e2f73a93be5977b5e18f4ba3aa05ea31bc5c16c4 (patch) | |
tree | 971f89e6f8db00b5bef9a4ed2c8e1dee680576ea /src | |
parent | 95792fb717bd84d500037b62c77a4949274e670d (diff) | |
download | justbuild-e2f73a93be5977b5e18f4ba3aa05ea31bc5c16c4.tar.gz |
Remove ContentBlobContainer and TransformedRange
Diffstat (limited to 'src')
-rw-r--r-- | src/buildtool/execution_api/common/TARGETS | 6 | ||||
-rw-r--r-- | src/buildtool/execution_api/common/content_blob_container.hpp | 83 | ||||
-rw-r--r-- | src/utils/cpp/TARGETS | 7 | ||||
-rw-r--r-- | src/utils/cpp/transformed_range.hpp | 117 |
4 files changed, 1 insertions, 212 deletions
diff --git a/src/buildtool/execution_api/common/TARGETS b/src/buildtool/execution_api/common/TARGETS index edb815b9..e2dd5d3b 100644 --- a/src/buildtool/execution_api/common/TARGETS +++ b/src/buildtool/execution_api/common/TARGETS @@ -125,11 +125,7 @@ { "type": ["@", "rules", "CC", "library"] , "name": ["content_blob_container"] , "hdrs": ["content_blob_container.hpp"] - , "deps": - [ ["@", "gsl", "", "gsl"] - , ["src/utils/cpp", "hash_combine"] - , ["src/utils/cpp", "transformed_range"] - ] + , "deps": [["@", "gsl", "", "gsl"], ["src/utils/cpp", "hash_combine"]] , "stage": ["src", "buildtool", "execution_api", "common"] } , "artifact_blob_container": diff --git a/src/buildtool/execution_api/common/content_blob_container.hpp b/src/buildtool/execution_api/common/content_blob_container.hpp index bc546ac4..d92c4961 100644 --- a/src/buildtool/execution_api/common/content_blob_container.hpp +++ b/src/buildtool/execution_api/common/content_blob_container.hpp @@ -19,13 +19,10 @@ #include <functional> #include <memory> #include <string> -#include <unordered_map> #include <utility> //std::move -#include <vector> #include "gsl/gsl" #include "src/utils/cpp/hash_combine.hpp" -#include "src/utils/cpp/transformed_range.hpp" template <typename TDigest> struct ContentBlob final { @@ -63,84 +60,4 @@ struct hash<ContentBlob<TDigest>> { }; } // namespace std -template <typename TDigest> -class ContentBlobContainer final { - public: - using DigestType = TDigest; - using BlobType = ContentBlob<TDigest>; - - ContentBlobContainer() noexcept = default; - explicit ContentBlobContainer(std::vector<BlobType> blobs) { - blobs_.reserve(blobs.size()); - for (auto& blob : blobs) { - this->Emplace(std::move(blob)); - } - } - - /// \brief Emplace new Blob to container. - void Emplace(BlobType&& blob) { - DigestType digest = blob.digest; - if (auto res = blobs_.emplace(std::move(digest), std::move(blob)); - res.second) { - // only count size if blob was actually added - content_size_ += res.first->second.data->size(); - } - } - - /// \brief Clear all Blobs from container. - void Clear() noexcept { - blobs_.clear(); - content_size_ = 0; - } - - /// \brief Number of Blobs in container. - [[nodiscard]] auto Size() const noexcept -> std::size_t { - return blobs_.size(); - } - - /// \brief Collective size of the stored content in container. - [[nodiscard]] auto ContentSize() const noexcept -> std::size_t { - return content_size_; - } - - /// \brief Is equivalent BazelBlob (with same Digest) in container. - /// \param[in] blob BazelBlob to search equivalent BazelBlob for - [[nodiscard]] auto Contains(BlobType const& blob) const noexcept -> bool { - return blobs_.contains(blob.digest); - } - - /// \brief Obtain iterable list of Blobs from container. - [[nodiscard]] auto Blobs() const noexcept { - auto converter = [](auto const& p) -> BlobType const& { - return p.second; - }; - return TransformedRange{ - blobs_.cbegin(), blobs_.cend(), std::move(converter)}; - } - - /// \brief Obtain iterable list of Digests from container. - [[nodiscard]] auto Digests() const noexcept { - auto converter = [](auto const& p) -> DigestType const& { - return p.first; - }; - return TransformedRange{ - blobs_.cbegin(), blobs_.cend(), std::move(converter)}; - } - - /// \brief Obtain iterable list of BazelBlobs related to Digests. - /// \param[in] related Related Digests - [[nodiscard]] auto RelatedBlobs( - std::vector<DigestType> const& related) const noexcept { - auto converter = [this](auto const& digest) -> BlobType const& { - return blobs_.at(digest); - }; - return TransformedRange{ - related.begin(), related.end(), std::move(converter)}; - }; - - private: - std::unordered_map<DigestType, BlobType> blobs_{}; - std::size_t content_size_{}; -}; - #endif // INCLUDED_SRC_BUILDTOOL_EXECUTION_API_COMMON_CONTENT_BLOB_CONTAINER_HPP diff --git a/src/utils/cpp/TARGETS b/src/utils/cpp/TARGETS index 509aae03..b7d5d3c7 100644 --- a/src/utils/cpp/TARGETS +++ b/src/utils/cpp/TARGETS @@ -94,13 +94,6 @@ , "hdrs": ["path_hash.hpp"] , "stage": ["src", "utils", "cpp"] } -, "transformed_range": - { "type": ["@", "rules", "CC", "library"] - , "name": ["transformed_range"] - , "hdrs": ["transformed_range.hpp"] - , "deps": [["@", "gsl", "", "gsl"]] - , "stage": ["src", "utils", "cpp"] - } , "prefix": { "type": ["@", "rules", "CC", "library"] , "name": ["prefix"] diff --git a/src/utils/cpp/transformed_range.hpp b/src/utils/cpp/transformed_range.hpp deleted file mode 100644 index f63f2325..00000000 --- a/src/utils/cpp/transformed_range.hpp +++ /dev/null @@ -1,117 +0,0 @@ -// Copyright 2024 Huawei Cloud Computing Technology Co., Ltd. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#ifndef INCLUDED_SRC_OTHER_TOOLS_TRANSFORMED_RANGE_HPP -#define INCLUDED_SRC_OTHER_TOOLS_TRANSFORMED_RANGE_HPP - -#include <cstddef> -#include <functional> -#include <iterator> -#include <type_traits> -#include <utility> // IWYU pragma: keep -#include <vector> - -#include "gsl/gsl" - -// TODO(modernize): Replace any use of this class by C++20's -// std::ranges/std::views (clang version >= 16.0.0) - -/// \brief Transform iterable sequence "on the fly" invoking the given -/// transformation callback. If the callback throws an exception, -/// std::terminate is called. -/// \tparam TIterator Type of the iterator of the sequence to be -/// transformed. -/// \tparam Result Type of the transformation result. -template <typename TIterator, typename Result> -class TransformedRange final { - public: - using converter_t = - std::function<Result(typename TIterator::value_type const&)>; - - class Iterator final { - public: - using value_type = std::remove_reference_t<Result>; - using pointer = value_type*; - using reference = value_type&; - using difference_type = std::ptrdiff_t; - using iterator_category = std::forward_iterator_tag; - - Iterator() noexcept = default; - Iterator(TIterator Iterator, converter_t c) noexcept - : iterator_(std::move(Iterator)), c_(std::move(c)) {} - - auto operator*() const noexcept -> decltype(auto) { - try { - return std::invoke(c_, *iterator_); - } catch (...) { - Ensures(false); - } - } - - auto operator++() noexcept -> Iterator& { - ++iterator_; - return *this; - } - - [[nodiscard]] friend auto operator==(Iterator const& lhs, - Iterator const& rhs) noexcept - -> bool { - return lhs.iterator_ == rhs.iterator_; - } - - [[nodiscard]] friend auto operator!=(Iterator const& lhs, - Iterator const& rhs) noexcept - -> bool { - return not(lhs == rhs); - } - - private: - TIterator iterator_{}; - converter_t c_{}; - }; - - TransformedRange(TIterator begin, TIterator end, converter_t c) noexcept - : begin_{std::move(begin), std::move(c)}, - end_{std::move(end), nullptr} {} - - [[nodiscard]] auto begin() const noexcept -> Iterator { return begin_; } - [[nodiscard]] auto end() const noexcept -> Iterator { return end_; } - [[nodiscard]] auto size() const -> typename Iterator::difference_type { - return std::distance(begin_, end_); - } - - [[nodiscard]] auto ToVector() const -> std::vector<Result> { - std::vector<Result> result; - result.reserve(gsl::narrow<std::size_t>(size())); - for (auto item : *this) { - result.emplace_back(std::move(item)); - } - return result; - } - - private: - Iterator const begin_; - Iterator const end_; -}; - -// User-defined deduction guide to help compiler dealing with generic lambdas -// and invokable objects. -template <typename TIterator, - typename Function, - typename IteratorValue = typename TIterator::value_type> -TransformedRange(TIterator, TIterator, Function) - -> TransformedRange<TIterator, - std::invoke_result_t<Function, IteratorValue>>; - -#endif // INCLUDED_SRC_OTHER_TOOLS_TRANSFORMED_RANGE_HPP |