summaryrefslogtreecommitdiffstats
path: root/yql/essentials/utils/chunked_buffer.cpp
diff options
context:
space:
mode:
authoraneporada <[email protected]>2024-11-08 22:23:41 +0300
committeraneporada <[email protected]>2024-11-08 22:36:11 +0300
commit7a852449509797b666bf1ad202836dcd0408b584 (patch)
treed38401518ed5ec38d786e659d8d27531b8793508 /yql/essentials/utils/chunked_buffer.cpp
parent1885c7f026a96d8fd5c7eced266e381c1d8bdfee (diff)
Fast TChunkedBuffer::Size()
commit_hash:6dd56a3c0d552a30b3e30a2b133d638716e1893d
Diffstat (limited to 'yql/essentials/utils/chunked_buffer.cpp')
-rw-r--r--yql/essentials/utils/chunked_buffer.cpp26
1 files changed, 10 insertions, 16 deletions
diff --git a/yql/essentials/utils/chunked_buffer.cpp b/yql/essentials/utils/chunked_buffer.cpp
index 906da8dcae8..7ae66d04efc 100644
--- a/yql/essentials/utils/chunked_buffer.cpp
+++ b/yql/essentials/utils/chunked_buffer.cpp
@@ -6,10 +6,14 @@ namespace NYql {
TChunkedBuffer::TChunkedBuffer(TChunkedBuffer&& other) {
Items_ = std::move(other.Items_);
+ Size_ = other.Size_;
+ other.Size_ = 0;
}
TChunkedBuffer& TChunkedBuffer::operator=(TChunkedBuffer&& other) {
Items_ = std::move(other.Items_);
+ Size_ = other.Size_;
+ other.Size_ = 0;
return *this;
}
@@ -40,25 +44,10 @@ size_t TChunkedBuffer::CopyTo(IOutputStream& dst, size_t toCopy) const {
return copied;
}
-size_t TChunkedBuffer::ContigousSize() const {
- return Items_.empty() ? 0 : Front().Buf.size();
-}
-
-size_t TChunkedBuffer::Size() const {
- size_t result = 0;
- for (auto& item : Items_) {
- result += item.Buf.size();
- }
- return result;
-}
-
-bool TChunkedBuffer::Empty() const {
- return Items_.empty();
-}
-
TChunkedBuffer& TChunkedBuffer::Append(TStringBuf buf, const std::shared_ptr<const void>& owner) {
if (!buf.empty()) {
Items_.emplace_back(TChunk{buf, owner});
+ Size_ += buf.size();
}
return *this;
}
@@ -67,6 +56,7 @@ TChunkedBuffer& TChunkedBuffer::Append(TString&& str) {
if (!str.empty()) {
auto owner = std::make_shared<TString>(std::move(str));
Items_.emplace_back(TChunk{*owner, owner});
+ Size_ += owner->size();
}
return *this;
}
@@ -74,13 +64,16 @@ TChunkedBuffer& TChunkedBuffer::Append(TString&& str) {
TChunkedBuffer& TChunkedBuffer::Append(TChunkedBuffer&& other) {
while (!other.Items_.empty()) {
Items_.emplace_back(std::move(other.Items_.front()));
+ Size_ += Items_.back().Buf.size();
other.Items_.pop_front();
}
+ other.Size_ = 0;
return *this;
}
TChunkedBuffer& TChunkedBuffer::Clear() {
Items_.clear();
+ Size_ = 0;
return *this;
}
@@ -90,6 +83,7 @@ TChunkedBuffer& TChunkedBuffer::Erase(size_t size) {
size_t toErase = std::min(buf.size(), size);
buf.Skip(toErase);
size -= toErase;
+ Size_ -= toErase;
if (buf.empty()) {
Items_.pop_front();
}