Refine inlining.

This commit is contained in:
Stephen Chung 2021-03-04 18:13:47 +08:00
parent 4e69b1847d
commit 0589572d19
10 changed files with 23 additions and 24 deletions

View File

@ -420,7 +420,7 @@ impl Hash for Dynamic {
}
/// Map the name of a standard type into a friendly form.
#[inline]
#[inline(always)]
pub(crate) fn map_std_type_name(name: &str) -> &str {
if name == type_name::<String>() {
"string"
@ -1496,7 +1496,7 @@ impl Dynamic {
}
/// Convert the [`Dynamic`] into an [`ImmutableString`] and return it.
/// Returns the name of the actual type if the cast fails.
#[inline]
#[inline(always)]
pub fn take_immutable_string(self) -> Result<ImmutableString, &'static str> {
match self.0 {
Union::Str(s, _) => Ok(s),

View File

@ -862,7 +862,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]
#[inline(always)]
pub fn new_raw() -> Self {
Self {
global_namespace: Default::default(),

View File

@ -1034,7 +1034,6 @@ impl Engine {
/// Read the contents of a file into a string.
#[cfg(not(feature = "no_std"))]
#[cfg(not(any(target_arch = "wasm32", target_arch = "wasm64")))]
#[inline]
fn read_file(path: crate::stdlib::path::PathBuf) -> Result<String, Box<EvalAltResult>> {
use crate::stdlib::io::Read;
@ -1276,7 +1275,7 @@ impl Engine {
/// # Ok(())
/// # }
/// ```
#[inline]
#[inline(always)]
pub fn compile_expression_with_scope(
&self,
scope: &Scope,
@ -1385,7 +1384,7 @@ impl Engine {
/// # Ok(())
/// # }
/// ```
#[inline]
#[inline(always)]
pub fn eval_with_scope<T: Variant + Clone>(
&self,
scope: &mut Scope,
@ -1437,7 +1436,7 @@ impl Engine {
/// # Ok(())
/// # }
/// ```
#[inline]
#[inline(always)]
pub fn eval_expression_with_scope<T: Variant + Clone>(
&self,
scope: &mut Scope,
@ -1502,7 +1501,7 @@ impl Engine {
/// # Ok(())
/// # }
/// ```
#[inline]
#[inline(always)]
pub fn eval_ast_with_scope<T: Variant + Clone>(
&self,
scope: &mut Scope,
@ -1578,7 +1577,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]
#[inline(always)]
pub fn consume_with_scope(
&self,
scope: &mut Scope,
@ -1659,7 +1658,7 @@ impl Engine {
/// # }
/// ```
#[cfg(not(feature = "no_function"))]
#[inline]
#[inline(always)]
pub fn call_fn<T: Variant + Clone>(
&self,
scope: &mut Scope,
@ -1760,7 +1759,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]
#[inline(always)]
pub(crate) fn call_fn_dynamic_raw(
&self,
scope: &mut Scope,
@ -1814,7 +1813,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]
#[inline(always)]
pub fn optimize_ast(
&self,
scope: &Scope,

View File

@ -176,7 +176,7 @@ impl Engine {
/// 3) Global modules - packages
/// 4) Imported modules - functions marked with global namespace
/// 5) Global sub-modules - functions marked with global namespace
#[inline]
#[inline(always)]
fn resolve_function<'s>(
&self,
mods: &Imports,
@ -831,7 +831,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]
#[inline(always)]
pub(crate) fn eval_global_statements(
&self,
scope: &mut Scope,

View File

@ -183,7 +183,7 @@ macro_rules! def_register {
RET: Variant + Clone
> RegisterFn<FN, ($($mark,)*), RET> for Engine
{
#[inline]
#[inline(always)]
fn register_fn(&mut self, name: &str, f: FN) -> &mut Self {
self.global_namespace.set_fn(name, FnNamespace::Global, FnAccess::Public, None,
&[$(map_type_id::<$par>()),*],
@ -198,7 +198,7 @@ macro_rules! def_register {
FN: Fn($($param),*) -> RhaiResult + SendSync + 'static,
> RegisterResultFn<FN, ($($mark,)*)> for Engine
{
#[inline]
#[inline(always)]
fn register_result_fn(&mut self, name: &str, f: FN) -> &mut Self {
self.global_namespace.set_fn(name, FnNamespace::Global, FnAccess::Public, None,
&[$(map_type_id::<$par>()),*],

View File

@ -598,7 +598,7 @@ impl Module {
/// let hash = module.set_fn_0("calc", || Ok(42_i64));
/// assert!(module.contains_fn(hash, true));
/// ```
#[inline]
#[inline(always)]
pub fn contains_fn(&self, hash_fn: NonZeroU64, public_only: bool) -> bool {
if public_only {
self.functions

View File

@ -105,7 +105,7 @@ impl<'e> ParseState<'e> {
/// i.e. the top element of the [`ParseState`] is offset 1.
///
/// Return `None` when the variable name is not found in the `stack`.
#[inline]
#[inline(always)]
fn access_var(&mut self, name: &str, _pos: Position) -> Option<NonZeroUsize> {
let mut barrier = false;
@ -230,7 +230,7 @@ impl Expr {
/// Convert a [`Variable`][Expr::Variable] into a [`Property`][Expr::Property].
/// All other variants are untouched.
#[cfg(not(feature = "no_object"))]
#[inline]
#[inline(always)]
fn into_property(self, state: &mut ParseState) -> Self {
match self {
Self::Variable(x) if x.1.is_none() => {

View File

@ -237,7 +237,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]
#[inline(always)]
pub(crate) fn push_dynamic_value(
&mut self,
name: impl Into<Cow<'a, str>>,
@ -420,7 +420,7 @@ impl<'a> Scope<'a> {
}
/// Clone the [`Scope`], keeping only the last instances of each variable name.
/// Shadowed variables are omitted in the copy.
#[inline]
#[inline(always)]
pub(crate) fn clone_visible(&self) -> Self {
let mut entries: Self = Default::default();

View File

@ -1029,7 +1029,7 @@ fn scan_block_comment(
/// # Volatile API
///
/// This function is volatile and may change.
#[inline]
#[inline(always)]
pub fn get_next_token(
stream: &mut impl InputStream,
state: &mut TokenizeState,
@ -1856,7 +1856,7 @@ impl Engine {
self.lex_raw(input, Some(map))
}
/// Tokenize an input text stream with an optional mapping function.
#[inline]
#[inline(always)]
pub(crate) fn lex_raw<'a>(
&'a self,
input: impl IntoIterator<Item = &'a &'a str>,

View File

@ -49,7 +49,7 @@ pub fn unsafe_cast_box<X: Variant, T: Variant>(item: Box<X>) -> Result<Box<T>, B
///
/// Force-casting a local variable's lifetime to the current [`Scope`][crate::Scope]'s larger lifetime saves
/// on allocations and string cloning, thus avoids us having to maintain a chain of [`Scope`][crate::Scope]'s.
#[inline]
#[inline(always)]
pub fn unsafe_cast_var_name_to_lifetime<'s>(name: &str) -> &'s str {
// WARNING - force-cast the variable name into the scope's lifetime to avoid cloning it
// this is safe because all local variables are cleared at the end of the block