Skip to content
This repository has been archived by the owner on Feb 18, 2024. It is now read-only.

Commit

Permalink
process comments and apply them to 'extend_trusted_len' as well
Browse files Browse the repository at this point in the history
  • Loading branch information
ritchie46 committed Sep 6, 2021
1 parent 8aab406 commit dc9925f
Showing 1 changed file with 10 additions and 15 deletions.
25 changes: 10 additions & 15 deletions src/array/primitive/mutable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,8 @@ impl<T: NativeType> MutablePrimitiveArray<T> {
if let Some(validity) = self.validity.as_mut() {
extend_trusted_len_unzip(iterator, validity, &mut self.values)
} else {
let mut validity =
MutableBitmap::from_trusted_len_iter(std::iter::repeat(true).take(self.len()));
let mut validity = MutableBitmap::new();
validity.extend_constant(self.len(), true);
extend_trusted_len_unzip(iterator, &mut validity, &mut self.values);
if validity.null_count() > 0 {
self.validity = Some(validity);
Expand All @@ -174,7 +174,6 @@ impl<T: NativeType> MutablePrimitiveArray<T> {
}
/// Extends the [`MutablePrimitiveArray`] from an iterator of values of trusted len.
/// This differs from `extend_trusted_len` which accepts in iterator of optional values.
#[inline]
pub fn extend_trusted_len_values<I>(&mut self, iterator: I)
where
I: TrustedLen<Item = T>,
Expand All @@ -186,33 +185,29 @@ impl<T: NativeType> MutablePrimitiveArray<T> {
/// This differs from `extend_trusted_len_unchecked` which accepts in iterator of optional values.
/// # Safety
/// The iterator must be trusted len.
#[inline]
pub unsafe fn extend_trusted_len_values_unchecked<I>(&mut self, iterator: I)
where
I: Iterator<Item = T>,
{
let size = iterator
.size_hint()
.1
.expect("upper bound should be set by trusted len iter");
self.values.extend_from_trusted_len_iter_unchecked(iterator);
self.update_all_valid(size);
self.update_all_valid();
}

#[inline]
/// Extends the [`MutablePrimitiveArray`] from a slice
pub fn extend_from_slice(&mut self, items: &[T]) {
self.values.extend_from_slice(items);
self.update_all_valid(items.len());
self.update_all_valid();
}

fn update_all_valid(&mut self, additional: usize) {
fn update_all_valid(&mut self) {
// get len before mutable borrow
let len = self.len();
if let Some(validity) = self.validity.as_mut() {
validity.extend_constant(additional, true);
validity.extend_constant(len - validity.len(), true);
} else {
let validity = MutableBitmap::from_trusted_len_iter(
std::iter::repeat(true).take(self.len() + additional),
);
let mut validity = MutableBitmap::new();
validity.extend_constant(len, true);
if validity.null_count() > 0 {
self.validity = Some(validity);
}
Expand Down

0 comments on commit dc9925f

Please sign in to comment.