Skip to content

Commit 9f10dfa

Browse files
perf: speed up TryFrom<Scalar> for Primitive (#7223)
Simple Signed-off-by: Joe Isaacs <joe.isaacs@live.co.uk>
1 parent 5ce08ed commit 9f10dfa

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

vortex-array/src/scalar/convert/primitive.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,14 @@ macro_rules! primitive_scalar {
6464
type Error = VortexError;
6565

6666
fn try_from(value: &Scalar) -> VortexResult<Self> {
67-
<Option<$T>>::try_from(value)?
68-
.ok_or_else(|| vortex_err!("Can't extract present value from null scalar"))
67+
match value.value() {
68+
Some(ScalarValue::Primitive(pv)) => pv.cast::<$T>(),
69+
Some(_) => Err(vortex_err!(
70+
"Expected primitive scalar, found {}",
71+
value.dtype()
72+
)),
73+
None => Err(vortex_err!("Can't extract present value from null scalar")),
74+
}
6975
}
7076
}
7177

0 commit comments

Comments
 (0)