From 83d62a1dc74b42080cc0449221b01c85aa1e1bdf Mon Sep 17 00:00:00 2001 From: Deepak Majeti Date: Wed, 4 Oct 2023 09:35:47 -0700 Subject: [PATCH] Improve DataBuffer.h code comments (#6638) Summary: Pull Request resolved: https://github.com/facebookincubator/velox/pull/6638 Reviewed By: Yuhta Differential Revision: D49898643 Pulled By: xiaoxmeng fbshipit-source-id: 2bb9d5284570156f72d6c687810d2765172c011d --- velox/dwio/common/DataBuffer.h | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/velox/dwio/common/DataBuffer.h b/velox/dwio/common/DataBuffer.h index b94336e10a03..5c914c14fb92 100644 --- a/velox/dwio/common/DataBuffer.h +++ b/velox/dwio/common/DataBuffer.h @@ -109,7 +109,7 @@ class DataBuffer { buf_ = reinterpret_cast(pool_->allocate(newSize)); } else { buf_ = reinterpret_cast( - pool_->reallocate(buf_, sizeInBytes(capacity_), newSize)); + pool_->reallocate(buf_, capacityInBytes(), newSize)); } VELOX_CHECK(buf_ != nullptr || newSize == 0); capacity_ = capacity; @@ -145,11 +145,11 @@ class DataBuffer { unsafeAppend(offset, src, items); } - /// Sets a value to the specified offset - if offset overflows current - /// capacity It safely allocate more space to meet the request. + /// Sets a value to the specified offset. If offset overflows current + /// capacity, it safely allocates more space to meet the request. void safeSet(uint64_t offset, T value) { if (offset >= capacity_) { - // 50% increasing capacity or offset; + // Increase capacity by 50% or by offset value. const auto size = std::max(offset + 1, capacity_ + ((capacity_ + 1) / 2) + 1); reserve(size); @@ -190,6 +190,7 @@ class DataBuffer { void append(T value) { if (size_ >= capacity_) { + // Increase capacity by 50%. reserve(capacity_ + ((capacity_ + 1) / 2) + 1); } unsafeAppend(value); @@ -225,11 +226,11 @@ class DataBuffer { // The referenced velox buffer. 'buf_' owns the memory when 'veloxRef_' is // nullptr. const velox::BufferPtr veloxRef_{nullptr}; - + // Buffer storing the items. T* buf_; - // current size + // Current number of items of type T. uint64_t size_; - // maximal capacity (actual allocated memory) + // Maximum capacity of items of type T. uint64_t capacity_; }; } // namespace common