Reduce usage of as_ref and as_mut.
This commit is contained in:
@@ -259,7 +259,7 @@ impl Engine {
|
||||
}
|
||||
|
||||
let mut this_ptr = this_ptr;
|
||||
let mut args: StaticVec<_> = arg_values.as_mut().iter_mut().collect();
|
||||
let mut args: StaticVec<_> = arg_values.iter_mut().collect();
|
||||
|
||||
// Check for data race.
|
||||
#[cfg(not(feature = "no_closure"))]
|
||||
|
@@ -219,7 +219,7 @@ impl Engine {
|
||||
) -> ParseResult<AST> {
|
||||
let (stream, tokenizer_control) = self.lex_raw(
|
||||
scripts.as_ref(),
|
||||
self.token_mapper.as_ref().map(Box::as_ref),
|
||||
self.token_mapper.as_ref().map(<_>::as_ref),
|
||||
);
|
||||
let mut state = ParseState::new(self, scope, tokenizer_control);
|
||||
self.parse(&mut stream.peekable(), &mut state, optimization_level)
|
||||
@@ -288,7 +288,7 @@ impl Engine {
|
||||
) -> ParseResult<AST> {
|
||||
let scripts = [script];
|
||||
let (stream, tokenizer_control) =
|
||||
self.lex_raw(&scripts, self.token_mapper.as_ref().map(Box::as_ref));
|
||||
self.lex_raw(&scripts, self.token_mapper.as_ref().map(<_>::as_ref));
|
||||
|
||||
let mut peekable = stream.peekable();
|
||||
let mut state = ParseState::new(self, scope, tokenizer_control);
|
||||
|
@@ -115,7 +115,7 @@ impl Engine {
|
||||
) -> RhaiResultOf<T> {
|
||||
let scripts = [script];
|
||||
let (stream, tokenizer_control) =
|
||||
self.lex_raw(&scripts, self.token_mapper.as_ref().map(Box::as_ref));
|
||||
self.lex_raw(&scripts, self.token_mapper.as_ref().map(<_>::as_ref));
|
||||
let mut state = ParseState::new(self, scope, tokenizer_control);
|
||||
|
||||
// No need to optimize a lone expression
|
||||
|
@@ -158,7 +158,9 @@ impl Engine {
|
||||
return Err("precedence cannot be zero".into());
|
||||
}
|
||||
|
||||
match Token::lookup_from_syntax(keyword.as_ref()) {
|
||||
let keyword = keyword.as_ref();
|
||||
|
||||
match Token::lookup_from_syntax(keyword) {
|
||||
// Standard identifiers, reserved keywords and custom keywords are OK
|
||||
None | Some(Token::Reserved(..)) | Some(Token::Custom(..)) => (),
|
||||
// Active standard keywords cannot be made custom
|
||||
@@ -167,7 +169,7 @@ impl Engine {
|
||||
if self.disabled_symbols.is_empty()
|
||||
|| !self.disabled_symbols.contains(&*token.syntax())
|
||||
{
|
||||
return Err(format!("'{}' is a reserved keyword", keyword.as_ref()));
|
||||
return Err(format!("'{}' is a reserved keyword", keyword));
|
||||
}
|
||||
}
|
||||
// Active standard symbols cannot be made custom
|
||||
@@ -175,7 +177,7 @@ impl Engine {
|
||||
if self.disabled_symbols.is_empty()
|
||||
|| !self.disabled_symbols.contains(&*token.syntax())
|
||||
{
|
||||
return Err(format!("'{}' is a reserved operator", keyword.as_ref()));
|
||||
return Err(format!("'{}' is a reserved operator", keyword));
|
||||
}
|
||||
}
|
||||
// Active standard symbols cannot be made custom
|
||||
@@ -183,15 +185,14 @@ impl Engine {
|
||||
if self.disabled_symbols.is_empty()
|
||||
|| !self.disabled_symbols.contains(&*token.syntax()) =>
|
||||
{
|
||||
return Err(format!("'{}' is a reserved symbol", keyword.as_ref()))
|
||||
return Err(format!("'{}' is a reserved symbol", keyword))
|
||||
}
|
||||
// Disabled symbols are OK
|
||||
Some(_) => (),
|
||||
}
|
||||
|
||||
// Add to custom keywords
|
||||
self.custom_keywords
|
||||
.insert(keyword.as_ref().into(), precedence);
|
||||
self.custom_keywords.insert(keyword.into(), precedence);
|
||||
|
||||
Ok(self)
|
||||
}
|
||||
|
@@ -987,8 +987,9 @@ impl Engine {
|
||||
module: Shared<Module>,
|
||||
) {
|
||||
let separator = crate::tokenizer::Token::DoubleColon.syntax();
|
||||
let separator = separator.as_ref();
|
||||
|
||||
if !name.contains(separator.as_ref()) {
|
||||
if !name.contains(separator) {
|
||||
if !module.is_indexed() {
|
||||
// Index the module (making a clone copy if necessary) if it is not indexed
|
||||
let mut module = crate::func::shared_take_or_clone(module);
|
||||
@@ -998,7 +999,7 @@ impl Engine {
|
||||
root.insert(name.into(), module);
|
||||
}
|
||||
} else {
|
||||
let mut iter = name.splitn(2, separator.as_ref());
|
||||
let mut iter = name.splitn(2, separator);
|
||||
let sub_module = iter.next().expect("contains separator").trim();
|
||||
let remainder = iter.next().expect("contains separator").trim();
|
||||
|
||||
|
@@ -23,7 +23,7 @@ impl Engine {
|
||||
pub fn run_with_scope(&self, scope: &mut Scope, script: &str) -> RhaiResultOf<()> {
|
||||
let scripts = [script];
|
||||
let (stream, tokenizer_control) =
|
||||
self.lex_raw(&scripts, self.token_mapper.as_ref().map(Box::as_ref));
|
||||
self.lex_raw(&scripts, self.token_mapper.as_ref().map(<_>::as_ref));
|
||||
let mut state = ParseState::new(self, scope, tokenizer_control);
|
||||
|
||||
let ast = self.parse(&mut stream.peekable(), &mut state, self.optimization_level)?;
|
||||
|
Reference in New Issue
Block a user