From 822fe801052ee74fbdbd0ee3ea45e2ca1a0fd62c Mon Sep 17 00:00:00 2001 From: Stephen Chung Date: Fri, 25 Dec 2020 11:02:29 +0800 Subject: [PATCH] Reduce redirections. --- src/ast.rs | 6 +++--- src/engine.rs | 16 ++++++++-------- src/optimize.rs | 2 +- src/parser.rs | 4 ++-- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/ast.rs b/src/ast.rs index 546c17ee..702a1ad5 100644 --- a/src/ast.rs +++ b/src/ast.rs @@ -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>, 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, diff --git a/src/engine.rs b/src/engine.rs index 58e7b930..bbef90bd 100644 --- a/src/engine.rs +++ b/src/engine.rs @@ -1091,7 +1091,7 @@ impl Engine { Expr::FnCall(_, _) => unreachable!(), // {xxx:map}.id = ??? Expr::Property(x) if target_val.is::() && 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::() => { - 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::() => { 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.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, diff --git a/src/optimize.rs b/src/optimize.rs index 7c032d30..06c94f46 100644 --- a/src/optimize.rs +++ b/src/optimize.rs @@ -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(); diff --git a/src/parser.rs b/src/parser.rs index 342fe94c..5a3b9747 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -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) }