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

Commit

Permalink
prevent unneeded offset check
Browse files Browse the repository at this point in the history
  • Loading branch information
ritchie46 committed Jun 8, 2022
1 parent 86e533f commit 720d858
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 30 deletions.
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
32 changes: 20 additions & 12 deletions src/io/avro/read/nested.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,21 +80,29 @@ impl<O: Offset> MutableArray for DynMutableListArray<O> {
}

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

0 comments on commit 720d858

Please sign in to comment.