Optimize IndexChainValue usage.

This commit is contained in:
Stephen Chung 2020-11-19 13:51:59 +08:00
parent 0e4743e7c7
commit a00d6ba99e

View File

@ -224,7 +224,7 @@ impl IndexChainValue {
#[cfg(not(feature = "no_index"))] #[cfg(not(feature = "no_index"))]
pub fn as_value(self) -> Dynamic { pub fn as_value(self) -> Dynamic {
match self { match self {
Self::None | Self::FnCallArgs(_) => panic!("expecting IndexChainValue::Value"), Self::None | Self::FnCallArgs(_) => unreachable!("expecting IndexChainValue::Value"),
Self::Value(value) => value, Self::Value(value) => value,
} }
} }
@ -236,7 +236,7 @@ impl IndexChainValue {
#[cfg(not(feature = "no_object"))] #[cfg(not(feature = "no_object"))]
pub fn as_fn_call_args(self) -> StaticVec<Dynamic> { pub fn as_fn_call_args(self) -> StaticVec<Dynamic> {
match self { match self {
Self::None | Self::Value(_) => panic!("expecting IndexChainValue::FnCallArgs"), Self::None | Self::Value(_) => unreachable!("expecting IndexChainValue::FnCallArgs"),
Self::FnCallArgs(value) => value, Self::FnCallArgs(value) => value,
} }
} }
@ -939,7 +939,7 @@ impl Engine {
this_ptr: &mut Option<&mut Dynamic>, this_ptr: &mut Option<&mut Dynamic>,
target: &mut Target, target: &mut Target,
rhs: &Expr, rhs: &Expr,
mut idx_values: StaticVec<IndexChainValue>, idx_values: &mut StaticVec<IndexChainValue>,
chain_type: ChainType, chain_type: ChainType,
level: usize, level: usize,
new_val: Option<(Dynamic, Position)>, new_val: Option<(Dynamic, Position)>,
@ -1261,19 +1261,10 @@ impl Engine {
_ => unreachable!(), _ => unreachable!(),
}; };
let mut idx_values = StaticVec::new(); let idx_values = &mut Default::default();
self.eval_indexed_chain( self.eval_indexed_chain(
scope, scope, mods, state, lib, this_ptr, rhs, chain_type, idx_values, 0, level,
mods,
state,
lib,
this_ptr,
rhs,
chain_type,
&mut idx_values,
0,
level,
)?; )?;
match lhs { match lhs {