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

Avoided redundant checks in creating an Utf8Array from MutableUtf8Array #560

Merged
merged 1 commit into from
Oct 31, 2021
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
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 created 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