Reduce redirections.

This commit is contained in:
Stephen Chung 2020-12-25 11:02:29 +08:00
parent 8f969b1ab5
commit 822fe80105
4 changed files with 14 additions and 14 deletions

View File

@ -970,7 +970,7 @@ pub enum Expr {
)>,
),
/// Property access - (getter, setter), prop
Property(Box<((ImmutableString, ImmutableString), Ident)>),
Property(Box<(ImmutableString, ImmutableString, Ident)>),
/// { [statement][Stmt] }
Stmt(Box<StaticVec<Stmt>>, Position),
/// Wrapped [expression][`Expr`] - should not be optimized away.
@ -1068,7 +1068,7 @@ impl Expr {
Self::FnPointer(_, pos) => *pos,
Self::Array(_, pos) => *pos,
Self::Map(_, pos) => *pos,
Self::Property(x) => (x.1).pos,
Self::Property(x) => (x.2).pos,
Self::Stmt(_, pos) => *pos,
Self::Variable(x) => (x.2).pos,
Self::FnCall(_, pos) => *pos,
@ -1101,7 +1101,7 @@ impl Expr {
Self::Array(_, pos) => *pos = new_pos,
Self::Map(_, pos) => *pos = new_pos,
Self::Variable(x) => (x.2).pos = new_pos,
Self::Property(x) => (x.1).pos = new_pos,
Self::Property(x) => (x.2).pos = new_pos,
Self::Stmt(_, pos) => *pos = new_pos,
Self::FnCall(_, pos) => *pos = new_pos,
Self::And(_, pos) | Self::Or(_, pos) | Self::In(_, pos) => *pos = new_pos,

View File

@ -1091,7 +1091,7 @@ impl Engine {
Expr::FnCall(_, _) => unreachable!(),
// {xxx:map}.id = ???
Expr::Property(x) if target_val.is::<Map>() && new_val.is_some() => {
let Ident { name, pos } = &x.1;
let Ident { name, pos } = &x.2;
let index = name.clone().into();
let mut val = self.get_indexed_mut(
mods, state, lib, target_val, index, *pos, true, is_ref, false, level,
@ -1104,7 +1104,7 @@ impl Engine {
}
// {xxx:map}.id
Expr::Property(x) if target_val.is::<Map>() => {
let Ident { name, pos } = &x.1;
let Ident { name, pos } = &x.2;
let index = name.clone().into();
let val = self.get_indexed_mut(
mods, state, lib, target_val, index, *pos, false, is_ref, false, level,
@ -1114,7 +1114,7 @@ impl Engine {
}
// xxx.id = ???
Expr::Property(x) if new_val.is_some() => {
let ((_, setter), Ident { pos, .. }) = x.as_ref();
let (_, setter, Ident { pos, .. }) = x.as_ref();
let mut new_val = new_val;
let mut args = [target_val, &mut new_val.as_mut().unwrap().0];
self.exec_fn_call(
@ -1126,7 +1126,7 @@ impl Engine {
}
// xxx.id
Expr::Property(x) => {
let ((getter, _), Ident { pos, .. }) = x.as_ref();
let (getter, _, Ident { pos, .. }) = x.as_ref();
let mut args = [target_val];
self.exec_fn_call(
mods, state, lib, getter, None, &mut args, is_ref, true, false, *pos,
@ -1139,7 +1139,7 @@ impl Engine {
Expr::Index(x, x_pos) | Expr::Dot(x, x_pos) if target_val.is::<Map>() => {
let mut val = match &x.lhs {
Expr::Property(p) => {
let Ident { name, pos } = &p.1;
let Ident { name, pos } = &p.2;
let index = name.clone().into();
self.get_indexed_mut(
mods, state, lib, target_val, index, *pos, false, is_ref, true,
@ -1179,7 +1179,7 @@ impl Engine {
match &x.lhs {
// xxx.prop[expr] | xxx.prop.expr
Expr::Property(p) => {
let ((getter, setter), Ident { pos, .. }) = p.as_ref();
let (getter, setter, Ident { pos, .. }) = p.as_ref();
let arg_values = &mut [target_val, &mut Default::default()];
let args = &mut arg_values[..1];
let (mut val, updated) = self
@ -1650,7 +1650,7 @@ impl Engine {
if target.is::<Map>() {
// map.prop - point directly to the item
let (_, Ident { name, pos }) = p.as_ref();
let (_, _, Ident { name, pos }) = p.as_ref();
let idx = name.clone().into();
if target.is_shared() || target.is_value() {
@ -1668,7 +1668,7 @@ impl Engine {
.map(|v| (v, *pos))
} else {
// var.prop - call property getter
let ((getter, _), Ident { pos, .. }) = p.as_ref();
let (getter, _, Ident { pos, .. }) = p.as_ref();
let mut args = [target.as_mut()];
self.exec_fn_call(
mods, state, lib, getter, None, &mut args, is_ref, true, false, *pos,

View File

@ -501,7 +501,7 @@ fn optimize_expr(expr: &mut Expr, state: &mut State) {
Expr::Dot(x, _) => match (&mut x.lhs, &mut x.rhs) {
// map.string
(Expr::Map(m, pos), Expr::Property(p)) if m.iter().all(|(_, x)| x.is_pure()) => {
let prop = &p.1.name;
let prop = &p.2.name;
// Map literal where everything is pure - promote the indexed item.
// All other items can be thrown away.
state.set_dirty();

View File

@ -241,7 +241,7 @@ impl Expr {
let ident = x.2;
let getter = state.get_interned_string(crate::engine::make_getter(&ident.name));
let setter = state.get_interned_string(crate::engine::make_setter(&ident.name));
Self::Property(Box::new(((getter, setter), ident.into())))
Self::Property(Box::new((getter, setter, ident.into())))
}
_ => self,
}
@ -1448,7 +1448,7 @@ fn make_dot_expr(
let ident = x.2;
let getter = state.get_interned_string(crate::engine::make_getter(&ident.name));
let setter = state.get_interned_string(crate::engine::make_setter(&ident.name));
let rhs = Expr::Property(Box::new(((getter, setter), ident)));
let rhs = Expr::Property(Box::new((getter, setter, ident)));
Expr::Dot(Box::new(BinaryExpr { lhs, rhs }), op_pos)
}