Skip to content

Commit be4c14f

Browse files
authored
Do not construct backtrace for opt (#5198)
Signed-off-by: Nicholas Gates <[email protected]>
1 parent 6d2c632 commit be4c14f

File tree

2 files changed

+19
-25
lines changed

2 files changed

+19
-25
lines changed

vortex-expr/src/expression.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,12 @@ impl Expression {
7979
///
8080
/// Panics if the expression's encoding or metadata cannot be cast to the specified vtable.
8181
pub fn as_<V: VTable>(&self) -> ExpressionView<'_, V> {
82-
ExpressionView::try_new(self).vortex_expect("Failed to downcast expression {} to {}")
82+
ExpressionView::maybe_new(self).vortex_expect("Failed to downcast expression {} to {}")
8383
}
8484

8585
/// Returns a typed view of this expression for the given vtable, if the types match.
8686
pub fn as_opt<V: VTable>(&self) -> Option<ExpressionView<'_, V>> {
87-
ExpressionView::try_new(self).ok()
87+
ExpressionView::maybe_new(self)
8888
}
8989

9090
/// Returns the expression ID.

vortex-expr/src/view.rs

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
// SPDX-License-Identifier: Apache-2.0
22
// SPDX-FileCopyrightText: Copyright the Vortex contributors
33

4-
use std::any::type_name;
54
use std::ops::Deref;
65

7-
use vortex_error::{VortexExpect, VortexResult, vortex_err};
6+
use vortex_error::VortexExpect;
87

98
use crate::{Expression, VTable};
109

1110
/// A view over an [`Expression`] with an associated vtable, allowing typed access to the
1211
/// expression's instance data.
1312
pub struct ExpressionView<'a, V: VTable> {
1413
expression: &'a Expression,
14+
vtable: &'a V,
1515
data: &'a V::Instance,
1616
}
1717

@@ -23,35 +23,29 @@ impl<'a, V: VTable> ExpressionView<'a, V> {
2323
/// Panics if the expression cannot be downcast to the specified vtable type.
2424
#[inline]
2525
pub fn new(expression: &'a Expression) -> Self {
26-
Self::try_new(expression).vortex_expect("Failed to downcast expression")
26+
Self::maybe_new(expression).vortex_expect("Failed to downcast expression")
2727
}
2828

2929
/// Attempts to wrap up the given expression as an [`ExpressionView`] of the specified vtable type.
3030
#[inline]
31-
pub fn try_new(expression: &'a Expression) -> VortexResult<Self> {
32-
expression.vtable().as_opt::<V>().ok_or_else(|| {
33-
vortex_err!(
34-
"Failed to downcast {} to {}",
35-
expression.id(),
36-
type_name::<V>()
37-
)
38-
})?;
39-
40-
let data = expression
41-
.data()
42-
.downcast_ref::<V::Instance>()
43-
.ok_or_else(|| {
44-
vortex_err!(
45-
"Failed to downcast expression instance data to expected type {}",
46-
type_name::<V::Instance>()
47-
)
48-
})?;
49-
50-
Ok(Self { expression, data })
31+
pub fn maybe_new(expression: &'a Expression) -> Option<Self> {
32+
let vtable = expression.vtable().as_opt::<V>()?;
33+
let data = expression.data().downcast_ref::<V::Instance>()?;
34+
Some(Self {
35+
expression,
36+
vtable,
37+
data,
38+
})
5139
}
5240
}
5341

5442
impl<'a, V: VTable> ExpressionView<'a, V> {
43+
/// Returns the vtable for this expression.
44+
#[inline(always)]
45+
pub fn vtable(&self) -> &'a V {
46+
self.vtable
47+
}
48+
5549
/// Returns the instance data for this expression.
5650
#[inline(always)]
5751
pub fn data(&self) -> &'a V::Instance {

0 commit comments

Comments
 (0)