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

Commit

Permalink
Avoided double checks in building an Utf8Array from Mutable.
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgecarleitao committed Oct 30, 2021
1 parent 5fc843d commit 13aee96
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/array/utf8/mutable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,17 @@ pub struct MutableUtf8Array<O: Offset> {

impl<O: Offset> From<MutableUtf8Array<O>> for Utf8Array<O> {
fn from(other: MutableUtf8Array<O>) -> Self {
Utf8Array::<O>::from_data(
other.data_type,
other.offsets.into(),
other.values.into(),
other.validity.map(|x| x.into()),
)
// Safety:
// `MutableUtf8Array` has the same invariants as `Utf8Array` and thus
// `Utf8Array` can be safely crated from `MutableUtf8Array` without checks.
unsafe {
Utf8Array::<O>::from_data_unchecked(
other.data_type,
other.offsets.into(),
other.values.into(),
other.validity.map(|x| x.into()),
)
}
}
}

Expand Down

0 comments on commit 13aee96

Please sign in to comment.