From 94cfdd9fd62c8e21ef4d0881d2a248154afc1a00 Mon Sep 17 00:00:00 2001 From: Paul Cristian Sarbu Date: Mon, 3 Jun 2024 11:42:14 +0200 Subject: 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. --- .../common/content_blob_container.hpp | 23 +++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) (limited to 'src/buildtool/execution_api/common/content_blob_container.hpp') 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 blobs_{}; + std::size_t content_size_{}; }; #endif // INCLUDED_SRC_BUILDTOOL_EXECUTION_API_COMMON_CONTENT_BLOB_CONTAINER_HPP -- cgit v1.2.3