Skip to content

Commit 8f13bda

Browse files
feat[array]: use transmute for up/down cast of Arc<Array> (#7140)
Prefer transmute over into/from_raw Signed-off-by: Joe Isaacs <joe.isaacs@live.co.uk>
1 parent 9f0f8ff commit 8f13bda

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

vortex-array/src/vtable/dyn_.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// SPDX-FileCopyrightText: Copyright the Vortex contributors
33

44
use std::fmt::Debug;
5+
use std::mem::transmute;
56
use std::sync::Arc;
67

78
use arcref::ArcRef;
@@ -222,8 +223,7 @@ fn downcast_owned<V: VTable>(array: ArrayRef) -> Arc<V::Array> {
222223
.vortex_expect("Failed to downcast array to expected encoding type");
223224
// SAFETY: ArrayAdapter<V> is #[repr(transparent)] over V::Array,
224225
// so Arc<ArrayAdapter<V>> and Arc<V::Array> have identical layout.
225-
let raw = Arc::into_raw(adapter) as *const V::Array;
226-
unsafe { Arc::from_raw(raw) }
226+
unsafe { transmute::<Arc<ArrayAdapter<V>>, Arc<V::Array>>(adapter) }
227227
}
228228

229229
/// Upcast an `Arc<V::Array>` into an `ArrayRef` without cloning.
@@ -233,6 +233,5 @@ fn downcast_owned<V: VTable>(array: ArrayRef) -> Arc<V::Array> {
233233
pub(crate) fn upcast_array<V: VTable>(array: Arc<V::Array>) -> ArrayRef {
234234
// SAFETY: ArrayAdapter<V> is #[repr(transparent)] over V::Array,
235235
// so Arc<V::Array> and Arc<ArrayAdapter<V>> have identical layout.
236-
let raw = Arc::into_raw(array) as *const ArrayAdapter<V>;
237-
unsafe { Arc::from_raw(raw) }
236+
unsafe { transmute::<Arc<V::Array>, Arc<ArrayAdapter<V>>>(array) }
238237
}

0 commit comments

Comments
 (0)