From e0673a2f1ab16db0894259c946679afdee4ece03 Mon Sep 17 00:00:00 2001 From: Stephen Chung Date: Sat, 10 Jul 2021 11:06:13 +0800 Subject: [PATCH] Change some #[inline(always)] to [#inline]. --- src/ast.rs | 27 +++++++++++---------------- src/dynamic.rs | 20 +++++++++----------- src/engine.rs | 33 ++++++++++++++++++--------------- src/engine_api.rs | 35 ++++++++++++++++------------------- src/error_parsing.rs | 2 -- src/fn_builtin.rs | 4 +--- src/fn_call.rs | 10 +++------- src/fn_hash.rs | 2 +- src/fn_native.rs | 26 ++++++++++++-------------- src/fn_ptr.rs | 5 ++--- src/fn_register.rs | 2 +- src/immutable_string.rs | 2 +- src/module/mod.rs | 25 +++++++++++++------------ src/module/resolvers/file.rs | 5 ++--- src/packages/string_basic.rs | 2 +- src/parse.rs | 8 ++++---- src/scope.rs | 23 +++++++---------------- src/token.rs | 16 +++++++--------- 18 files changed, 109 insertions(+), 138 deletions(-) diff --git a/src/ast.rs b/src/ast.rs index eb992f6a..01b41fe3 100644 --- a/src/ast.rs +++ b/src/ast.rs @@ -78,7 +78,6 @@ pub struct ScriptFnDef { } impl fmt::Display for ScriptFnDef { - #[inline(always)] fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!( f, @@ -129,7 +128,6 @@ pub struct ScriptFnMetadata<'a> { #[cfg(not(feature = "no_function"))] impl fmt::Display for ScriptFnMetadata<'_> { - #[inline(always)] fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!( f, @@ -150,7 +148,7 @@ impl fmt::Display for ScriptFnMetadata<'_> { #[cfg(not(feature = "no_function"))] impl<'a> Into> for &'a ScriptFnDef { - #[inline(always)] + #[inline] fn into(self) -> ScriptFnMetadata<'a> { ScriptFnMetadata { #[cfg(not(feature = "no_function"))] @@ -215,7 +213,7 @@ impl Default for AST { impl AST { /// Create a new [`AST`]. - #[inline(always)] + #[inline] #[must_use] pub fn new( statements: impl IntoIterator, @@ -258,7 +256,7 @@ impl AST { self.source.as_ref() } /// Set the source. - #[inline(always)] + #[inline] pub fn set_source(&mut self, source: impl Into) -> &mut Self { let source = source.into(); Shared::get_mut(&mut self.functions) @@ -386,7 +384,7 @@ impl AST { /// /// This operation is cheap because functions are shared. #[cfg(not(feature = "no_function"))] - #[inline(always)] + #[inline] #[must_use] pub fn clone_functions_only_filtered( &self, @@ -657,7 +655,7 @@ impl AST { /// # Ok(()) /// # } /// ``` - #[inline(always)] + #[inline] pub fn combine_filtered( &mut self, other: Self, @@ -696,7 +694,7 @@ impl AST { /// # } /// ``` #[cfg(not(feature = "no_function"))] - #[inline(always)] + #[inline] pub fn retain_functions( &mut self, filter: impl Fn(FnNamespace, FnAccess, &str, usize) -> bool, @@ -748,7 +746,7 @@ impl AST { /// Return `false` from the callback to terminate the walk. #[cfg(not(feature = "internals"))] #[cfg(not(feature = "no_module"))] - #[inline(always)] + #[inline] pub(crate) fn walk(&self, on_node: &mut impl FnMut(&[ASTNode]) -> bool) -> bool { let path = &mut Default::default(); @@ -770,7 +768,7 @@ impl AST { /// Return `false` from the callback to terminate the walk. /// Exported under the `internals` feature only. #[cfg(feature = "internals")] - #[inline(always)] + #[inline] pub fn walk(&self, on_node: &mut impl FnMut(&[ASTNode]) -> bool) -> bool { let path = &mut Default::default(); @@ -835,7 +833,6 @@ pub struct Ident { } impl fmt::Debug for Ident { - #[inline(always)] fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "{:?}", self.name)?; self.pos.debug_print(f) @@ -939,7 +936,6 @@ impl DerefMut for StmtBlock { } impl fmt::Debug for StmtBlock { - #[inline(always)] fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.write_str("Block")?; fmt::Debug::fmt(&self.0, f)?; @@ -1027,7 +1023,7 @@ impl Default for Stmt { } impl From for StmtBlock { - #[inline(always)] + #[inline] fn from(stmt: Stmt) -> Self { match stmt { Stmt::Block(mut block, pos) => Self(block.iter_mut().map(mem::take).collect(), pos), @@ -1226,7 +1222,7 @@ impl Stmt { /// /// Only variable declarations (i.e. `let` and `const`) and `import`/`export` statements /// are internally pure. - #[inline(always)] + #[inline] #[must_use] pub fn is_internally_pure(&self) -> bool { match self { @@ -1245,7 +1241,7 @@ impl Stmt { /// Currently this is only true for `return`, `throw`, `break` and `continue`. /// /// All statements following this statement will essentially be dead code. - #[inline(always)] + #[inline] #[must_use] pub const fn is_control_flow_break(&self) -> bool { match self { @@ -1634,7 +1630,6 @@ impl fmt::Debug for FloatWrapper { #[cfg(not(feature = "no_float"))] impl> fmt::Display for FloatWrapper { - #[inline(always)] fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { let abs = self.0.abs(); if abs > Self::MAX_NATURAL_FLOAT_FOR_DISPLAY.into() diff --git a/src/dynamic.rs b/src/dynamic.rs index d4c0732e..17f3db2d 100644 --- a/src/dynamic.rs +++ b/src/dynamic.rs @@ -405,13 +405,11 @@ impl Dynamic { #[inline(always)] #[must_use] pub fn is(&self) -> bool { - let mut target_type_id = TypeId::of::(); - - if target_type_id == TypeId::of::() { - target_type_id = TypeId::of::(); + if TypeId::of::() == TypeId::of::() { + self.type_id() == TypeId::of::() + } else { + self.type_id() == TypeId::of::() } - - self.type_id() == target_type_id } /// Get the [`TypeId`] of the value held by this [`Dynamic`]. /// @@ -577,7 +575,7 @@ impl Hash for Dynamic { } /// Map the name of a standard type into a friendly form. -#[inline(always)] +#[inline] #[must_use] pub(crate) fn map_std_type_name(name: &str) -> &str { if name == type_name::() { @@ -1321,7 +1319,7 @@ impl Dynamic { /// /// assert_eq!(x.cast::(), 42); /// ``` - #[inline(always)] + #[inline] #[must_use] pub fn cast(self) -> T { #[cfg(not(feature = "no_closure"))] @@ -1481,7 +1479,7 @@ impl Dynamic { /// /// Under the `sync` feature, this call may deadlock, or [panic](https://doc.rust-lang.org/std/sync/struct.RwLock.html#panics-1). /// Otherwise, this call panics if the data is currently borrowed for write. - #[inline(always)] + #[inline] #[must_use] pub fn read_lock(&self) -> Option> { match self.0 { @@ -1515,7 +1513,7 @@ impl Dynamic { /// /// Under the `sync` feature, this call may deadlock, or [panic](https://doc.rust-lang.org/std/sync/struct.RwLock.html#panics-1). /// Otherwise, this call panics if the data is currently borrowed for write. - #[inline(always)] + #[inline] #[must_use] pub fn write_lock(&mut self) -> Option> { match self.0 { @@ -1836,7 +1834,7 @@ impl Dynamic { } /// Convert the [`Dynamic`] into an [`ImmutableString`] and return it. /// Returns the name of the actual type if the cast fails. - #[inline(always)] + #[inline] #[must_use] pub fn as_immutable_string(self) -> Result { match self.0 { diff --git a/src/engine.rs b/src/engine.rs index 91b20d8b..c34d8c2f 100644 --- a/src/engine.rs +++ b/src/engine.rs @@ -67,7 +67,10 @@ impl Imports { #[inline(always)] #[must_use] pub fn new() -> Self { - Default::default() + Self { + keys: StaticVec::new(), + modules: StaticVec::new(), + } } /// Get the length of this stack of imported [modules][Module]. #[inline(always)] @@ -376,7 +379,7 @@ pub enum Target<'a> { impl<'a> Target<'a> { /// Is the `Target` a reference pointing to other data? #[allow(dead_code)] - #[inline(always)] + #[inline] #[must_use] pub const fn is_ref(&self) -> bool { match self { @@ -391,7 +394,7 @@ impl<'a> Target<'a> { } } /// Is the `Target` a temp value? - #[inline(always)] + #[inline] #[must_use] pub const fn is_temp_value(&self) -> bool { match self { @@ -407,7 +410,7 @@ impl<'a> Target<'a> { } /// Is the `Target` a shared value? #[cfg(not(feature = "no_closure"))] - #[inline(always)] + #[inline] #[must_use] pub fn is_shared(&self) -> bool { match self { @@ -423,7 +426,7 @@ impl<'a> Target<'a> { } /// Is the `Target` a specific type? #[allow(dead_code)] - #[inline(always)] + #[inline] #[must_use] pub fn is(&self) -> bool { match self { @@ -438,7 +441,7 @@ impl<'a> Target<'a> { } } /// Get the value of the `Target` as a `Dynamic`, cloning a referenced value if necessary. - #[inline(always)] + #[inline] #[must_use] pub fn take_or_clone(self) -> Dynamic { match self { @@ -469,7 +472,7 @@ impl<'a> Target<'a> { } /// Propagate a changed value back to the original source. /// This has no effect except for string indexing. - #[inline(always)] + #[inline] #[must_use] pub fn propagate_changed_value(&mut self) -> Result<(), Box> { match self { @@ -534,7 +537,7 @@ impl<'a> Target<'a> { } impl<'a> From<&'a mut Dynamic> for Target<'a> { - #[inline(always)] + #[inline] fn from(value: &'a mut Dynamic) -> Self { #[cfg(not(feature = "no_closure"))] if value.is_shared() { @@ -555,7 +558,7 @@ impl<'a> From<&'a mut Dynamic> for Target<'a> { impl Deref for Target<'_> { type Target = Dynamic; - #[inline(always)] + #[inline] fn deref(&self) -> &Dynamic { match self { Self::RefMut(r) => *r, @@ -578,7 +581,7 @@ impl AsRef for Target<'_> { } impl DerefMut for Target<'_> { - #[inline(always)] + #[inline] fn deref_mut(&mut self) -> &mut Dynamic { match self { Self::RefMut(r) => *r, @@ -947,7 +950,7 @@ impl Default for Engine { /// Make getter function #[cfg(not(feature = "no_object"))] -#[inline(always)] +#[inline] #[must_use] pub fn make_getter(id: &str) -> String { format!("{}{}", FN_GET, id) @@ -955,7 +958,7 @@ pub fn make_getter(id: &str) -> String { /// Make setter function #[cfg(not(feature = "no_object"))] -#[inline(always)] +#[inline] #[must_use] pub fn make_setter(id: &str) -> String { format!("{}{}", FN_SET, id) @@ -970,7 +973,7 @@ pub fn is_anonymous_fn(fn_name: &str) -> bool { } /// Print to `stdout` -#[inline(always)] +#[inline] #[allow(unused_variables)] fn print_to_stdout(s: &str) { #[cfg(not(feature = "no_std"))] @@ -979,7 +982,7 @@ fn print_to_stdout(s: &str) { } /// Debug to `stdout` -#[inline(always)] +#[inline] #[allow(unused_variables)] fn debug_to_stdout(s: &str, source: Option<&str>, pos: Position) { #[cfg(not(feature = "no_std"))] @@ -1021,7 +1024,7 @@ impl Engine { /// Create a new [`Engine`] with minimal built-in functions. /// /// Use [`register_global_module`][Engine::register_global_module] to add packages of functions. - #[inline(always)] + #[inline] #[must_use] pub fn new_raw() -> Self { let mut engine = Self { diff --git a/src/engine_api.rs b/src/engine_api.rs index a7a28177..1d977b23 100644 --- a/src/engine_api.rs +++ b/src/engine_api.rs @@ -329,8 +329,7 @@ impl Engine { name: &str, get_fn: impl Fn(&mut T) -> V + SendSync + 'static, ) -> &mut Self { - use crate::engine::make_getter; - self.register_fn(&make_getter(name), get_fn) + self.register_fn(&crate::engine::make_getter(name), get_fn) } /// Register a getter function for a member of a registered type with the [`Engine`]. /// @@ -378,8 +377,7 @@ impl Engine { name: &str, get_fn: impl Fn(&mut T) -> Result> + SendSync + 'static, ) -> &mut Self { - use crate::engine::make_getter; - self.register_result_fn(&make_getter(name), get_fn) + self.register_result_fn(&crate::engine::make_getter(name), get_fn) } /// Register a setter function for a member of a registered type with the [`Engine`]. /// @@ -426,8 +424,7 @@ impl Engine { name: &str, set_fn: impl Fn(&mut T, V) + SendSync + 'static, ) -> &mut Self { - use crate::engine::make_setter; - self.register_fn(&make_setter(name), set_fn) + self.register_fn(&crate::engine::make_setter(name), set_fn) } /// Register a setter function for a member of a registered type with the [`Engine`]. /// @@ -477,8 +474,7 @@ impl Engine { name: &str, set_fn: impl Fn(&mut T, V) -> Result<(), Box> + SendSync + 'static, ) -> &mut Self { - use crate::engine::make_setter; - self.register_result_fn(&make_setter(name), set_fn) + self.register_result_fn(&crate::engine::make_setter(name), set_fn) } /// Short-hand for registering both getter and setter functions /// of a registered type with the [`Engine`]. @@ -1189,7 +1185,7 @@ impl Engine { self.compile_with_scope_and_optimization_level(scope, scripts, self.optimization_level) } /// Join a list of strings and compile into an [`AST`] using own scope at a specific optimization level. - #[inline(always)] + #[inline] #[must_use] pub(crate) fn compile_with_scope_and_optimization_level( &self, @@ -1476,7 +1472,7 @@ impl Engine { /// # Ok(()) /// # } /// ``` - #[inline(always)] + #[inline] #[must_use] pub fn compile_expression_with_scope( &self, @@ -1644,7 +1640,7 @@ impl Engine { /// # Ok(()) /// # } /// ``` - #[inline(always)] + #[inline] #[must_use] pub fn eval_expression_with_scope( &self, @@ -1717,7 +1713,7 @@ impl Engine { /// # Ok(()) /// # } /// ``` - #[inline(always)] + #[inline] #[must_use] pub fn eval_ast_with_scope( &self, @@ -1740,7 +1736,7 @@ impl Engine { }); } /// Evaluate an [`AST`] with own scope. - #[inline(always)] + #[inline] #[must_use] pub(crate) fn eval_ast_with_scope_raw<'a>( &self, @@ -1797,7 +1793,7 @@ impl Engine { } /// Evaluate a string with own scope, but throw away the result and only return error (if any). /// Useful for when you don't need the result, but still need to keep track of possible errors. - #[inline(always)] + #[inline] pub fn consume_with_scope( &self, scope: &mut Scope, @@ -1824,7 +1820,7 @@ impl Engine { } /// Evaluate an [`AST`] with own scope, but throw away the result and only return error (if any). /// Useful for when you don't need the result, but still need to keep track of possible errors. - #[inline(always)] + #[inline] pub fn consume_ast_with_scope( &self, scope: &mut Scope, @@ -1889,7 +1885,7 @@ impl Engine { /// # } /// ``` #[cfg(not(feature = "no_function"))] - #[inline(always)] + #[inline] #[must_use] pub fn call_fn( &self, @@ -1970,7 +1966,7 @@ impl Engine { /// # } /// ``` #[cfg(not(feature = "no_function"))] - #[inline(always)] + #[inline] #[must_use] pub fn call_fn_dynamic( &self, @@ -1995,7 +1991,7 @@ impl Engine { /// Do not use the arguments after this call. If they are needed afterwards, /// clone them _before_ calling this function. #[cfg(not(feature = "no_function"))] - #[inline(always)] + #[inline] #[must_use] pub(crate) fn call_fn_dynamic_raw( &self, @@ -2052,7 +2048,7 @@ impl Engine { /// (i.e. with [`Scope::push_constant`]). /// Then, the [`AST`] is cloned and the copy re-optimized before running. #[cfg(not(feature = "no_optimize"))] - #[inline(always)] + #[inline] #[must_use] pub fn optimize_ast( &self, @@ -2087,6 +2083,7 @@ impl Engine { /// 2) Functions in registered sub-modules /// 3) Functions in packages (optional) #[cfg(feature = "metadata")] + #[inline] #[must_use] pub fn gen_fn_signatures(&self, include_packages: bool) -> Vec { let mut signatures: Vec<_> = Default::default(); diff --git a/src/error_parsing.rs b/src/error_parsing.rs index d89ca226..c65b9b07 100644 --- a/src/error_parsing.rs +++ b/src/error_parsing.rs @@ -39,7 +39,6 @@ pub enum LexError { impl Error for LexError {} impl fmt::Display for LexError { - #[inline(always)] fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { Self::UnexpectedInput(s) => write!(f, "Unexpected '{}'", s), @@ -283,7 +282,6 @@ pub struct ParseError(pub Box, pub Position); impl Error for ParseError {} impl fmt::Display for ParseError { - #[inline(always)] fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fmt::Display::fmt(&self.0, f)?; diff --git a/src/fn_builtin.rs b/src/fn_builtin.rs index 3d4346bf..2230804a 100644 --- a/src/fn_builtin.rs +++ b/src/fn_builtin.rs @@ -18,7 +18,7 @@ use rust_decimal::Decimal; const BUILTIN: &str = "never fails because this is built-in code and the type is already checked"; /// Is the type a numeric type? -#[inline(always)] +#[inline] #[must_use] fn is_numeric(type_id: TypeId) -> bool { let result = type_id == TypeId::of::() @@ -206,7 +206,6 @@ pub fn get_builtin_binary_op_fn( // char op string if types_pair == (TypeId::of::(), TypeId::of::()) { - #[inline(always)] fn get_s1s2(args: &FnCallArgs) -> ([char; 2], [char; 2]) { let x = args[0].as_char().expect(BUILTIN); let y = &*args[1].read_lock::().expect(BUILTIN); @@ -233,7 +232,6 @@ pub fn get_builtin_binary_op_fn( } // string op char if types_pair == (TypeId::of::(), TypeId::of::()) { - #[inline(always)] fn get_s1s2(args: &FnCallArgs) -> ([char; 2], [char; 2]) { let x = &*args[0].read_lock::().expect(BUILTIN); let y = args[1].as_char().expect(BUILTIN); diff --git a/src/fn_call.rs b/src/fn_call.rs index 45cc65e6..5334069d 100644 --- a/src/fn_call.rs +++ b/src/fn_call.rs @@ -100,7 +100,7 @@ impl Drop for ArgBackup<'_> { } #[cfg(not(feature = "no_closure"))] -#[inline(always)] +#[inline] #[must_use] pub fn ensure_no_data_race( fn_name: &str, @@ -157,7 +157,6 @@ impl Engine { /// 3) Global modules - packages /// 4) Imported modules - functions marked with global namespace /// 5) Global sub-modules - functions marked with global namespace - #[inline(always)] #[must_use] fn resolve_fn<'s>( &self, @@ -447,7 +446,6 @@ impl Engine { pos: Position, level: usize, ) -> RhaiResult { - #[inline(always)] fn make_error( name: String, fn_def: &crate::ast::ScriptFnDef, @@ -564,7 +562,6 @@ impl Engine { // Does a scripted function exist? #[cfg(not(feature = "no_function"))] - #[inline(always)] #[must_use] pub(crate) fn has_script_fn( &self, @@ -619,7 +616,6 @@ impl Engine { _capture_scope: Option, _level: usize, ) -> Result<(Dynamic, bool), Box> { - #[inline(always)] fn no_method_err(name: &str, pos: Position) -> Result<(Dynamic, bool), Box> { let msg = format!("'{0}' should not be called this way. Try {0}(...);", name); EvalAltResult::ErrorRuntime(msg.into(), pos).into() @@ -782,7 +778,7 @@ impl Engine { /// Evaluate a list of statements with no `this` pointer. /// This is commonly used to evaluate a list of statements in an [`AST`] or a script function body. - #[inline(always)] + #[inline] #[must_use] pub(crate) fn eval_global_statements( &self, @@ -1018,7 +1014,7 @@ impl Engine { } /// Evaluate an argument. - #[inline(always)] + #[inline] #[must_use] pub(crate) fn get_arg_value( &self, diff --git a/src/fn_hash.rs b/src/fn_hash.rs index 1a20d02a..54d61623 100644 --- a/src/fn_hash.rs +++ b/src/fn_hash.rs @@ -21,7 +21,7 @@ impl Hasher for StraightHasher { fn finish(&self) -> u64 { self.0 } - #[inline(always)] + #[inline] fn write(&mut self, bytes: &[u8]) { assert_eq!(bytes.len(), 8, "StraightHasher can only hash u64 values"); diff --git a/src/fn_native.rs b/src/fn_native.rs index 82670f89..8ac9cedb 100644 --- a/src/fn_native.rs +++ b/src/fn_native.rs @@ -195,7 +195,7 @@ impl<'a> NativeCallContext<'a> { /// /// If `is_method` is [`true`], the first argument is assumed to be passed /// by reference and is not consumed. - #[inline(always)] + #[inline] #[must_use] pub fn call_fn_dynamic_raw( &self, @@ -338,7 +338,6 @@ pub enum CallableFunction { } impl fmt::Debug for CallableFunction { - #[inline(always)] fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { Self::Pure(_) => write!(f, "NativePureFunction"), @@ -353,7 +352,6 @@ impl fmt::Debug for CallableFunction { } impl fmt::Display for CallableFunction { - #[inline(always)] fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { Self::Pure(_) => write!(f, "NativePureFunction"), @@ -369,7 +367,7 @@ impl fmt::Display for CallableFunction { impl CallableFunction { /// Is this a pure native Rust function? - #[inline(always)] + #[inline] #[must_use] pub fn is_pure(&self) -> bool { match self { @@ -383,7 +381,7 @@ impl CallableFunction { } } /// Is this a native Rust method function? - #[inline(always)] + #[inline] #[must_use] pub fn is_method(&self) -> bool { match self { @@ -397,7 +395,7 @@ impl CallableFunction { } } /// Is this an iterator function? - #[inline(always)] + #[inline] #[must_use] pub const fn is_iter(&self) -> bool { match self { @@ -409,7 +407,7 @@ impl CallableFunction { } } /// Is this a Rhai-scripted function? - #[inline(always)] + #[inline] #[must_use] pub const fn is_script(&self) -> bool { match self { @@ -420,7 +418,7 @@ impl CallableFunction { } } /// Is this a plugin function? - #[inline(always)] + #[inline] #[must_use] pub const fn is_plugin_fn(&self) -> bool { match self { @@ -432,7 +430,7 @@ impl CallableFunction { } } /// Is this a native Rust function? - #[inline(always)] + #[inline] #[must_use] pub const fn is_native(&self) -> bool { match self { @@ -445,7 +443,7 @@ impl CallableFunction { } } /// Get the access mode. - #[inline(always)] + #[inline] #[must_use] pub fn access(&self) -> FnAccess { match self { @@ -457,7 +455,7 @@ impl CallableFunction { } } /// Get a shared reference to a native Rust function. - #[inline(always)] + #[inline] #[must_use] pub fn get_native_fn(&self) -> Option<&Shared> { match self { @@ -472,7 +470,7 @@ impl CallableFunction { /// /// Not available under `no_function`. #[cfg(not(feature = "no_function"))] - #[inline(always)] + #[inline] #[must_use] pub const fn get_script_fn_def(&self) -> Option<&Shared> { match self { @@ -481,7 +479,7 @@ impl CallableFunction { } } /// Get a reference to an iterator function. - #[inline(always)] + #[inline] #[must_use] pub fn get_iter_fn(&self) -> Option { match self { @@ -493,7 +491,7 @@ impl CallableFunction { } } /// Get a shared reference to a plugin function. - #[inline(always)] + #[inline] #[must_use] pub fn get_plugin_fn<'s>(&'s self) -> Option<&Shared> { match self { diff --git a/src/fn_ptr.rs b/src/fn_ptr.rs index 5c22208d..33a8f57e 100644 --- a/src/fn_ptr.rs +++ b/src/fn_ptr.rs @@ -96,7 +96,7 @@ impl FnPtr { /// This is to avoid unnecessarily cloning the arguments. /// Do not use the arguments after this call. If they are needed afterwards, /// clone them _before_ calling this function. - #[inline(always)] + #[inline] #[must_use] pub fn call_dynamic( &self, @@ -127,7 +127,6 @@ impl FnPtr { } impl fmt::Display for FnPtr { - #[inline(always)] fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "Fn({})", self.0) } @@ -136,7 +135,7 @@ impl fmt::Display for FnPtr { impl TryFrom for FnPtr { type Error = Box; - #[inline(always)] + #[inline] fn try_from(value: Identifier) -> Result { if is_valid_identifier(value.chars()) { Ok(Self(value, Default::default())) diff --git a/src/fn_register.rs b/src/fn_register.rs index 0e978142..b74a93ce 100644 --- a/src/fn_register.rs +++ b/src/fn_register.rs @@ -88,7 +88,7 @@ pub trait RegisterNativeFunction { fn return_type_name() -> &'static str; } -#[inline(always)] +#[inline] #[must_use] fn is_setter(_fn_name: &str) -> bool { #[cfg(not(feature = "no_object"))] diff --git a/src/immutable_string.rs b/src/immutable_string.rs index d6555698..1b4cd660 100644 --- a/src/immutable_string.rs +++ b/src/immutable_string.rs @@ -322,7 +322,7 @@ impl Add for &ImmutableString { } impl AddAssign for ImmutableString { - #[inline(always)] + #[inline] fn add_assign(&mut self, rhs: String) { if !rhs.is_empty() { if self.is_empty() { diff --git a/src/module/mod.rs b/src/module/mod.rs index ddcd7d3c..6dd33e6b 100644 --- a/src/module/mod.rs +++ b/src/module/mod.rs @@ -112,7 +112,7 @@ impl FuncInfo { /// # Note /// /// The first module name is skipped. Hashing starts from the _second_ module in the chain. -#[inline(always)] +#[inline] fn calc_native_fn_hash<'a>( modules: impl Iterator, fn_name: &str, @@ -324,7 +324,7 @@ impl Module { /// let module = Module::new(); /// assert!(module.is_empty()); /// ``` - #[inline(always)] + #[inline] #[must_use] pub fn is_empty(&self) -> bool { self.functions.is_empty() @@ -437,7 +437,7 @@ impl Module { /// module.set_var("answer", 42_i64); /// assert_eq!(module.get_var_value::("answer").unwrap(), 42); /// ``` - #[inline(always)] + #[inline] pub fn set_var( &mut self, name: impl Into, @@ -519,7 +519,7 @@ impl Module { /// By taking a mutable reference, it is assumed that some sub-modules will be modified. /// Thus the [`Module`] is automatically set to be non-indexed. #[cfg(not(feature = "no_module"))] - #[inline(always)] + #[inline] #[must_use] pub(crate) fn sub_modules_mut(&mut self) -> &mut BTreeMap> { // We must assume that the user has changed the sub-modules @@ -580,7 +580,7 @@ impl Module { /// module.set_sub_module("question", sub_module); /// assert!(module.get_sub_module("question").is_some()); /// ``` - #[inline(always)] + #[inline] pub fn set_sub_module( &mut self, name: impl Into, @@ -624,7 +624,7 @@ impl Module { /// The _last entry_ in the list should be the _return type_ of the function. /// In other words, the number of entries should be one larger than the number of parameters. #[cfg(feature = "metadata")] - #[inline(always)] + #[inline] pub fn update_fn_metadata(&mut self, hash_fn: u64, arg_names: &[&str]) -> &mut Self { let param_names = arg_names .iter() @@ -641,7 +641,7 @@ impl Module { /// Update the namespace of a registered function. /// /// The [`u64`] hash is returned by the [`set_native_fn`][Module::set_native_fn] call. - #[inline(always)] + #[inline] pub fn update_fn_namespace(&mut self, hash_fn: u64, namespace: FnNamespace) -> &mut Self { if let Some(f) = self.functions.get_mut(&hash_fn) { f.namespace = namespace; @@ -652,7 +652,7 @@ impl Module { } /// Remap type ID. - #[inline(always)] + #[inline] #[must_use] fn map_type(map: bool, type_id: TypeId) -> TypeId { if !map { @@ -1611,7 +1611,7 @@ impl Module { } /// Set a type iterator into the [`Module`]. - #[inline(always)] + #[inline] pub fn set_iter(&mut self, type_id: TypeId, func: IteratorFn) -> &mut Self { if self.indexed { self.all_type_iterators.insert(type_id, func.clone()); @@ -1678,7 +1678,6 @@ pub struct NamespaceRef { } impl fmt::Debug for NamespaceRef { - #[inline(always)] fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { if let Some(index) = self.index { write!(f, "{} -> ", index)?; @@ -1696,7 +1695,6 @@ impl fmt::Debug for NamespaceRef { } impl fmt::Display for NamespaceRef { - #[inline(always)] fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { for Ident { name, .. } in self.path.iter() { write!(f, "{}{}", name, Token::DoubleColon.syntax())?; @@ -1735,7 +1733,10 @@ impl NamespaceRef { #[inline(always)] #[must_use] pub fn new(&self) -> Self { - Default::default() + Self { + index: None, + path: StaticVec::new(), + } } /// Get the [`Scope`][crate::Scope] index offset. #[inline(always)] diff --git a/src/module/resolvers/file.rs b/src/module/resolvers/file.rs index 441114f3..f3b06113 100644 --- a/src/module/resolvers/file.rs +++ b/src/module/resolvers/file.rs @@ -200,7 +200,7 @@ impl FileModuleResolver { } /// Is a particular path cached? - #[inline(always)] + #[inline] #[must_use] pub fn is_cached(&self, path: &str, source_path: Option<&str>) -> bool { if !self.cache_enabled { @@ -227,7 +227,7 @@ impl FileModuleResolver { /// Remove the specified path from internal cache. /// /// The next time this path is resolved, the script file will be loaded once again. - #[inline(always)] + #[inline] #[must_use] pub fn clear_cache_for_path( &mut self, @@ -252,7 +252,6 @@ impl FileModuleResolver { } /// Construct a full file path. #[must_use] - #[must_use] fn get_file_path(&self, path: &str, source_path: Option<&str>) -> PathBuf { let path = Path::new(path); diff --git a/src/packages/string_basic.rs b/src/packages/string_basic.rs index c361863f..9169c3de 100644 --- a/src/packages/string_basic.rs +++ b/src/packages/string_basic.rs @@ -22,7 +22,7 @@ def_package!(crate:BasicStringPackage:"Basic string utilities, including printin // Register print and debug -#[inline(always)] +#[inline] pub fn print_with_func( fn_name: &str, ctx: &NativeCallContext, diff --git a/src/parse.rs b/src/parse.rs index 9d00409f..ae7e003e 100644 --- a/src/parse.rs +++ b/src/parse.rs @@ -59,7 +59,7 @@ pub struct IdentifierBuilder( impl IdentifierBuilder { /// Get an identifier from a text string. - #[inline(always)] + #[inline] #[must_use] pub fn get(&mut self, text: impl AsRef + Into) -> Identifier { #[cfg(not(feature = "no_smartstring"))] @@ -141,7 +141,7 @@ impl<'e> ParseState<'e> { /// i.e. the top element of [`ParseState`]'s variables stack is offset 1. /// /// Return `None` when the variable name is not found in the `stack`. - #[inline(always)] + #[inline] pub fn access_var(&mut self, name: &str, _pos: Position) -> Option { let mut barrier = false; @@ -242,7 +242,7 @@ impl ParseSettings { } /// Make sure that the current level of expression nesting is within the maximum limit. #[cfg(not(feature = "unchecked"))] - #[inline(always)] + #[inline] #[must_use] pub fn ensure_level_within_max_limit( &self, @@ -261,7 +261,7 @@ impl Expr { /// Convert a [`Variable`][Expr::Variable] into a [`Property`][Expr::Property]. /// All other variants are untouched. #[cfg(not(feature = "no_object"))] - #[inline(always)] + #[inline] #[must_use] fn into_property(self, state: &mut ParseState) -> Self { match self { diff --git a/src/scope.rs b/src/scope.rs index 9fa87088..861f92db 100644 --- a/src/scope.rs +++ b/src/scope.rs @@ -49,7 +49,7 @@ const SCOPE_ENTRIES_INLINED: usize = 8; // look up a variable. Variable lookup is usually via direct indexing, by-passing the name altogether. // // Since [`Dynamic`] is reasonably small, packing it tightly improves cache locality when variables are accessed. -#[derive(Debug, Clone, Hash)] +#[derive(Debug, Clone, Hash, Default)] pub struct Scope<'a> { /// Current value of the entry. values: smallvec::SmallVec<[Dynamic; SCOPE_ENTRIES_INLINED]>, @@ -59,13 +59,6 @@ pub struct Scope<'a> { >, } -impl Default for Scope<'_> { - #[inline(always)] - fn default() -> Self { - Self::new() - } -} - impl<'a> IntoIterator for Scope<'a> { type Item = (Cow<'a, str>, Dynamic); type IntoIter = Box + 'a>; @@ -97,10 +90,7 @@ impl<'a> Scope<'a> { #[inline(always)] #[must_use] pub fn new() -> Self { - Self { - values: Default::default(), - names: Default::default(), - } + Default::default() } /// Empty the [`Scope`]. /// @@ -246,7 +236,7 @@ impl<'a> Scope<'a> { self.push_dynamic_value(name, AccessMode::ReadOnly, value) } /// Add (push) a new entry with a [`Dynamic`] value to the [`Scope`]. - #[inline(always)] + #[inline] pub(crate) fn push_dynamic_value( &mut self, name: impl Into>, @@ -371,7 +361,7 @@ impl<'a> Scope<'a> { /// my_scope.set_value("x", 0_i64); /// assert_eq!(my_scope.get_value::("x").unwrap(), 0); /// ``` - #[inline(always)] + #[inline] pub fn set_value(&mut self, name: &'a str, value: impl Variant + Clone) -> &mut Self { match self.get_index(name) { None => { @@ -408,6 +398,7 @@ impl<'a> Scope<'a> { /// /// assert_eq!(my_scope.get_value::("x").unwrap(), 123); /// ``` + #[inline(always)] #[must_use] pub fn get_mut(&mut self, name: &str) -> Option<&mut Dynamic> { self.get_index(name) @@ -434,7 +425,7 @@ impl<'a> Scope<'a> { /// /// Panics if the index is out of bounds. #[cfg(not(feature = "no_module"))] - #[inline(always)] + #[inline] pub(crate) fn add_entry_alias(&mut self, index: usize, alias: Identifier) -> &mut Self { let (_, aliases) = self .names @@ -456,7 +447,7 @@ impl<'a> Scope<'a> { #[inline(always)] #[must_use] pub(crate) fn clone_visible(&self) -> Self { - let mut entries: Self = Default::default(); + let mut entries = Self::new(); self.names .iter() diff --git a/src/token.rs b/src/token.rs index 86ad18fc..8d2f4cc2 100644 --- a/src/token.rs +++ b/src/token.rs @@ -211,7 +211,6 @@ impl Default for Position { } impl fmt::Display for Position { - #[inline(always)] fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { if self.is_none() { write!(f, "none")?; @@ -227,7 +226,6 @@ impl fmt::Display for Position { } impl fmt::Debug for Position { - #[inline(always)] fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { #[cfg(not(feature = "no_position"))] write!(f, "{}:{}", self.line, self.pos)?; @@ -772,10 +770,8 @@ impl Token { #[inline(always)] #[must_use] pub const fn is_eof(&self) -> bool { - use Token::*; - match self { - EOF => true, + Self::EOF => true, _ => false, } } @@ -917,6 +913,7 @@ impl Token { } /// Is this token an active standard keyword? + #[inline] #[must_use] pub const fn is_keyword(&self) -> bool { use Token::*; @@ -947,6 +944,7 @@ impl Token { /// Convert a token into a function name, if possible. #[cfg(not(feature = "no_function"))] + #[inline] #[must_use] pub(crate) fn into_function_name_for_override(self) -> Result { match self { @@ -1304,7 +1302,7 @@ fn scan_block_comment( /// # Volatile API /// /// This function is volatile and may change. -#[inline(always)] +#[inline] #[must_use] pub fn get_next_token( stream: &mut impl InputStream, @@ -1986,7 +1984,7 @@ fn get_identifier( } /// Is this keyword allowed as a function? -#[inline(always)] +#[inline] #[must_use] pub fn is_keyword_function(name: &str) -> bool { match name { @@ -2062,7 +2060,7 @@ pub struct MultiInputsStream<'a> { } impl InputStream for MultiInputsStream<'_> { - #[inline(always)] + #[inline] fn unget(&mut self, ch: char) { if self.buf.is_some() { panic!("cannot unget two characters in a row"); @@ -2252,7 +2250,7 @@ impl Engine { self.lex_raw(input, Some(map)) } /// Tokenize an input text stream with an optional mapping function. - #[inline(always)] + #[inline] #[must_use] pub(crate) fn lex_raw<'a>( &'a self,