Skip to content

Commit

Permalink
use unsafe for downcasting as it never fails
Browse files Browse the repository at this point in the history
  • Loading branch information
ritchie46 committed Sep 11, 2020
1 parent 90d8a88 commit 945cda3
Showing 1 changed file with 9 additions and 13 deletions.
22 changes: 9 additions & 13 deletions polars/src/chunked_array/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ pub mod temporal;
pub mod unique;
pub mod upstream_traits;
use arrow::array::{
ArrayDataRef, Date32Array, DurationMicrosecondArray, DurationMillisecondArray,
Array, ArrayDataRef, Date32Array, DurationMicrosecondArray, DurationMillisecondArray,
DurationNanosecondArray, DurationSecondArray, IntervalDayTimeArray, IntervalYearMonthArray,
LargeListArray, Time32MillisecondArray, Time32SecondArray, Time64MicrosecondArray,
TimestampMicrosecondArray, TimestampMillisecondArray, TimestampNanosecondArray,
Expand Down Expand Up @@ -747,9 +747,8 @@ where
self.chunks
.iter()
.map(|arr| {
arr.as_any()
.downcast_ref::<PrimitiveArray<T>>()
.expect("could not downcast one of the chunks")
let arr = &**arr;
unsafe { &*(arr as *const dyn Array as *const PrimitiveArray<T>) }
})
.collect::<Vec<_>>()
}
Expand All @@ -760,9 +759,8 @@ impl Downcast<StringArray> for Utf8Chunked {
self.chunks
.iter()
.map(|arr| {
arr.as_any()
.downcast_ref()
.expect("could not downcast one of the chunks")
let arr = &**arr;
unsafe { &*(arr as *const dyn Array as *const StringArray) }
})
.collect::<Vec<_>>()
}
Expand All @@ -773,9 +771,8 @@ impl Downcast<BooleanArray> for BooleanChunked {
self.chunks
.iter()
.map(|arr| {
arr.as_any()
.downcast_ref()
.expect("could not downcast one of the chunks")
let arr = &**arr;
unsafe { &*(arr as *const dyn Array as *const BooleanArray) }
})
.collect::<Vec<_>>()
}
Expand All @@ -786,9 +783,8 @@ impl Downcast<LargeListArray> for LargeListChunked {
self.chunks
.iter()
.map(|arr| {
arr.as_any()
.downcast_ref()
.expect("could not downcast one of the chunks")
let arr = &**arr;
unsafe { &*(arr as *const dyn Array as *const LargeListArray) }
})
.collect::<Vec<_>>()
}
Expand Down

0 comments on commit 945cda3

Please sign in to comment.