From 2c52ee391ff8f2d9e6cd1144ad1b00669801b6b6 Mon Sep 17 00:00:00 2001 From: Runji Wang Date: Fri, 7 Jun 2024 13:23:25 +0800 Subject: [PATCH] rename `capacity` to `item_capacity` in bytes and utf8 array builder Signed-off-by: Runji Wang --- src/common/src/array/bytes_array.rs | 15 ++++++++++----- src/common/src/array/utf8_array.rs | 13 +++++++++---- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/src/common/src/array/bytes_array.rs b/src/common/src/array/bytes_array.rs index 2019c37271919..f3d0f9266a12a 100644 --- a/src/common/src/array/bytes_array.rs +++ b/src/common/src/array/bytes_array.rs @@ -142,19 +142,24 @@ pub struct BytesArrayBuilder { impl ArrayBuilder for BytesArrayBuilder { type ArrayType = BytesArray; - fn new(capacity: usize) -> Self { - let mut offset = Vec::with_capacity(capacity + 1); + /// Creates a new `BytesArrayBuilder`. + /// + /// `item_capacity` is the number of items to pre-allocate. The size of the preallocated + /// buffer of offsets is the number of items plus one. + /// No additional memory is pre-allocated for the data buffer. + fn new(item_capacity: usize) -> Self { + let mut offset = Vec::with_capacity(item_capacity + 1); offset.push(0); Self { offset, - data: Vec::with_capacity(capacity), + data: Vec::with_capacity(0), bitmap: BitmapBuilder::with_capacity(capacity), } } - fn with_type(capacity: usize, ty: DataType) -> Self { + fn with_type(item_capacity: usize, ty: DataType) -> Self { assert_eq!(ty, DataType::Bytea); - Self::new(capacity) + Self::new(item_capacity) } fn append_n<'a>(&'a mut self, n: usize, value: Option<&'a [u8]>) { diff --git a/src/common/src/array/utf8_array.rs b/src/common/src/array/utf8_array.rs index 75d799d026918..5580ab6cc5970 100644 --- a/src/common/src/array/utf8_array.rs +++ b/src/common/src/array/utf8_array.rs @@ -123,15 +123,20 @@ pub struct Utf8ArrayBuilder { impl ArrayBuilder for Utf8ArrayBuilder { type ArrayType = Utf8Array; - fn new(capacity: usize) -> Self { + /// Creates a new `Utf8ArrayBuilder`. + /// + /// `item_capacity` is the number of items to pre-allocate. The size of the preallocated + /// buffer of offsets is the number of items plus one. + /// No additional memory is pre-allocated for the data buffer. + fn new(item_capacity: usize) -> Self { Self { - bytes: BytesArrayBuilder::new(capacity), + bytes: BytesArrayBuilder::new(item_capacity), } } - fn with_type(capacity: usize, ty: DataType) -> Self { + fn with_type(item_capacity: usize, ty: DataType) -> Self { assert_eq!(ty, DataType::Varchar); - Self::new(capacity) + Self::new(item_capacity) } #[inline]