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

prevent unneeded offset check #1059

Merged
merged 3 commits into from
Jun 8, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 30 additions & 18 deletions src/array/list/mutable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,16 @@ impl<O: Offset, M: MutableArray + Default> Default for MutableListArray<O, M> {

impl<O: Offset, M: MutableArray> From<MutableListArray<O, M>> for ListArray<O> {
fn from(mut other: MutableListArray<O, M>) -> Self {
ListArray::new(
other.data_type,
other.offsets.into(),
other.values.as_arc(),
other.validity.map(|x| x.into()),
)
// Safety:
// MutableListArray has monotonically increasing offsets
unsafe {
ListArray::new_unchecked(
other.data_type,
other.offsets.into(),
other.values.as_arc(),
other.validity.map(|x| x.into()),
)
}
}
}

Expand Down Expand Up @@ -209,21 +213,29 @@ impl<O: Offset, M: MutableArray + Default + 'static> MutableArray for MutableLis
}

fn as_box(&mut self) -> Box<dyn Array> {
Box::new(ListArray::new(
self.data_type.clone(),
std::mem::take(&mut self.offsets).into(),
self.values.as_arc(),
std::mem::take(&mut self.validity).map(|x| x.into()),
))
// Safety:
// MutableListArray has monotonically increasing offsets
unsafe {
Box::new(ListArray::new_unchecked(
self.data_type.clone(),
std::mem::take(&mut self.offsets).into(),
self.values.as_arc(),
std::mem::take(&mut self.validity).map(|x| x.into()),
))
}
}

fn as_arc(&mut self) -> Arc<dyn Array> {
Arc::new(ListArray::new(
self.data_type.clone(),
std::mem::take(&mut self.offsets).into(),
self.values.as_arc(),
std::mem::take(&mut self.validity).map(|x| x.into()),
))
// Safety:
// MutableListArray has monotonically increasing offsets
unsafe {
Arc::new(ListArray::new_unchecked(
self.data_type.clone(),
std::mem::take(&mut self.offsets).into(),
self.values.as_arc(),
std::mem::take(&mut self.validity).map(|x| x.into()),
))
}
}

fn data_type(&self) -> &DataType {
Expand Down