Skip to content

Commit 8ed7851

Browse files
committed
Remove capacity and use allocated_size instead
1 parent 290e8ef commit 8ed7851

File tree

1 file changed

+8
-16
lines changed

1 file changed

+8
-16
lines changed

arrow-buffer/src/builder/null.rs

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ use crate::{BooleanBufferBuilder, MutableBuffer, NullBuffer};
2828
/// This optimization is **very** important for the performance as it avoids
2929
/// allocating memory for the null buffer when there are no nulls.
3030
///
31+
/// See [`Self::allocated_size`] to get the current memory allocated by the builder.
32+
///
3133
/// # Example
3234
/// ```
3335
/// # use arrow_buffer::NullBufferBuilder;
@@ -136,16 +138,6 @@ impl NullBufferBuilder {
136138
}
137139
}
138140

139-
/// Returns the capacity of the buffer
140-
#[inline]
141-
pub fn capacity(&self) -> usize {
142-
if let Some(ref buf) = self.bitmap_builder {
143-
buf.capacity()
144-
} else {
145-
0
146-
}
147-
}
148-
149141
/// Gets a bit in the buffer at `index`
150142
#[inline]
151143
pub fn is_valid(&self, index: usize) -> bool {
@@ -256,7 +248,7 @@ mod tests {
256248
builder.append_n_nulls(2);
257249
builder.append_n_non_nulls(2);
258250
assert_eq!(6, builder.len());
259-
assert_eq!(512, builder.capacity());
251+
assert_eq!(512, builder.allocated_size());
260252

261253
let buf = builder.finish().unwrap();
262254
assert_eq!(&[0b110010_u8], buf.validity());
@@ -269,7 +261,7 @@ mod tests {
269261
builder.append_n_nulls(2);
270262
builder.append_slice(&[false, false, false]);
271263
assert_eq!(6, builder.len());
272-
assert_eq!(512, builder.capacity());
264+
assert_eq!(512, builder.allocated_size());
273265

274266
let buf = builder.finish().unwrap();
275267
assert_eq!(&[0b0_u8], buf.validity());
@@ -282,7 +274,7 @@ mod tests {
282274
builder.append_n_non_nulls(2);
283275
builder.append_slice(&[true, true, true]);
284276
assert_eq!(6, builder.len());
285-
assert_eq!(0, builder.capacity());
277+
assert_eq!(0, builder.allocated_size());
286278

287279
let buf = builder.finish();
288280
assert!(buf.is_none());
@@ -326,14 +318,14 @@ mod tests {
326318
builder.truncate(20);
327319
assert_eq!(builder.as_slice(), None);
328320
assert_eq!(builder.len(), 16);
329-
assert_eq!(builder.capacity(), 0);
321+
assert_eq!(builder.allocated_size(), 0);
330322
builder.truncate(14);
331323
assert_eq!(builder.as_slice(), None);
332324
assert_eq!(builder.len(), 14);
333325
builder.append_null();
334326
builder.append_non_null();
335327
assert_eq!(builder.as_slice().unwrap(), &[0xFF, 0b10111111]);
336-
assert_eq!(builder.capacity(), 512);
328+
assert_eq!(builder.allocated_size(), 512);
337329
}
338330

339331
#[test]
@@ -343,6 +335,6 @@ mod tests {
343335
builder.append_n_nulls(2);
344336
assert_eq!(builder.len(), 2);
345337
builder.truncate(1);
346-
assert_eq!(builder.len(), 1);
338+
assert_eq!(builder.len(), 2);
347339
}
348340
}

0 commit comments

Comments
 (0)