Use #[inline(always)] only when relatively certain.

This commit is contained in:
Stephen Chung 2021-10-21 17:26:43 +08:00
parent 313999b0ac
commit 9c16d90de9
21 changed files with 129 additions and 122 deletions

View File

@ -718,7 +718,7 @@ impl AST {
/// Not available under `no_function`.
#[cfg(not(feature = "no_function"))]
#[cfg(not(feature = "no_module"))]
#[inline(always)]
#[inline]
pub(crate) fn iter_fn_def(&self) -> impl Iterator<Item = &ScriptFnDef> {
self.functions
.iter_script_fn()
@ -728,7 +728,7 @@ impl AST {
///
/// Not available under `no_function`.
#[cfg(not(feature = "no_function"))]
#[inline(always)]
#[inline]
pub fn iter_functions<'a>(&'a self) -> impl Iterator<Item = ScriptFnMetadata> + 'a {
self.functions
.iter_script_fn()
@ -944,7 +944,7 @@ impl fmt::Debug for StmtBlock {
}
impl From<StmtBlock> for Stmt {
#[inline(always)]
#[inline]
fn from(block: StmtBlock) -> Self {
let block_pos = block.position();
Self::Block(block.0.into_boxed_slice(), block_pos)
@ -1852,7 +1852,7 @@ impl<F: Float> From<F> for FloatWrapper<F> {
impl<F: Float + FromStr> FromStr for FloatWrapper<F> {
type Err = <F as FromStr>::Err;
#[inline(always)]
#[inline]
fn from_str(s: &str) -> Result<Self, Self::Err> {
F::from_str(s).map(Into::<Self>::into)
}
@ -2132,7 +2132,7 @@ impl Expr {
}
}
/// Is the expression a simple variable access?
#[inline(always)]
#[inline]
#[must_use]
pub(crate) const fn is_variable_access(&self, non_qualified: bool) -> bool {
match self {
@ -2141,7 +2141,7 @@ impl Expr {
}
}
/// Return the variable name if the expression a simple variable access.
#[inline(always)]
#[inline]
#[must_use]
pub(crate) fn get_variable_name(&self, non_qualified: bool) -> Option<&str> {
match self {

View File

@ -255,7 +255,7 @@ enum DynamicReadLockInner<'d, T: Clone> {
impl<'d, T: Any + Clone> Deref for DynamicReadLock<'d, T> {
type Target = T;
#[inline(always)]
#[inline]
fn deref(&self) -> &Self::Target {
match self.0 {
DynamicReadLockInner::Reference(ref reference) => *reference,
@ -296,7 +296,7 @@ enum DynamicWriteLockInner<'d, T: Clone> {
impl<'d, T: Any + Clone> Deref for DynamicWriteLock<'d, T> {
type Target = T;
#[inline(always)]
#[inline]
fn deref(&self) -> &Self::Target {
match self.0 {
DynamicWriteLockInner::Reference(ref reference) => *reference,
@ -307,7 +307,7 @@ impl<'d, T: Any + Clone> Deref for DynamicWriteLock<'d, T> {
}
impl<'d, T: Any + Clone> DerefMut for DynamicWriteLock<'d, T> {
#[inline(always)]
#[inline]
fn deref_mut(&mut self) -> &mut Self::Target {
match self.0 {
DynamicWriteLockInner::Reference(ref mut reference) => *reference,
@ -384,17 +384,16 @@ impl Dynamic {
#[inline(always)]
#[must_use]
pub const fn is_shared(&self) -> bool {
match self.0 {
#[cfg(not(feature = "no_closure"))]
Union::Shared(_, _, _) => true,
_ => false,
}
#[cfg(not(feature = "no_closure"))]
return matches!(self.0, Union::Shared(_, _, _));
#[cfg(feature = "no_closure")]
return false;
}
/// Is the value held by this [`Dynamic`] a particular type?
///
/// If the [`Dynamic`] is a shared variant checking is performed on
/// top of its internal value.
#[inline(always)]
#[inline]
#[must_use]
pub fn is<T: Any + Clone>(&self) -> bool {
if TypeId::of::<T>() == TypeId::of::<String>() {
@ -1221,7 +1220,7 @@ impl Dynamic {
///
/// If the [`Dynamic`] value is already shared, this method returns itself.
#[cfg(not(feature = "no_closure"))]
#[inline(always)]
#[inline]
#[must_use]
pub fn into_shared(self) -> Self {
let _access = self.access_mode();
@ -1452,7 +1451,7 @@ impl Dynamic {
/// If the [`Dynamic`] is not a shared value, it returns a cloned copy.
///
/// If the [`Dynamic`] is a shared value, it returns a cloned copy of the shared value.
#[inline(always)]
#[inline]
#[must_use]
pub fn flatten_clone(&self) -> Self {
match self.0 {
@ -1471,7 +1470,7 @@ impl Dynamic {
///
/// If the [`Dynamic`] is a shared value, it returns the shared value if there are no
/// outstanding references, or a cloned copy.
#[inline(always)]
#[inline]
#[must_use]
pub fn flatten(self) -> Self {
match self.0 {
@ -1495,7 +1494,7 @@ impl Dynamic {
///
/// If the [`Dynamic`] is a shared value, it is set to the shared value if there are no
/// outstanding references, or a cloned copy otherwise.
#[inline(always)]
#[inline]
pub(crate) fn flatten_in_place(&mut self) -> &mut Self {
match self.0 {
#[cfg(not(feature = "no_closure"))]
@ -1528,7 +1527,7 @@ impl Dynamic {
/// Access just waits until the [`RwLock`][std::sync::RwLock] is released.
/// So this method always returns [`false`] under [`Sync`].
#[cfg(not(feature = "no_closure"))]
#[inline(always)]
#[inline]
#[must_use]
pub fn is_locked(&self) -> bool {
#[cfg(not(feature = "no_closure"))]
@ -1895,7 +1894,7 @@ impl Dynamic {
/// Convert the [`Dynamic`] into a [`String`] and return it.
/// If there are other references to the same string, a cloned copy is returned.
/// Returns the name of the actual type if the cast fails.
#[inline(always)]
#[inline]
pub fn into_string(self) -> Result<String, &'static str> {
self.into_immutable_string()
.map(ImmutableString::into_owned)
@ -1997,7 +1996,7 @@ impl Dynamic {
}
#[cfg(not(feature = "no_index"))]
impl<T: Variant + Clone> From<Vec<T>> for Dynamic {
#[inline(always)]
#[inline]
fn from(value: Vec<T>) -> Self {
Self(Union::Array(
Box::new(value.into_iter().map(Dynamic::from).collect()),
@ -2008,7 +2007,7 @@ impl<T: Variant + Clone> From<Vec<T>> for Dynamic {
}
#[cfg(not(feature = "no_index"))]
impl<T: Variant + Clone> From<&[T]> for Dynamic {
#[inline(always)]
#[inline]
fn from(value: &[T]) -> Self {
Self(Union::Array(
Box::new(value.iter().cloned().map(Dynamic::from).collect()),
@ -2019,7 +2018,7 @@ impl<T: Variant + Clone> From<&[T]> for Dynamic {
}
#[cfg(not(feature = "no_index"))]
impl<T: Variant + Clone> std::iter::FromIterator<T> for Dynamic {
#[inline(always)]
#[inline]
fn from_iter<X: IntoIterator<Item = T>>(iter: X) -> Self {
Self(Union::Array(
Box::new(iter.into_iter().map(Dynamic::from).collect()),

View File

@ -144,7 +144,7 @@ impl Imports {
}
/// Does the specified function hash key exist in this stack of imported [modules][Module]?
#[allow(dead_code)]
#[inline(always)]
#[inline]
#[must_use]
pub fn contains_fn(&self, hash: u64) -> bool {
self.modules.iter().any(|m| m.contains_qualified_fn(hash))
@ -161,7 +161,7 @@ impl Imports {
/// Does the specified [`TypeId`][std::any::TypeId] iterator exist in this stack of
/// imported [modules][Module]?
#[allow(dead_code)]
#[inline(always)]
#[inline]
#[must_use]
pub fn contains_iter(&self, id: TypeId) -> bool {
self.modules.iter().any(|m| m.contains_qualified_iter(id))
@ -888,7 +888,7 @@ impl<'x, 'px, 'pt> EvalContext<'_, 'x, 'px, '_, '_, '_, '_, 'pt> {
self.mods
}
/// Get an iterator over the namespaces containing definition of all script-defined functions.
#[inline(always)]
#[inline]
pub fn iter_namespaces(&self) -> impl Iterator<Item = &Module> {
self.lib.iter().cloned()
}
@ -3262,7 +3262,7 @@ impl Engine {
///
/// If a type is registered via [`register_type_with_name`][Engine::register_type_with_name],
/// the type name provided for the registration will be used.
#[inline(always)]
#[inline]
#[must_use]
pub fn map_type_name<'a>(&'a self, name: &'a str) -> &'a str {
self.type_names
@ -3272,7 +3272,7 @@ impl Engine {
}
/// Make a `Box<`[`EvalAltResult<ErrorMismatchDataType>`][EvalAltResult::ErrorMismatchDataType]`>`.
#[inline(always)]
#[inline]
#[must_use]
pub(crate) fn make_type_mismatch_err<T>(&self, typ: &str, pos: Position) -> Box<EvalAltResult> {
EvalAltResult::ErrorMismatchDataType(

View File

@ -1287,7 +1287,7 @@ impl Engine {
/// ```
#[cfg(not(feature = "no_std"))]
#[cfg(not(any(target_arch = "wasm32", target_arch = "wasm64")))]
#[inline(always)]
#[inline]
pub fn compile_file_with_scope(
&self,
scope: &Scope,
@ -1491,7 +1491,7 @@ impl Engine {
/// ```
#[cfg(not(feature = "no_std"))]
#[cfg(not(any(target_arch = "wasm32", target_arch = "wasm64")))]
#[inline(always)]
#[inline]
pub fn eval_file<T: Variant + Clone>(
&self,
path: std::path::PathBuf,
@ -1521,7 +1521,7 @@ impl Engine {
/// ```
#[cfg(not(feature = "no_std"))]
#[cfg(not(any(target_arch = "wasm32", target_arch = "wasm64")))]
#[inline(always)]
#[inline]
pub fn eval_file_with_scope<T: Variant + Clone>(
&self,
scope: &mut Scope,
@ -1569,7 +1569,7 @@ impl Engine {
/// # Ok(())
/// # }
/// ```
#[inline(always)]
#[inline]
pub fn eval_with_scope<T: Variant + Clone>(
&self,
scope: &mut Scope,
@ -1744,7 +1744,7 @@ impl Engine {
/// Not available under `no_std` or `WASM`.
#[cfg(not(feature = "no_std"))]
#[cfg(not(any(target_arch = "wasm32", target_arch = "wasm64")))]
#[inline(always)]
#[inline]
pub fn run_file(&self, path: std::path::PathBuf) -> Result<(), Box<EvalAltResult>> {
Self::read_file(path).and_then(|contents| self.run(&contents))
}
@ -1753,7 +1753,7 @@ impl Engine {
/// Not available under `no_std` or `WASM`.
#[cfg(not(feature = "no_std"))]
#[cfg(not(any(target_arch = "wasm32", target_arch = "wasm64")))]
#[inline(always)]
#[inline]
pub fn run_file_with_scope(
&self,
scope: &mut Scope,

View File

@ -67,7 +67,7 @@ impl Engine {
///
/// Not available under `unchecked`.
#[cfg(not(feature = "unchecked"))]
#[inline(always)]
#[inline]
#[must_use]
pub const fn max_operations(&self) -> u64 {
if let Some(n) = self.limits.max_operations {
@ -117,7 +117,7 @@ impl Engine {
///
/// Not available under `unchecked`.
#[cfg(not(feature = "unchecked"))]
#[inline(always)]
#[inline]
#[must_use]
pub const fn max_expr_depth(&self) -> usize {
if let Some(n) = self.limits.max_expr_depth {
@ -131,7 +131,7 @@ impl Engine {
/// Not available under `unchecked` or `no_function`.
#[cfg(not(feature = "unchecked"))]
#[cfg(not(feature = "no_function"))]
#[inline(always)]
#[inline]
#[must_use]
pub const fn max_function_expr_depth(&self) -> usize {
if let Some(n) = self.limits.max_function_expr_depth {
@ -153,7 +153,7 @@ impl Engine {
///
/// Not available under `unchecked`.
#[cfg(not(feature = "unchecked"))]
#[inline(always)]
#[inline]
#[must_use]
pub const fn max_string_size(&self) -> usize {
if let Some(n) = self.limits.max_string_size {
@ -177,7 +177,7 @@ impl Engine {
/// Not available under `unchecked` or `no_index`.
#[cfg(not(feature = "unchecked"))]
#[cfg(not(feature = "no_index"))]
#[inline(always)]
#[inline]
#[must_use]
pub const fn max_array_size(&self) -> usize {
if let Some(n) = self.limits.max_array_size {
@ -201,7 +201,7 @@ impl Engine {
/// Not available under `unchecked` or `no_object`.
#[cfg(not(feature = "unchecked"))]
#[cfg(not(feature = "no_object"))]
#[inline(always)]
#[inline]
#[must_use]
pub const fn max_map_size(&self) -> usize {
if let Some(n) = self.limits.max_map_size {

View File

@ -57,7 +57,7 @@ pub trait FuncArgs {
}
impl<T: Variant + Clone> FuncArgs for Vec<T> {
#[inline(always)]
#[inline]
fn parse<CONTAINER: Extend<Dynamic>>(self, container: &mut CONTAINER) {
container.extend(self.into_iter().map(Variant::into_dynamic));
}
@ -69,7 +69,7 @@ macro_rules! impl_args {
($($p:ident),*) => {
impl<$($p: Variant + Clone),*> FuncArgs for ($($p,)*)
{
#[inline(always)]
#[inline]
#[allow(unused_variables)]
fn parse<CONTAINER: Extend<Dynamic>>(self, container: &mut CONTAINER) {
let ($($p,)*) = self;

View File

@ -57,7 +57,7 @@ impl<'a> ArgBackup<'a> {
/// # Panics
///
/// Panics when `args` is empty.
#[inline(always)]
#[inline]
fn change_first_arg_to_copy(&mut self, args: &mut FnCallArgs<'a>) {
// Clone the original value.
self.value_copy = args[0].clone();
@ -91,7 +91,7 @@ impl<'a> ArgBackup<'a> {
}
impl Drop for ArgBackup<'_> {
#[inline(always)]
#[inline]
fn drop(&mut self) {
// Panic if the shorter lifetime leaks.
assert!(

View File

@ -96,13 +96,13 @@ macro_rules! def_anonymous_fn {
#[cfg(not(feature = "sync"))]
type Output = Box<dyn Fn($($par),*) -> Result<RET, Box<EvalAltResult>>>;
#[inline(always)]
#[inline]
fn create_from_ast(self, ast: AST, entry_point: &str) -> Self::Output {
let fn_name: SmartString = entry_point.into();
Box::new(move |$($par),*| self.call_fn(&mut Scope::new(), &ast, &fn_name, ($($par,)*)))
}
#[inline(always)]
#[inline]
fn create_from_script(self, script: &str, entry_point: &str) -> Result<Self::Output, ParseError> {
let ast = self.compile(script)?;
Ok(Func::<($($par,)*), RET>::create_from_ast(self, ast, entry_point))

View File

@ -144,14 +144,14 @@ impl<'a> NativeCallContext<'a> {
///
/// Not available under `no_module`.
#[cfg(not(feature = "no_module"))]
#[inline(always)]
#[inline]
pub fn iter_imports(&self) -> impl Iterator<Item = (&str, &Module)> {
self.mods.iter().flat_map(|&m| m.iter())
}
/// Get an iterator over the current set of modules imported via `import` statements.
#[cfg(not(feature = "no_module"))]
#[allow(dead_code)]
#[inline(always)]
#[inline]
pub(crate) fn iter_imports_raw(
&self,
) -> impl Iterator<Item = (&crate::Identifier, &Shared<Module>)> {
@ -169,7 +169,7 @@ impl<'a> NativeCallContext<'a> {
self.mods
}
/// Get an iterator over the namespaces containing definitions of all script-defined functions.
#[inline(always)]
#[inline]
pub fn iter_namespaces(&self) -> impl Iterator<Item = &Module> {
self.lib.iter().cloned()
}
@ -239,7 +239,7 @@ pub fn shared_make_mut<T: Clone>(value: &mut Shared<T>) -> &mut T {
}
/// Consume a [`Shared`] resource if is unique (i.e. not shared), or clone it otherwise.
#[inline(always)]
#[inline]
#[must_use]
pub fn shared_take_or_clone<T: Clone>(value: Shared<T>) -> T {
shared_try_take(value).unwrap_or_else(|v| v.as_ref().clone())
@ -256,7 +256,7 @@ pub fn shared_try_take<T>(value: Shared<T>) -> Result<T, Shared<T>> {
/// # Panics
///
/// Panics if the resource is shared (i.e. has other outstanding references).
#[inline(always)]
#[inline]
#[must_use]
pub fn shared_take<T>(value: Shared<T>) -> T {
shared_try_take(value)

View File

@ -69,7 +69,7 @@ impl FnPtr {
self
}
/// Set curried arguments to the function pointer.
#[inline(always)]
#[inline]
pub fn set_curry(&mut self, values: impl IntoIterator<Item = Dynamic>) -> &mut Self {
self.1 = values.into_iter().collect();
self

View File

@ -90,26 +90,29 @@ impl Borrow<str> for ImmutableString {
impl From<&str> for ImmutableString {
#[inline(always)]
fn from(value: &str) -> Self {
Self(Into::<SmartString>::into(value).into())
let value: SmartString = value.into();
Self(value.into())
}
}
impl From<&String> for ImmutableString {
#[inline(always)]
fn from(value: &String) -> Self {
Self(Into::<SmartString>::into(value).into())
let value: SmartString = value.into();
Self(value.into())
}
}
impl From<String> for ImmutableString {
#[inline(always)]
fn from(value: String) -> Self {
Self(Into::<SmartString>::into(value).into())
let value: SmartString = value.into();
Self(value.into())
}
}
#[cfg(not(feature = "no_smartstring"))]
impl From<&SmartString> for ImmutableString {
#[inline(always)]
fn from(value: &SmartString) -> Self {
Self(Into::<SmartString>::into(value.as_str()).into())
Self(value.clone().into())
}
}
#[cfg(not(feature = "no_smartstring"))]
@ -137,33 +140,34 @@ impl FromStr for ImmutableString {
#[inline(always)]
fn from_str(s: &str) -> Result<Self, Self::Err> {
Ok(Self(Into::<SmartString>::into(s).into()))
let s: SmartString = s.into();
Ok(Self(s.into()))
}
}
impl FromIterator<char> for ImmutableString {
#[inline(always)]
#[inline]
fn from_iter<T: IntoIterator<Item = char>>(iter: T) -> Self {
Self(iter.into_iter().collect::<SmartString>().into())
}
}
impl<'a> FromIterator<&'a char> for ImmutableString {
#[inline(always)]
#[inline]
fn from_iter<T: IntoIterator<Item = &'a char>>(iter: T) -> Self {
Self(iter.into_iter().cloned().collect::<SmartString>().into())
}
}
impl<'a> FromIterator<&'a str> for ImmutableString {
#[inline(always)]
#[inline]
fn from_iter<T: IntoIterator<Item = &'a str>>(iter: T) -> Self {
Self(iter.into_iter().collect::<SmartString>().into())
}
}
impl<'a> FromIterator<String> for ImmutableString {
#[inline(always)]
#[inline]
fn from_iter<T: IntoIterator<Item = String>>(iter: T) -> Self {
Self(iter.into_iter().collect::<SmartString>().into())
}
@ -171,7 +175,7 @@ impl<'a> FromIterator<String> for ImmutableString {
#[cfg(not(feature = "no_smartstring"))]
impl<'a> FromIterator<SmartString> for ImmutableString {
#[inline(always)]
#[inline]
fn from_iter<T: IntoIterator<Item = SmartString>>(iter: T) -> Self {
Self(iter.into_iter().collect::<SmartString>().into())
}
@ -278,7 +282,7 @@ impl Add<&str> for &ImmutableString {
}
impl AddAssign<&str> for ImmutableString {
#[inline(always)]
#[inline]
fn add_assign(&mut self, rhs: &str) {
if !rhs.is_empty() {
self.make_mut().push_str(rhs);
@ -324,7 +328,8 @@ impl AddAssign<String> for ImmutableString {
fn add_assign(&mut self, rhs: String) {
if !rhs.is_empty() {
if self.is_empty() {
self.0 = Into::<SmartString>::into(rhs).into();
let rhs: SmartString = rhs.into();
self.0 = rhs.into();
} else {
self.make_mut().push_str(&rhs);
}
@ -335,7 +340,7 @@ impl AddAssign<String> for ImmutableString {
impl Add<char> for ImmutableString {
type Output = Self;
#[inline(always)]
#[inline]
fn add(mut self, rhs: char) -> Self::Output {
self.make_mut().push(rhs);
self
@ -345,7 +350,7 @@ impl Add<char> for ImmutableString {
impl Add<char> for &ImmutableString {
type Output = ImmutableString;
#[inline(always)]
#[inline]
fn add(self, rhs: char) -> Self::Output {
let mut s = self.clone();
s.make_mut().push(rhs);
@ -354,7 +359,7 @@ impl Add<char> for &ImmutableString {
}
impl AddAssign<char> for ImmutableString {
#[inline(always)]
#[inline]
fn add_assign(&mut self, rhs: char) {
self.make_mut().push(rhs);
}
@ -397,7 +402,8 @@ impl SubAssign<&ImmutableString> for ImmutableString {
if self.is_empty() {
self.0 = rhs.0.clone();
} else {
self.0 = Into::<SmartString>::into(self.replace(rhs.as_str(), "")).into();
let rhs: SmartString = self.replace(rhs.as_str(), "").into();
self.0 = rhs.into();
}
}
}
@ -410,7 +416,8 @@ impl SubAssign<ImmutableString> for ImmutableString {
if self.is_empty() {
self.0 = rhs.0;
} else {
self.0 = Into::<SmartString>::into(self.replace(rhs.as_str(), "")).into();
let rhs: SmartString = self.replace(rhs.as_str(), "").into();
self.0 = rhs.into();
}
}
}
@ -447,9 +454,10 @@ impl Sub<String> for &ImmutableString {
}
impl SubAssign<String> for ImmutableString {
#[inline(always)]
#[inline]
fn sub_assign(&mut self, rhs: String) {
self.0 = Into::<SmartString>::into(self.replace(&rhs, "")).into();
let rhs: SmartString = self.replace(&rhs, "").into();
self.0 = rhs.into();
}
}
@ -472,9 +480,10 @@ impl Sub<char> for &ImmutableString {
}
impl SubAssign<char> for ImmutableString {
#[inline(always)]
#[inline]
fn sub_assign(&mut self, rhs: char) {
self.0 = Into::<SmartString>::into(self.replace(rhs, "")).into();
let rhs: SmartString = self.replace(rhs, "").into();
self.0 = rhs.into();
}
}
@ -527,7 +536,7 @@ impl ImmutableString {
}
/// Consume the [`ImmutableString`] and convert it into a [`String`].
/// If there are other references to the same string, a cloned copy is returned.
#[inline(always)]
#[inline]
pub fn into_owned(mut self) -> String {
self.make_mut(); // Make sure it is unique reference
shared_take(self.0).into() // Should succeed

View File

@ -204,7 +204,7 @@ impl AsRef<Module> for Module {
impl<M: AsRef<Module>> Add<M> for &Module {
type Output = Module;
#[inline(always)]
#[inline]
fn add(self, rhs: M) -> Self::Output {
let mut module = self.clone();
module.merge(rhs.as_ref());
@ -240,7 +240,7 @@ impl Module {
/// module.set_var("answer", 42_i64);
/// assert_eq!(module.get_var_value::<i64>("answer").expect("answer should exist"), 42);
/// ```
#[inline(always)]
#[inline]
#[must_use]
pub fn new() -> Self {
Self {
@ -269,7 +269,7 @@ impl Module {
/// module.set_id("hello");
/// assert_eq!(module.id(), Some("hello"));
/// ```
#[inline(always)]
#[inline]
#[must_use]
pub fn id(&self) -> Option<&str> {
self.id_raw().map(|s| s.as_str())
@ -365,7 +365,7 @@ impl Module {
/// Generate signatures for all the non-private functions in the [`Module`].
/// Exported under the `metadata` feature only.
#[cfg(feature = "metadata")]
#[inline(always)]
#[inline]
pub fn gen_fn_signatures(&self) -> impl Iterator<Item = String> + '_ {
self.functions
.values()
@ -402,7 +402,7 @@ impl Module {
/// module.set_var("answer", 42_i64);
/// assert_eq!(module.get_var_value::<i64>("answer").expect("answer should exist"), 42);
/// ```
#[inline(always)]
#[inline]
#[must_use]
pub fn get_var_value<T: Variant + Clone>(&self, name: &str) -> Option<T> {
self.get_var(name).and_then(Dynamic::try_cast::<T>)
@ -559,7 +559,7 @@ impl Module {
/// module.set_sub_module("question", sub_module);
/// assert!(module.get_sub_module("question").is_some());
/// ```
#[inline(always)]
#[inline]
#[must_use]
pub fn get_sub_module(&self, name: &str) -> Option<&Module> {
self.modules.get(name).map(|m| m.as_ref())
@ -1113,7 +1113,7 @@ impl Module {
/// Get a Rust function.
///
/// The [`u64`] hash is returned by the [`set_native_fn`][Module::set_native_fn] call.
#[inline(always)]
#[inline]
#[must_use]
pub(crate) fn get_fn(&self, hash_fn: u64) -> Option<&CallableFunction> {
self.functions.get(&hash_fn).map(|f| f.func.as_ref())
@ -1131,7 +1131,7 @@ impl Module {
/// Get a namespace-qualified function.
///
/// The [`u64`] hash is calculated by [`build_index`][Module::build_index].
#[inline(always)]
#[inline]
#[must_use]
pub(crate) fn get_qualified_fn(&self, hash_qualified_fn: u64) -> Option<&CallableFunction> {
self.all_functions
@ -1289,19 +1289,19 @@ impl Module {
}
/// Get an iterator to the sub-modules in the [`Module`].
#[inline(always)]
#[inline]
pub fn iter_sub_modules(&self) -> impl Iterator<Item = (&str, Shared<Module>)> {
self.modules.iter().map(|(k, m)| (k.as_str(), m.clone()))
}
/// Get an iterator to the variables in the [`Module`].
#[inline(always)]
#[inline]
pub fn iter_var(&self) -> impl Iterator<Item = (&str, &Dynamic)> {
self.variables.iter().map(|(k, v)| (k.as_str(), v))
}
/// Get an iterator to the functions in the [`Module`].
#[inline(always)]
#[inline]
#[allow(dead_code)]
pub(crate) fn iter_fn(&self) -> impl Iterator<Item = &FuncInfo> {
self.functions.values().map(Box::as_ref)
@ -1316,7 +1316,7 @@ impl Module {
/// 4) Number of parameters.
/// 5) Shared reference to function definition [`ScriptFnDef`][crate::ast::ScriptFnDef].
#[cfg(not(feature = "no_function"))]
#[inline(always)]
#[inline]
pub(crate) fn iter_script_fn(
&self,
) -> impl Iterator<
@ -1351,7 +1351,7 @@ impl Module {
/// 4) Number of parameters.
#[cfg(not(feature = "no_function"))]
#[cfg(not(feature = "internals"))]
#[inline(always)]
#[inline]
pub fn iter_script_fn_info(
&self,
) -> impl Iterator<Item = (FnNamespace, FnAccess, &str, usize)> {
@ -1610,7 +1610,7 @@ impl Module {
}
/// Set a type iterator into the [`Module`].
#[inline(always)]
#[inline]
pub fn set_iterable<T>(&mut self) -> &mut Self
where
T: Variant + Clone + IntoIterator,
@ -1622,7 +1622,7 @@ impl Module {
}
/// Set an iterator type into the [`Module`] as a type iterator.
#[inline(always)]
#[inline]
pub fn set_iterator<T>(&mut self) -> &mut Self
where
T: Variant + Clone + Iterator,
@ -1634,14 +1634,14 @@ impl Module {
}
/// Get the specified type iterator.
#[inline(always)]
#[inline]
#[must_use]
pub(crate) fn get_qualified_iter(&self, id: TypeId) -> Option<IteratorFn> {
self.all_type_iterators.get(&id).cloned()
}
/// Get the specified type iterator.
#[inline(always)]
#[inline]
#[must_use]
pub(crate) fn get_iter(&self, id: TypeId) -> Option<IteratorFn> {
self.type_iterators.get(&id).cloned()
@ -1709,8 +1709,7 @@ impl DerefMut for NamespaceRef {
impl From<StaticVec<Ident>> for NamespaceRef {
#[inline(always)]
fn from(path: StaticVec<Ident>) -> Self {
let mut path = path;
fn from(mut path: StaticVec<Ident>) -> Self {
path.shrink_to_fit();
Self { index: None, path }
}

View File

@ -76,7 +76,7 @@ impl ModuleResolversCollection {
self.0.remove(index)
}
/// Get an iterator of all the [module resolvers][ModuleResolver].
#[inline(always)]
#[inline]
pub fn iter(&self) -> impl Iterator<Item = &dyn ModuleResolver> {
self.0.iter().map(|v| v.as_ref())
}
@ -100,7 +100,7 @@ impl ModuleResolversCollection {
}
/// Add another [`ModuleResolversCollection`] to the end of this collection.
/// The other [`ModuleResolversCollection`] is consumed.
#[inline(always)]
#[inline]
pub fn append(&mut self, other: Self) -> &mut Self {
self.0.extend(other.0.into_iter());
self

View File

@ -215,7 +215,7 @@ impl FileModuleResolver {
return self.cache.write().unwrap().contains_key(&file_path);
}
/// Empty the internal cache.
#[inline(always)]
#[inline]
pub fn clear_cache(&mut self) -> &mut Self {
#[cfg(not(feature = "sync"))]
self.cache.borrow_mut().clear();

View File

@ -48,7 +48,7 @@ impl StaticModuleResolver {
Default::default()
}
/// Add a [module][Module] keyed by its path.
#[inline(always)]
#[inline]
pub fn insert(&mut self, path: impl Into<Identifier>, mut module: Module) {
module.build_index();
self.0.insert(path.into(), module.into());
@ -65,17 +65,17 @@ impl StaticModuleResolver {
self.0.contains_key(path)
}
/// Get an iterator of all the [modules][Module].
#[inline(always)]
#[inline]
pub fn iter(&self) -> impl Iterator<Item = (&str, &Shared<Module>)> {
self.0.iter().map(|(k, v)| (k.as_str(), v))
}
/// Get a mutable iterator of all the [modules][Module].
#[inline(always)]
#[inline]
pub fn iter_mut(&mut self) -> impl Iterator<Item = (&str, &mut Shared<Module>)> {
self.0.iter_mut().map(|(k, v)| (k.as_str(), v))
}
/// Get an iterator of all the [module][Module] paths.
#[inline(always)]
#[inline]
pub fn paths(&self) -> impl Iterator<Item = &str> {
self.0.keys().map(|s| s.as_str())
}
@ -105,7 +105,7 @@ impl StaticModuleResolver {
/// The other [`StaticModuleResolver`] is consumed.
///
/// Existing modules of the same path name are overwritten.
#[inline(always)]
#[inline]
pub fn merge(&mut self, other: Self) -> &mut Self {
if !other.is_empty() {
self.0.extend(other.0.into_iter());
@ -124,7 +124,7 @@ impl IntoIterator for StaticModuleResolver {
}
impl ModuleResolver for StaticModuleResolver {
#[inline(always)]
#[inline]
fn resolve(
&self,
_: &Engine,

View File

@ -123,7 +123,7 @@ impl<'a> OptimizerState<'a> {
})
}
/// Call a registered function
#[inline(always)]
#[inline]
pub fn call_fn_with_constant_arguments(
&self,
fn_name: &str,

View File

@ -251,7 +251,7 @@ impl Iterator for CharsStream {
}
}
#[inline(always)]
#[inline]
fn size_hint(&self) -> (usize, Option<usize>) {
let remaining = self.0.len() - self.1;
(remaining, Some(remaining))
@ -261,7 +261,7 @@ impl Iterator for CharsStream {
impl FusedIterator for CharsStream {}
impl ExactSizeIterator for CharsStream {
#[inline(always)]
#[inline]
fn len(&self) -> usize {
self.0.len() - self.1
}

View File

@ -3322,7 +3322,7 @@ impl Engine {
}
/// Run the parser on an input stream, returning an AST.
#[inline(always)]
#[inline]
pub(crate) fn parse(
&self,
input: &mut TokenStream,

View File

@ -482,7 +482,7 @@ impl<'a> Scope<'a> {
/// # Panics
///
/// Panics if the index is out of bounds.
#[inline(always)]
#[inline]
#[must_use]
pub(crate) fn get_mut_by_index(&mut self, index: usize) -> &mut Dynamic {
self.values.get_mut(index).expect("index is out of bounds")
@ -565,7 +565,7 @@ impl<'a> Scope<'a> {
/// assert!(is_constant);
/// assert_eq!(value.cast::<String>(), "hello");
/// ```
#[inline(always)]
#[inline]
pub fn iter(&self) -> impl Iterator<Item = (&str, bool, Dynamic)> {
self.iter_raw()
.map(|(name, constant, value)| (name, constant, value.flatten_clone()))
@ -582,7 +582,7 @@ impl<'a> Scope<'a> {
}
impl<'a, K: Into<Cow<'a, str>>> Extend<(K, Dynamic)> for Scope<'a> {
#[inline(always)]
#[inline]
fn extend<T: IntoIterator<Item = (K, Dynamic)>>(&mut self, iter: T) {
iter.into_iter().for_each(|(name, value)| {
self.names.push((name.into(), Default::default()));

View File

@ -113,7 +113,7 @@ impl Position {
/// If `line` is zero, then [`None`] is returned.
///
/// If `position` is zero, then it is at the beginning of a line.
#[inline(always)]
#[inline]
#[must_use]
pub const fn new_const(line: u16, position: u16) -> Option<Self> {
if line == 0 {
@ -129,7 +129,7 @@ impl Position {
})
}
/// Get the line number (1-based), or [`None`] if there is no position.
#[inline(always)]
#[inline]
#[must_use]
pub const fn line(self) -> Option<usize> {
#[cfg(not(feature = "no_position"))]
@ -143,7 +143,7 @@ impl Position {
return None;
}
/// Get the character position (1-based), or [`None`] if at beginning of a line.
#[inline(always)]
#[inline]
#[must_use]
pub const fn position(self) -> Option<usize> {
#[cfg(not(feature = "no_position"))]
@ -157,7 +157,7 @@ impl Position {
return None;
}
/// Advance by one character position.
#[inline(always)]
#[inline]
pub(crate) fn advance(&mut self) {
#[cfg(not(feature = "no_position"))]
{
@ -174,7 +174,7 @@ impl Position {
/// # Panics
///
/// Panics if already at beginning of a line - cannot rewind to a previous line.
#[inline(always)]
#[inline]
pub(crate) fn rewind(&mut self) {
#[cfg(not(feature = "no_position"))]
{
@ -184,7 +184,7 @@ impl Position {
}
}
/// Advance to the next line.
#[inline(always)]
#[inline]
pub(crate) fn new_line(&mut self) {
#[cfg(not(feature = "no_position"))]
{
@ -198,7 +198,7 @@ impl Position {
}
}
/// Is this [`Position`] at the beginning of a line?
#[inline(always)]
#[inline]
#[must_use]
pub const fn is_beginning_of_line(self) -> bool {
#[cfg(not(feature = "no_position"))]
@ -207,7 +207,7 @@ impl Position {
return false;
}
/// Is there no [`Position`]?
#[inline(always)]
#[inline]
#[must_use]
pub const fn is_none(self) -> bool {
#[cfg(not(feature = "no_position"))]
@ -216,7 +216,7 @@ impl Position {
return true;
}
/// Print this [`Position`] for debug purposes.
#[inline(always)]
#[inline]
pub(crate) fn debug_print(&self, _f: &mut fmt::Formatter<'_>) -> fmt::Result {
#[cfg(not(feature = "no_position"))]
if !self.is_none() {
@ -1352,7 +1352,7 @@ fn is_numeric_digit(c: char) -> bool {
/// Test if the comment block is a doc-comment.
#[cfg(not(feature = "no_function"))]
#[cfg(feature = "metadata")]
#[inline(always)]
#[inline]
#[must_use]
pub fn is_doc_comment(comment: &str) -> bool {
(comment.starts_with("///") && !comment.starts_with("////"))

View File

@ -8,7 +8,7 @@ use std::{
};
/// Cast a type into another type.
#[inline(always)]
#[inline]
pub fn unsafe_try_cast<A: Any, B: Any>(a: A) -> Result<B, A> {
if TypeId::of::<B>() == a.type_id() {
// SAFETY: Just checked we have the right type. We explicitly forget the
@ -25,7 +25,7 @@ pub fn unsafe_try_cast<A: Any, B: Any>(a: A) -> Result<B, A> {
}
/// Cast a Boxed type into another type.
#[inline(always)]
#[inline]
pub fn unsafe_cast_box<X: Any, T: Any>(item: Box<X>) -> Result<Box<T>, Box<X>> {
// Only allow casting to the exact same type
if TypeId::of::<X>() == TypeId::of::<T>() {