From c02d702081ee2b600ae5ba4904ea211dc445c15b Mon Sep 17 00:00:00 2001 From: Stephen Chung Date: Sun, 6 Jun 2021 12:17:04 +0800 Subject: [PATCH] Use StaticVec. --- src/ast.rs | 21 ++++++++++----------- src/fn_call.rs | 2 +- src/module/mod.rs | 4 ++-- 3 files changed, 13 insertions(+), 14 deletions(-) diff --git a/src/ast.rs b/src/ast.rs index a2d81e44..2adba823 100644 --- a/src/ast.rs +++ b/src/ast.rs @@ -90,7 +90,7 @@ impl fmt::Display for ScriptFnDef { self.params .iter() .map(|s| s.as_str()) - .collect::>() + .collect::>() .join(", ") ) } @@ -138,7 +138,11 @@ impl fmt::Display for ScriptFnMetadata<'_> { FnAccess::Private => "private ", }, self.name, - self.params.iter().cloned().collect::>().join(", ") + self.params + .iter() + .cloned() + .collect::>() + .join(", ") ) } } @@ -215,10 +219,9 @@ impl AST { statements: impl IntoIterator, functions: impl Into>, ) -> Self { - let statements: StaticVec<_> = statements.into_iter().collect(); Self { source: None, - body: StmtBlock::new(statements, Position::NONE), + body: StmtBlock::new(statements.into_iter().collect(), Position::NONE), functions: functions.into(), #[cfg(not(feature = "no_module"))] resolver: None, @@ -231,10 +234,9 @@ impl AST { functions: impl Into>, source: impl Into, ) -> Self { - let statements: StaticVec<_> = statements.into_iter().collect(); Self { source: Some(source.into()), - body: StmtBlock::new(statements, Position::NONE), + body: StmtBlock::new(statements.into_iter().collect(), Position::NONE), functions: functions.into(), #[cfg(not(feature = "no_module"))] resolver: None, @@ -866,8 +868,7 @@ pub struct StmtBlock(StaticVec, Position); impl StmtBlock { /// Create a new [`StmtBlock`]. - pub fn new(statements: impl Into>, pos: Position) -> Self { - let mut statements = statements.into(); + pub fn new(mut statements: StaticVec, pos: Position) -> Self { statements.shrink_to_fit(); Self(statements, pos) } @@ -1000,9 +1001,7 @@ impl From for StmtBlock { #[inline(always)] fn from(stmt: Stmt) -> Self { match stmt { - Stmt::Block(mut block, pos) => { - Self(block.iter_mut().map(|v| mem::take(v)).collect(), pos) - } + Stmt::Block(mut block, pos) => Self(block.iter_mut().map(mem::take).collect(), pos), Stmt::Noop(pos) => Self(Default::default(), pos), _ => { let pos = stmt.position(); diff --git a/src/fn_call.rs b/src/fn_call.rs index 27cc2116..d1f3d3bc 100644 --- a/src/fn_call.rs +++ b/src/fn_call.rs @@ -140,7 +140,7 @@ impl Engine { } else { self.map_type_name((*a).type_name()) }) - .collect::>() + .collect::>() .join(", ") ) } diff --git a/src/module/mod.rs b/src/module/mod.rs index c9f9966f..63052d6b 100644 --- a/src/module/mod.rs +++ b/src/module/mod.rs @@ -71,7 +71,7 @@ impl FuncInfo { let mut sig = format!("{}(", self.name); if !self.param_names.is_empty() { - let mut params: Vec = + let mut params: StaticVec = self.param_names.iter().map(|s| s.as_str().into()).collect(); let return_type = params.pop().unwrap_or_else(|| "()".into()); sig.push_str(¶ms.join(", ")); @@ -1649,7 +1649,7 @@ impl fmt::Debug for NamespaceRef { .path .iter() .map(|Ident { name, .. }| name.as_str()) - .collect::>() + .collect::>() .join("::"), ) }