Reduce usage of as_ref and as_mut.

This commit is contained in:
Stephen Chung
2022-07-05 16:26:38 +08:00
parent 9319f87a7b
commit b6528bd51d
33 changed files with 211 additions and 137 deletions

View File

@@ -248,7 +248,7 @@ impl Engine {
self.inc_operations(&mut global.num_operations, stmt.position())?;
let result = if x.1.lhs.is_variable_access(false) {
let (op_info, BinaryExpr { lhs, rhs }) = x.as_ref();
let (op_info, BinaryExpr { lhs, rhs }) = &**x;
let rhs_result = self
.eval_expr(scope, global, caches, lib, this_ptr, rhs, level)
@@ -294,7 +294,7 @@ impl Engine {
rhs_result
}
} else {
let (op_info, BinaryExpr { lhs, rhs }) = x.as_ref();
let (op_info, BinaryExpr { lhs, rhs }) = &**x;
let rhs_result = self
.eval_expr(scope, global, caches, lib, this_ptr, rhs, level)
@@ -356,7 +356,7 @@ impl Engine {
// If statement
Stmt::If(x, ..) => {
let (expr, if_block, else_block) = x.as_ref();
let (expr, if_block, else_block) = &**x;
let guard_val = self
.eval_expr(scope, global, caches, lib, this_ptr, expr, level)
@@ -399,7 +399,7 @@ impl Engine {
def_case,
ranges,
},
) = x.as_ref();
) = &**x;
let value_result =
self.eval_expr(scope, global, caches, lib, this_ptr, expr, level);
@@ -500,7 +500,7 @@ impl Engine {
// Loop
Stmt::While(x, ..) if matches!(x.0, Expr::Unit(..)) => loop {
let (.., body) = x.as_ref();
let (.., body) = &**x;
if !body.is_empty() {
match self
@@ -521,7 +521,7 @@ impl Engine {
// While loop
Stmt::While(x, ..) => loop {
let (expr, body) = x.as_ref();
let (expr, body) = &**x;
let condition = self
.eval_expr(scope, global, caches, lib, this_ptr, expr, level)
@@ -552,7 +552,7 @@ impl Engine {
// Do loop
Stmt::Do(x, options, ..) => loop {
let (expr, body) = x.as_ref();
let (expr, body) = &**x;
let is_while = !options.contains(ASTFlags::NEGATED);
if !body.is_empty() {
@@ -585,7 +585,7 @@ impl Engine {
// For loop
Stmt::For(x, ..) => {
let (var_name, counter, expr, statements) = x.as_ref();
let (var_name, counter, expr, statements) = &**x;
let iter_result = self
.eval_expr(scope, global, caches, lib, this_ptr, expr, level)
@@ -728,7 +728,7 @@ impl Engine {
name: catch_var, ..
},
catch_block,
} = x.as_ref();
} = &**x;
let result = self
.eval_stmt_block(scope, global, caches, lib, this_ptr, try_block, true, level)
@@ -832,7 +832,7 @@ impl Engine {
}
// Let/const statement
Stmt::Var(x, options, pos) => {
let (var_name, expr, index) = x.as_ref();
let (var_name, expr, index) = &**x;
let access = if options.contains(ASTFlags::CONSTANT) {
AccessMode::ReadOnly
@@ -926,7 +926,7 @@ impl Engine {
// Import statement
#[cfg(not(feature = "no_module"))]
Stmt::Import(x, _pos) => {
let (expr, export) = x.as_ref();
let (expr, export) = &**x;
// Guard against too many modules
#[cfg(not(feature = "unchecked"))]
@@ -995,7 +995,7 @@ impl Engine {
// Export statement
#[cfg(not(feature = "no_module"))]
Stmt::Export(x, ..) => {
let (Ident { name, pos, .. }, alias) = x.as_ref();
let (Ident { name, pos, .. }, alias) = &**x;
// Mark scope variables as public
if let Some((index, ..)) = scope.get_index(name) {
let alias = if alias.is_empty() { name } else { alias }.clone();