Reduce usage of as_ref and as_mut.
This commit is contained in:
@@ -205,7 +205,7 @@ impl Engine {
|
||||
|
||||
let crate::ast::FnCallExpr {
|
||||
name, hashes, args, ..
|
||||
} = x.as_ref();
|
||||
} = &**x;
|
||||
|
||||
let offset = idx_values.len() - args.len();
|
||||
let call_args = &mut idx_values[offset..];
|
||||
@@ -266,7 +266,7 @@ impl Engine {
|
||||
#[cfg(feature = "debugging")]
|
||||
self.run_debugger(scope, global, lib, this_ptr, rhs, level)?;
|
||||
|
||||
let ((getter, hash_get), (setter, hash_set), name) = x.as_ref();
|
||||
let ((getter, hash_get), (setter, hash_set), name) = &**x;
|
||||
let (mut new_val, op_info) = new_val.expect("`Some`");
|
||||
|
||||
if op_info.is_op_assignment() {
|
||||
@@ -331,7 +331,7 @@ impl Engine {
|
||||
#[cfg(feature = "debugging")]
|
||||
self.run_debugger(scope, global, lib, this_ptr, rhs, level)?;
|
||||
|
||||
let ((getter, hash_get), _, name) = x.as_ref();
|
||||
let ((getter, hash_get), _, name) = &**x;
|
||||
let args = &mut [target.as_mut()];
|
||||
self.call_native_fn(
|
||||
global, caches, lib, getter, *hash_get, args, is_ref_mut, false, *pos,
|
||||
@@ -382,7 +382,7 @@ impl Engine {
|
||||
|
||||
let crate::ast::FnCallExpr {
|
||||
name, hashes, args, ..
|
||||
} = x.as_ref();
|
||||
} = &**x;
|
||||
|
||||
let offset = idx_values.len() - args.len();
|
||||
let call_args = &mut idx_values[offset..];
|
||||
@@ -425,7 +425,7 @@ impl Engine {
|
||||
#[cfg(feature = "debugging")]
|
||||
self.run_debugger(scope, global, lib, this_ptr, _node, level)?;
|
||||
|
||||
let ((getter, hash_get), (setter, hash_set), name) = p.as_ref();
|
||||
let ((getter, hash_get), (setter, hash_set), name) = &**p;
|
||||
let rhs_chain = rhs.into();
|
||||
let mut arg_values = [target.as_mut(), &mut Dynamic::UNIT.clone()];
|
||||
let args = &mut arg_values[..1];
|
||||
@@ -507,7 +507,7 @@ impl Engine {
|
||||
|
||||
let crate::ast::FnCallExpr {
|
||||
name, hashes, args, ..
|
||||
} = f.as_ref();
|
||||
} = &**f;
|
||||
let rhs_chain = rhs.into();
|
||||
|
||||
let offset = idx_values.len() - args.len();
|
||||
@@ -563,9 +563,9 @@ impl Engine {
|
||||
let chain_type = ChainType::from(expr);
|
||||
let (crate::ast::BinaryExpr { lhs, rhs }, options, op_pos) = match expr {
|
||||
#[cfg(not(feature = "no_index"))]
|
||||
Expr::Index(x, options, pos) => (x.as_ref(), *options, *pos),
|
||||
Expr::Index(x, options, pos) => (&**x, *options, *pos),
|
||||
#[cfg(not(feature = "no_object"))]
|
||||
Expr::Dot(x, options, pos) => (x.as_ref(), *options, *pos),
|
||||
Expr::Dot(x, options, pos) => (&**x, *options, *pos),
|
||||
expr => unreachable!("Expr::Index or Expr::Dot expected but gets {:?}", expr),
|
||||
};
|
||||
|
||||
@@ -666,7 +666,7 @@ impl Engine {
|
||||
Expr::MethodCall(x, ..)
|
||||
if _parent_chain_type == ChainType::Dotting && !x.is_qualified() =>
|
||||
{
|
||||
for arg_expr in x.args.as_ref() {
|
||||
for arg_expr in &x.args {
|
||||
idx_values.push(
|
||||
self.get_arg_value(scope, global, caches, lib, this_ptr, arg_expr, level)?
|
||||
.0
|
||||
@@ -686,7 +686,7 @@ impl Engine {
|
||||
Expr::Index(x, options, ..) | Expr::Dot(x, options, ..)
|
||||
if !parent_options.contains(ASTFlags::BREAK) =>
|
||||
{
|
||||
let crate::ast::BinaryExpr { lhs, rhs, .. } = x.as_ref();
|
||||
let crate::ast::BinaryExpr { lhs, rhs, .. } = &**x;
|
||||
|
||||
let mut _arg_values = FnArgsVec::new_const();
|
||||
|
||||
@@ -700,7 +700,7 @@ impl Engine {
|
||||
Expr::MethodCall(x, ..)
|
||||
if _parent_chain_type == ChainType::Dotting && !x.is_qualified() =>
|
||||
{
|
||||
for arg_expr in x.args.as_ref() {
|
||||
for arg_expr in &x.args {
|
||||
_arg_values.push(
|
||||
self.get_arg_value(
|
||||
scope, global, caches, lib, this_ptr, arg_expr, level,
|
||||
|
@@ -357,7 +357,7 @@ impl Debugger {
|
||||
ASTNode::Expr(Expr::FnCall(x, ..)) | ASTNode::Stmt(Stmt::FnCall(x, ..)) => {
|
||||
x.name == *name
|
||||
}
|
||||
ASTNode::Stmt(Stmt::Expr(e)) => match e.as_ref() {
|
||||
ASTNode::Stmt(Stmt::Expr(e)) => match &**e {
|
||||
Expr::FnCall(x, ..) => x.name == *name,
|
||||
_ => false,
|
||||
},
|
||||
@@ -367,7 +367,7 @@ impl Debugger {
|
||||
ASTNode::Expr(Expr::FnCall(x, ..)) | ASTNode::Stmt(Stmt::FnCall(x, ..)) => {
|
||||
x.args.len() == *args && x.name == *name
|
||||
}
|
||||
ASTNode::Stmt(Stmt::Expr(e)) => match e.as_ref() {
|
||||
ASTNode::Stmt(Stmt::Expr(e)) => match &**e {
|
||||
Expr::FnCall(x, ..) => x.args.len() == *args && x.name == *name,
|
||||
_ => false,
|
||||
},
|
||||
@@ -560,7 +560,7 @@ impl Engine {
|
||||
ASTNode::Expr(Expr::FnCall(..)) | ASTNode::Stmt(Stmt::FnCall(..)) => {
|
||||
level + 1
|
||||
}
|
||||
ASTNode::Stmt(Stmt::Expr(e)) if matches!(e.as_ref(), Expr::FnCall(..)) => {
|
||||
ASTNode::Stmt(Stmt::Expr(e)) if matches!(**e, Expr::FnCall(..)) => {
|
||||
level + 1
|
||||
}
|
||||
_ => level,
|
||||
|
@@ -60,7 +60,7 @@ impl Engine {
|
||||
Expr::Variable(_, Some(_), _) => {
|
||||
self.search_scope_only(scope, global, lib, this_ptr, expr, level)
|
||||
}
|
||||
Expr::Variable(v, None, _var_pos) => match v.as_ref() {
|
||||
Expr::Variable(v, None, _var_pos) => match &**v {
|
||||
// Normal variable access
|
||||
#[cfg(not(feature = "no_module"))]
|
||||
(_, ns, ..) if ns.is_empty() => {
|
||||
@@ -323,7 +323,7 @@ impl Engine {
|
||||
let mut op_info = OpAssignment::new_op_assignment(OP_CONCAT, Position::NONE);
|
||||
let root = ("", Position::NONE);
|
||||
|
||||
for expr in x.iter() {
|
||||
for expr in &**x {
|
||||
let item =
|
||||
match self.eval_expr(scope, global, caches, lib, this_ptr, expr, level) {
|
||||
Ok(r) => r,
|
||||
@@ -354,7 +354,7 @@ impl Engine {
|
||||
#[cfg(not(feature = "unchecked"))]
|
||||
let mut sizes = (0, 0, 0);
|
||||
|
||||
for item_expr in x.iter() {
|
||||
for item_expr in &**x {
|
||||
let value = match self
|
||||
.eval_expr(scope, global, caches, lib, this_ptr, item_expr, level)
|
||||
{
|
||||
@@ -392,7 +392,7 @@ impl Engine {
|
||||
#[cfg(not(feature = "unchecked"))]
|
||||
let mut sizes = (0, 0, 0);
|
||||
|
||||
for (key, value_expr) in x.0.iter() {
|
||||
for (key, value_expr) in &x.0 {
|
||||
let value = match self
|
||||
.eval_expr(scope, global, caches, lib, this_ptr, value_expr, level)
|
||||
{
|
||||
|
@@ -197,7 +197,7 @@ impl GlobalRuntimeState<'_> {
|
||||
.iter()
|
||||
.rev()
|
||||
.zip(self.modules.iter().rev())
|
||||
.map(|(name, module)| (name.as_str(), module.as_ref()))
|
||||
.map(|(name, module)| (name.as_str(), &**module))
|
||||
}
|
||||
/// Get an iterator to the stack of globally-imported [modules][crate::Module] in reverse order.
|
||||
///
|
||||
@@ -327,6 +327,21 @@ impl IntoIterator for GlobalRuntimeState<'_> {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "no_module"))]
|
||||
impl<'a> IntoIterator for &'a GlobalRuntimeState<'_> {
|
||||
type Item = (&'a Identifier, &'a crate::Shared<crate::Module>);
|
||||
type IntoIter = std::iter::Zip<
|
||||
std::iter::Rev<std::slice::Iter<'a, Identifier>>,
|
||||
std::iter::Rev<std::slice::Iter<'a, crate::Shared<crate::Module>>>,
|
||||
>;
|
||||
|
||||
#[inline]
|
||||
fn into_iter(self) -> Self::IntoIter {
|
||||
let x = self.keys.iter().rev().zip(self.modules.iter().rev());
|
||||
x
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "no_module"))]
|
||||
impl<K: Into<Identifier>, M: Into<crate::Shared<crate::Module>>> Extend<(K, M)>
|
||||
for GlobalRuntimeState<'_>
|
||||
|
@@ -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();
|
||||
|
Reference in New Issue
Block a user