diff options
author | Paul Cristian Sarbu <paul.cristian.sarbu@huawei.com> | 2024-06-03 11:42:14 +0200 |
---|---|---|
committer | Paul Cristian Sarbu <paul.cristian.sarbu@huawei.com> | 2024-06-04 13:47:11 +0200 |
commit | 94cfdd9fd62c8e21ef4d0881d2a248154afc1a00 (patch) | |
tree | c6e1399367e43204ce2885c2dfa0ad1ce91c3e19 /src | |
parent | d81681792d316819444861049f8d2d59af17889e (diff) | |
download | justbuild-94cfdd9fd62c8e21ef4d0881d2a248154afc1a00.tar.gz |
ContentBlobContainer: Add content size field
As the ContentBlobContainer is used to store actual content needed
to be transferred, it is useful to automatically keep track of the
running (bytes) size of the data being stored.
Diffstat (limited to 'src')
-rw-r--r-- | src/buildtool/execution_api/common/content_blob_container.hpp | 23 |
1 files changed, 18 insertions, 5 deletions
diff --git a/src/buildtool/execution_api/common/content_blob_container.hpp b/src/buildtool/execution_api/common/content_blob_container.hpp index f2d7476e..f15187f1 100644 --- a/src/buildtool/execution_api/common/content_blob_container.hpp +++ b/src/buildtool/execution_api/common/content_blob_container.hpp @@ -56,20 +56,32 @@ class ContentBlobContainer final { } } - /// \brief Emplace new BazelBlob to container. + /// \brief Emplace new Blob to container. void Emplace(BlobType&& blob) { DigestType digest = blob.digest; - blobs_.emplace(std::move(digest), std::move(blob)); + 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 BazelBlobs from container. - void Clear() noexcept { return blobs_.clear(); } + /// \brief Clear all Blobs from container. + void Clear() noexcept { + blobs_.clear(); + content_size_ = 0; + } - /// \brief Number of BazelBlobs in container. + /// \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 { @@ -107,6 +119,7 @@ class ContentBlobContainer final { private: std::unordered_map<DigestType, BlobType> blobs_{}; + std::size_t content_size_{}; }; #endif // INCLUDED_SRC_BUILDTOOL_EXECUTION_API_COMMON_CONTENT_BLOB_CONTAINER_HPP |