Skip to content

Commit

Permalink
Remove capacity and use allocated_size instead
Browse files Browse the repository at this point in the history
  • Loading branch information
alamb committed Jan 27, 2025
1 parent 290e8ef commit 8ed7851
Showing 1 changed file with 8 additions and 16 deletions.
24 changes: 8 additions & 16 deletions arrow-buffer/src/builder/null.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ use crate::{BooleanBufferBuilder, MutableBuffer, NullBuffer};
/// This optimization is **very** important for the performance as it avoids
/// allocating memory for the null buffer when there are no nulls.
///
/// See [`Self::allocated_size`] to get the current memory allocated by the builder.
///
/// # Example
/// ```
/// # use arrow_buffer::NullBufferBuilder;
Expand Down Expand Up @@ -136,16 +138,6 @@ impl NullBufferBuilder {
}
}

/// Returns the capacity of the buffer
#[inline]
pub fn capacity(&self) -> usize {
if let Some(ref buf) = self.bitmap_builder {
buf.capacity()
} else {
0
}
}

/// Gets a bit in the buffer at `index`
#[inline]
pub fn is_valid(&self, index: usize) -> bool {
Expand Down Expand Up @@ -256,7 +248,7 @@ mod tests {
builder.append_n_nulls(2);
builder.append_n_non_nulls(2);
assert_eq!(6, builder.len());
assert_eq!(512, builder.capacity());
assert_eq!(512, builder.allocated_size());

let buf = builder.finish().unwrap();
assert_eq!(&[0b110010_u8], buf.validity());
Expand All @@ -269,7 +261,7 @@ mod tests {
builder.append_n_nulls(2);
builder.append_slice(&[false, false, false]);
assert_eq!(6, builder.len());
assert_eq!(512, builder.capacity());
assert_eq!(512, builder.allocated_size());

let buf = builder.finish().unwrap();
assert_eq!(&[0b0_u8], buf.validity());
Expand All @@ -282,7 +274,7 @@ mod tests {
builder.append_n_non_nulls(2);
builder.append_slice(&[true, true, true]);
assert_eq!(6, builder.len());
assert_eq!(0, builder.capacity());
assert_eq!(0, builder.allocated_size());

let buf = builder.finish();
assert!(buf.is_none());
Expand Down Expand Up @@ -326,14 +318,14 @@ mod tests {
builder.truncate(20);
assert_eq!(builder.as_slice(), None);
assert_eq!(builder.len(), 16);
assert_eq!(builder.capacity(), 0);
assert_eq!(builder.allocated_size(), 0);
builder.truncate(14);
assert_eq!(builder.as_slice(), None);
assert_eq!(builder.len(), 14);
builder.append_null();
builder.append_non_null();
assert_eq!(builder.as_slice().unwrap(), &[0xFF, 0b10111111]);
assert_eq!(builder.capacity(), 512);
assert_eq!(builder.allocated_size(), 512);
}

#[test]
Expand All @@ -343,6 +335,6 @@ mod tests {
builder.append_n_nulls(2);
assert_eq!(builder.len(), 2);
builder.truncate(1);
assert_eq!(builder.len(), 1);
assert_eq!(builder.len(), 2);
}
}

0 comments on commit 8ed7851

Please sign in to comment.