Reduce usage of as_ref and as_mut.
This commit is contained in:
@@ -54,7 +54,7 @@ impl fmt::Debug for AST {
|
||||
|
||||
#[cfg(not(feature = "no_function"))]
|
||||
if !self.lib.is_empty() {
|
||||
for (.., ref fn_def) in self.lib.iter_script_fn() {
|
||||
for (.., fn_def) in self.lib.iter_script_fn() {
|
||||
let sig = fn_def.to_string();
|
||||
fp.field(&sig, &fn_def.body.as_slice());
|
||||
}
|
||||
@@ -523,19 +523,19 @@ impl AST {
|
||||
|
||||
#[cfg(not(feature = "no_module"))]
|
||||
match (
|
||||
self.resolver().map_or(0, |r| r.len()),
|
||||
other.resolver().map_or(0, |r| r.len()),
|
||||
self.resolver().map_or(true, |r| r.is_empty()),
|
||||
other.resolver().map_or(true, |r| r.is_empty()),
|
||||
) {
|
||||
(0, 0) => (),
|
||||
(_, 0) => {
|
||||
(true, true) => (),
|
||||
(false, true) => {
|
||||
_ast.set_resolver(self.resolver().unwrap().clone());
|
||||
}
|
||||
(0, _) => {
|
||||
(true, false) => {
|
||||
_ast.set_resolver(other.resolver().unwrap().clone());
|
||||
}
|
||||
(_, _) => {
|
||||
let mut resolver = (**self.resolver().unwrap()).clone();
|
||||
let other_resolver = (**other.resolver().unwrap()).clone();
|
||||
(false, false) => {
|
||||
let mut resolver = self.resolver().unwrap().as_ref().clone();
|
||||
let other_resolver = other.resolver().unwrap().as_ref().clone();
|
||||
for (k, v) in other_resolver {
|
||||
resolver.insert(k, crate::func::shared_take_or_clone(v));
|
||||
}
|
||||
@@ -611,23 +611,16 @@ impl AST {
|
||||
other: Self,
|
||||
_filter: impl Fn(FnNamespace, FnAccess, bool, &str, usize) -> bool,
|
||||
) -> &mut Self {
|
||||
self.body.extend(other.body.into_iter());
|
||||
|
||||
#[cfg(not(feature = "no_function"))]
|
||||
if !other.lib.is_empty() {
|
||||
crate::func::shared_make_mut(&mut self.lib).merge_filtered(&other.lib, &_filter);
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "no_module"))]
|
||||
match (
|
||||
self.resolver.as_ref().map_or(0, |r| r.len()),
|
||||
other.resolver.as_ref().map_or(0, |r| r.len()),
|
||||
self.resolver().map_or(true, |r| r.is_empty()),
|
||||
other.resolver().map_or(true, |r| r.is_empty()),
|
||||
) {
|
||||
(_, 0) => (),
|
||||
(0, _) => {
|
||||
(_, true) => (),
|
||||
(true, false) => {
|
||||
self.set_resolver(other.resolver.unwrap());
|
||||
}
|
||||
(_, _) => {
|
||||
(false, false) => {
|
||||
let resolver = crate::func::shared_make_mut(self.resolver.as_mut().unwrap());
|
||||
let other_resolver = crate::func::shared_take_or_clone(other.resolver.unwrap());
|
||||
for (k, v) in other_resolver {
|
||||
@@ -636,6 +629,13 @@ impl AST {
|
||||
}
|
||||
}
|
||||
|
||||
self.body.extend(other.body.into_iter());
|
||||
|
||||
#[cfg(not(feature = "no_function"))]
|
||||
if !other.lib.is_empty() {
|
||||
crate::func::shared_make_mut(&mut self.lib).merge_filtered(&other.lib, &_filter);
|
||||
}
|
||||
|
||||
self
|
||||
}
|
||||
/// Filter out the functions, retaining only some based on a filter predicate.
|
||||
@@ -792,7 +792,7 @@ impl AST {
|
||||
if options.contains(ASTFlags::CONSTANT) && include_constants
|
||||
|| !options.contains(ASTFlags::CONSTANT) && include_variables =>
|
||||
{
|
||||
let (name, expr, ..) = x.as_ref();
|
||||
let (name, expr, ..) = &**x;
|
||||
if let Some(value) = expr.get_literal_value() {
|
||||
Some((name.as_str(), options.contains(ASTFlags::CONSTANT), value))
|
||||
} else {
|
||||
|
@@ -886,14 +886,14 @@ impl Expr {
|
||||
|
||||
match self {
|
||||
Self::Stmt(x) => {
|
||||
for s in x.iter() {
|
||||
for s in &**x {
|
||||
if !s.walk(path, on_node) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
Self::InterpolatedString(x, ..) | Self::Array(x, ..) => {
|
||||
for e in x.as_ref() {
|
||||
for e in &**x {
|
||||
if !e.walk(path, on_node) {
|
||||
return false;
|
||||
}
|
||||
|
@@ -123,7 +123,7 @@ impl<'a> From<&'a ScriptFnDef> for ScriptFnMetadata<'a> {
|
||||
params: value.params.iter().map(|s| s.as_str()).collect(),
|
||||
access: value.access,
|
||||
#[cfg(feature = "metadata")]
|
||||
comments: value.comments.iter().map(Box::as_ref).collect(),
|
||||
comments: value.comments.iter().map(<_>::as_ref).collect(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -175,6 +175,7 @@ impl fmt::Debug for RangeCase {
|
||||
|
||||
impl From<Range<INT>> for RangeCase {
|
||||
#[inline(always)]
|
||||
#[must_use]
|
||||
fn from(value: Range<INT>) -> Self {
|
||||
Self::ExclusiveInt(value, 0)
|
||||
}
|
||||
@@ -182,6 +183,7 @@ impl From<Range<INT>> for RangeCase {
|
||||
|
||||
impl From<RangeInclusive<INT>> for RangeCase {
|
||||
#[inline(always)]
|
||||
#[must_use]
|
||||
fn from(value: RangeInclusive<INT>) -> Self {
|
||||
Self::InclusiveInt(value, 0)
|
||||
}
|
||||
@@ -467,6 +469,17 @@ impl IntoIterator for StmtBlock {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> IntoIterator for &'a StmtBlock {
|
||||
type Item = &'a Stmt;
|
||||
type IntoIter = std::slice::Iter<'a, Stmt>;
|
||||
|
||||
#[inline(always)]
|
||||
fn into_iter(self) -> Self::IntoIter {
|
||||
let x = self.block.iter();
|
||||
x
|
||||
}
|
||||
}
|
||||
|
||||
impl Extend<Stmt> for StmtBlock {
|
||||
#[inline(always)]
|
||||
fn extend<T: IntoIterator<Item = Stmt>>(&mut self, iter: T) {
|
||||
@@ -730,7 +743,7 @@ impl Stmt {
|
||||
x.0.is_pure() && x.1.iter().all(Stmt::is_pure) && x.2.iter().all(Stmt::is_pure)
|
||||
}
|
||||
Self::Switch(x, ..) => {
|
||||
let (expr, sw) = x.as_ref();
|
||||
let (expr, sw) = &**x;
|
||||
expr.is_pure()
|
||||
&& sw.cases.values().all(|&c| {
|
||||
let block = &sw.blocks[c];
|
||||
@@ -814,7 +827,7 @@ impl Stmt {
|
||||
match self {
|
||||
Self::Var(x, ..) => x.1.is_pure(),
|
||||
|
||||
Self::Expr(e) => match e.as_ref() {
|
||||
Self::Expr(e) => match &**e {
|
||||
Expr::Stmt(s) => s.iter().all(Stmt::is_internally_pure),
|
||||
_ => self.is_pure(),
|
||||
},
|
||||
@@ -864,48 +877,48 @@ impl Stmt {
|
||||
if !x.0.walk(path, on_node) {
|
||||
return false;
|
||||
}
|
||||
for s in x.1.iter() {
|
||||
for s in &x.1 {
|
||||
if !s.walk(path, on_node) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
for s in x.2.iter() {
|
||||
for s in &x.2 {
|
||||
if !s.walk(path, on_node) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
Self::Switch(x, ..) => {
|
||||
let (expr, sw) = x.as_ref();
|
||||
let (expr, sw) = &**x;
|
||||
|
||||
if !expr.walk(path, on_node) {
|
||||
return false;
|
||||
}
|
||||
for (.., &b) in sw.cases.iter() {
|
||||
for (.., &b) in &sw.cases {
|
||||
let block = &sw.blocks[b];
|
||||
|
||||
if !block.condition.walk(path, on_node) {
|
||||
return false;
|
||||
}
|
||||
for s in block.statements.iter() {
|
||||
for s in &block.statements {
|
||||
if !s.walk(path, on_node) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
for r in sw.ranges.iter() {
|
||||
for r in &sw.ranges {
|
||||
let block = &sw.blocks[r.index()];
|
||||
|
||||
if !block.condition.walk(path, on_node) {
|
||||
return false;
|
||||
}
|
||||
for s in block.statements.iter() {
|
||||
for s in &block.statements {
|
||||
if !s.walk(path, on_node) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
for s in sw.blocks[sw.def_case].statements.iter() {
|
||||
for s in &sw.blocks[sw.def_case].statements {
|
||||
if !s.walk(path, on_node) {
|
||||
return false;
|
||||
}
|
||||
@@ -925,7 +938,7 @@ impl Stmt {
|
||||
if !x.2.walk(path, on_node) {
|
||||
return false;
|
||||
}
|
||||
for s in x.3.iter() {
|
||||
for s in &x.3 {
|
||||
if !s.walk(path, on_node) {
|
||||
return false;
|
||||
}
|
||||
@@ -954,12 +967,12 @@ impl Stmt {
|
||||
}
|
||||
}
|
||||
Self::TryCatch(x, ..) => {
|
||||
for s in x.try_block.iter() {
|
||||
for s in &x.try_block {
|
||||
if !s.walk(path, on_node) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
for s in x.catch_block.iter() {
|
||||
for s in &x.catch_block {
|
||||
if !s.walk(path, on_node) {
|
||||
return false;
|
||||
}
|
||||
|
Reference in New Issue
Block a user