Change some inline(always) into inline.

This commit is contained in:
Stephen Chung 2021-08-14 15:10:37 +08:00
parent 0f46bc7725
commit 3610b5eb7e
9 changed files with 46 additions and 46 deletions

View File

@ -81,7 +81,7 @@ impl Expression<'_> {
/// [`ImmutableString`][crate::ImmutableString].
///
/// Returns [`None`] also if the constant is not of the specified type.
#[inline(always)]
#[inline]
#[must_use]
pub fn get_literal_value<T: Variant>(&self) -> Option<T> {
// Coded this way in order to maximally leverage potentials for dead-code removal.

View File

@ -1038,7 +1038,7 @@ impl Dynamic {
/// assert_eq!(new_result.type_name(), "string");
/// assert_eq!(new_result.to_string(), "hello");
/// ```
#[inline(always)]
#[inline]
#[must_use]
pub fn from<T: Variant + Clone>(mut value: T) -> Self {
// Coded this way in order to maximally leverage potentials for dead-code removal.
@ -1179,7 +1179,7 @@ impl Dynamic {
///
/// assert_eq!(x.try_cast::<u32>().unwrap(), 42);
/// ```
#[inline(always)]
#[inline]
#[must_use]
pub fn try_cast<T: Any>(self) -> Option<T> {
// Coded this way in order to maximally leverage potentials for dead-code removal.
@ -1538,7 +1538,7 @@ impl Dynamic {
/// Casting to [`Dynamic`] just returns a reference to it.
///
/// Returns [`None`] if the cast fails, or if the value is shared.
#[inline(always)]
#[inline]
#[must_use]
pub(crate) fn downcast_ref<T: Any + Clone + ?Sized>(&self) -> Option<&T> {
// Coded this way in order to maximally leverage potentials for dead-code removal.
@ -1629,7 +1629,7 @@ impl Dynamic {
/// Casting to [`Dynamic`] just returns a mutable reference to it.
///
/// Returns [`None`] if the cast fails, or if the value is shared.
#[inline(always)]
#[inline]
#[must_use]
pub(crate) fn downcast_mut<T: Any + Clone>(&mut self) -> Option<&mut T> {
// Coded this way in order to maximally leverage potentials for dead-code removal.
@ -1728,7 +1728,7 @@ impl Dynamic {
}
/// Cast the [`Dynamic`] as a unit `()` and return it.
/// Returns the name of the actual type if the cast fails.
#[inline(always)]
#[inline]
pub fn as_unit(&self) -> Result<(), &'static str> {
match self.0 {
Union::Unit(value, _, _) => Ok(value),
@ -1739,7 +1739,7 @@ impl Dynamic {
}
/// Cast the [`Dynamic`] as the system integer type [`INT`] and return it.
/// Returns the name of the actual type if the cast fails.
#[inline(always)]
#[inline]
pub fn as_int(&self) -> Result<INT, &'static str> {
match self.0 {
Union::Int(n, _, _) => Ok(n),
@ -1753,7 +1753,7 @@ impl Dynamic {
///
/// Not available under `no_float`.
#[cfg(not(feature = "no_float"))]
#[inline(always)]
#[inline]
pub fn as_float(&self) -> Result<FLOAT, &'static str> {
match self.0 {
Union::Float(n, _, _) => Ok(*n),
@ -1767,7 +1767,7 @@ impl Dynamic {
///
/// Exported under the `decimal` feature only.
#[cfg(feature = "decimal")]
#[inline(always)]
#[inline]
pub fn as_decimal(&self) -> Result<Decimal, &'static str> {
match self.0 {
Union::Decimal(ref n, _, _) => Ok(**n),
@ -1778,7 +1778,7 @@ impl Dynamic {
}
/// Cast the [`Dynamic`] as a [`bool`] and return it.
/// Returns the name of the actual type if the cast fails.
#[inline(always)]
#[inline]
pub fn as_bool(&self) -> Result<bool, &'static str> {
match self.0 {
Union::Bool(b, _, _) => Ok(b),
@ -1789,7 +1789,7 @@ impl Dynamic {
}
/// Cast the [`Dynamic`] as a [`char`] and return it.
/// Returns the name of the actual type if the cast fails.
#[inline(always)]
#[inline]
pub fn as_char(&self) -> Result<char, &'static str> {
match self.0 {
Union::Char(n, _, _) => Ok(n),
@ -1804,7 +1804,7 @@ impl Dynamic {
/// # Panics
///
/// Panics if the value is shared.
#[inline(always)]
#[inline]
pub(crate) fn as_str_ref(&self) -> Result<&str, &'static str> {
match self.0 {
Union::Str(ref s, _, _) => Ok(s),
@ -1816,7 +1816,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 as_string(self) -> Result<String, &'static str> {
self.as_immutable_string().map(ImmutableString::into_owned)
}
@ -1954,7 +1954,7 @@ impl Dynamic {
impl<K: Into<crate::Identifier>, T: Variant + Clone> From<std::collections::HashMap<K, T>>
for Dynamic
{
#[inline(always)]
#[inline]
fn from(value: std::collections::HashMap<K, T>) -> Self {
Self(Union::Map(
Box::new(
@ -1971,7 +1971,7 @@ impl<K: Into<crate::Identifier>, T: Variant + Clone> From<std::collections::Hash
#[cfg(not(feature = "no_object"))]
#[cfg(not(feature = "no_std"))]
impl<K: Into<crate::Identifier>> From<std::collections::HashSet<K>> for Dynamic {
#[inline(always)]
#[inline]
fn from(value: std::collections::HashSet<K>) -> Self {
Self(Union::Map(
Box::new(
@ -1989,7 +1989,7 @@ impl<K: Into<crate::Identifier>> From<std::collections::HashSet<K>> for Dynamic
impl<K: Into<crate::Identifier>, T: Variant + Clone> From<std::collections::BTreeMap<K, T>>
for Dynamic
{
#[inline(always)]
#[inline]
fn from(value: std::collections::BTreeMap<K, T>) -> Self {
Self(Union::Map(
Box::new(
@ -2005,7 +2005,7 @@ impl<K: Into<crate::Identifier>, T: Variant + Clone> From<std::collections::BTre
}
#[cfg(not(feature = "no_object"))]
impl<K: Into<crate::Identifier>> From<std::collections::BTreeSet<K>> for Dynamic {
#[inline(always)]
#[inline]
fn from(value: std::collections::BTreeSet<K>) -> Self {
Self(Union::Map(
Box::new(

View File

@ -98,7 +98,7 @@ impl Imports {
self.modules.get_mut(index)
}
/// Get the index of an imported [module][Module] by name.
#[inline(always)]
#[inline]
#[must_use]
pub fn find(&self, name: &str) -> Option<usize> {
self.keys
@ -121,7 +121,7 @@ impl Imports {
}
/// Get an iterator to this stack of imported [modules][Module] in reverse order.
#[allow(dead_code)]
#[inline(always)]
#[inline]
pub fn iter(&self) -> impl Iterator<Item = (&str, &Module)> {
self.keys
.iter()
@ -131,13 +131,13 @@ impl Imports {
}
/// Get an iterator to this stack of imported [modules][Module] in reverse order.
#[allow(dead_code)]
#[inline(always)]
#[inline]
pub(crate) fn iter_raw(&self) -> impl Iterator<Item = (&Identifier, &Shared<Module>)> {
self.keys.iter().rev().zip(self.modules.iter().rev())
}
/// Get an iterator to this stack of imported [modules][Module] in forward order.
#[allow(dead_code)]
#[inline(always)]
#[inline]
pub(crate) fn scan_raw(&self) -> impl Iterator<Item = (&Identifier, &Shared<Module>)> {
self.keys.iter().zip(self.modules.iter())
}
@ -149,7 +149,7 @@ impl Imports {
self.modules.iter().any(|m| m.contains_qualified_fn(hash))
}
/// Get the specified function via its hash key from this stack of imported [modules][Module].
#[inline(always)]
#[inline]
#[must_use]
pub fn get_fn(&self, hash: u64) -> Option<(&CallableFunction, Option<&Identifier>)> {
self.modules
@ -167,7 +167,7 @@ impl Imports {
}
/// Get the specified [`TypeId`][std::any::TypeId] iterator from this stack of imported
/// [modules][Module].
#[inline(always)]
#[inline]
#[must_use]
pub fn get_iter(&self, id: TypeId) -> Option<IteratorFn> {
self.modules
@ -182,7 +182,7 @@ impl IntoIterator for Imports {
type IntoIter =
Zip<Rev<smallvec::IntoIter<[Identifier; 4]>>, Rev<smallvec::IntoIter<[Shared<Module>; 4]>>>;
#[inline(always)]
#[inline]
fn into_iter(self) -> Self::IntoIter {
self.keys
.into_iter()
@ -694,7 +694,7 @@ impl EvalState {
self.scope_level == 0
}
/// Get a mutable reference to the current function resolution cache.
#[inline(always)]
#[inline]
#[must_use]
pub fn fn_resolution_cache_mut(&mut self) -> &mut FnResolutionCache {
if self.fn_resolution_caches.is_empty() {

View File

@ -574,7 +574,7 @@ impl Engine {
/// # }
/// ```
#[cfg(any(not(feature = "no_index"), not(feature = "no_object")))]
#[inline(always)]
#[inline]
pub fn register_indexer_get<T: Variant + Clone, X: Variant + Clone, V: Variant + Clone>(
&mut self,
get_fn: impl Fn(&mut T, X) -> V + SendSync + 'static,
@ -648,7 +648,7 @@ impl Engine {
/// # }
/// ```
#[cfg(any(not(feature = "no_index"), not(feature = "no_object")))]
#[inline(always)]
#[inline]
pub fn register_indexer_get_result<
T: Variant + Clone,
X: Variant + Clone,
@ -724,7 +724,7 @@ impl Engine {
/// # }
/// ```
#[cfg(any(not(feature = "no_index"), not(feature = "no_object")))]
#[inline(always)]
#[inline]
pub fn register_indexer_set<T: Variant + Clone, X: Variant + Clone, V: Variant + Clone>(
&mut self,
set_fn: impl Fn(&mut T, X, V) + SendSync + 'static,
@ -799,7 +799,7 @@ impl Engine {
/// # }
/// ```
#[cfg(any(not(feature = "no_index"), not(feature = "no_object")))]
#[inline(always)]
#[inline]
pub fn register_indexer_set_result<
T: Variant + Clone,
X: Variant + Clone,

View File

@ -447,7 +447,7 @@ impl EvalAltResult {
}
/// Consume the current [`EvalAltResult`] and return a new one with the specified [`Position`]
/// if the current position is [`Position::None`].
#[inline(always)]
#[inline]
#[must_use]
pub(crate) fn fill_position(mut self: Box<Self>, new_position: Position) -> Box<Self> {
if self.position().is_none() {

View File

@ -39,7 +39,7 @@ pub fn by_ref<T: Variant + Clone>(data: &mut Dynamic) -> DynamicWriteLock<T> {
}
/// Dereference into value.
#[inline(always)]
#[inline]
#[must_use]
pub fn by_value<T: Variant + Clone>(data: &mut Dynamic) -> T {
if TypeId::of::<T>() == TypeId::of::<&str>() {

View File

@ -455,7 +455,7 @@ impl Module {
/// Get a reference to a namespace-qualified variable.
/// Name and Position in [`EvalAltResult`] are [`None`] and [`NONE`][Position::NONE] and must be set afterwards.
#[inline(always)]
#[inline]
pub(crate) fn get_qualified_var(&self, hash_var: u64) -> Result<&Dynamic, Box<EvalAltResult>> {
self.all_variables.get(&hash_var).ok_or_else(|| {
EvalAltResult::ErrorVariableNotFound(String::new(), Position::NONE).into()
@ -497,7 +497,7 @@ impl Module {
/// Get a shared reference to the script-defined function in the [`Module`] based on name
/// and number of parameters.
#[cfg(not(feature = "no_function"))]
#[inline(always)]
#[inline]
#[must_use]
pub fn get_script_fn(
&self,
@ -965,7 +965,7 @@ impl Module {
/// assert!(module.contains_fn(hash));
/// ```
#[cfg(any(not(feature = "no_index"), not(feature = "no_object")))]
#[inline(always)]
#[inline]
pub fn set_indexer_get_fn<ARGS, A, B, T, F>(&mut self, func: F) -> u64
where
A: Variant + Clone,
@ -1026,7 +1026,7 @@ impl Module {
/// assert!(module.contains_fn(hash));
/// ```
#[cfg(any(not(feature = "no_index"), not(feature = "no_object")))]
#[inline(always)]
#[inline]
pub fn set_indexer_set_fn<ARGS, A, B, C, F>(&mut self, func: F) -> u64
where
A: Variant + Clone,

View File

@ -189,7 +189,7 @@ impl<'e> ParseState<'e> {
///
/// Panics when called under `no_module`.
#[cfg(not(feature = "no_module"))]
#[inline(always)]
#[inline]
#[must_use]
pub fn find_module(&self, name: &str) -> Option<NonZeroUsize> {
self.modules
@ -325,7 +325,7 @@ impl Expr {
}
/// Make sure that the next expression is not a statement expression (i.e. wrapped in `{}`).
#[inline(always)]
#[inline]
fn ensure_not_statement_expr(input: &mut TokenStream, type_name: &str) -> Result<(), ParseError> {
match input.peek().expect(NEVER_ENDS) {
(Token::LeftBrace, pos) => Err(PERR::ExprExpected(type_name.to_string()).into_err(*pos)),
@ -334,7 +334,7 @@ fn ensure_not_statement_expr(input: &mut TokenStream, type_name: &str) -> Result
}
/// Make sure that the next expression is not a mis-typed assignment (i.e. `a = b` instead of `a == b`).
#[inline(always)]
#[inline]
fn ensure_not_assignment(input: &mut TokenStream) -> Result<(), ParseError> {
match input.peek().expect(NEVER_ENDS) {
(Token::Equals, pos) => Err(LexError::ImproperSymbol(

View File

@ -63,7 +63,7 @@ impl<'a> IntoIterator for Scope<'a> {
type Item = (Cow<'a, str>, Dynamic);
type IntoIter = Box<dyn Iterator<Item = Self::Item> + 'a>;
#[inline(always)]
#[inline]
fn into_iter(self) -> Self::IntoIter {
Box::new(
self.values
@ -293,7 +293,7 @@ impl<'a> Scope<'a> {
/// assert!(my_scope.contains("x"));
/// assert!(!my_scope.contains("y"));
/// ```
#[inline(always)]
#[inline]
#[must_use]
pub fn contains(&self, name: &str) -> bool {
self.names
@ -302,7 +302,7 @@ impl<'a> Scope<'a> {
.any(|(key, _)| name == key.as_ref())
}
/// Find an entry in the [`Scope`], starting from the last.
#[inline(always)]
#[inline]
#[must_use]
pub(crate) fn get_index(&self, name: &str) -> Option<(usize, AccessMode)> {
self.names
@ -329,7 +329,7 @@ impl<'a> Scope<'a> {
/// my_scope.push("x", 42_i64);
/// assert_eq!(my_scope.get_value::<i64>("x").unwrap(), 42);
/// ```
#[inline(always)]
#[inline]
#[must_use]
pub fn get_value<T: Variant + Clone>(&self, name: &str) -> Option<T> {
self.names
@ -398,7 +398,7 @@ impl<'a> Scope<'a> {
///
/// assert_eq!(my_scope.get_value::<i64>("x").unwrap(), 123);
/// ```
#[inline(always)]
#[inline]
#[must_use]
pub fn get_mut(&mut self, name: &str) -> Option<&mut Dynamic> {
self.get_index(name)
@ -444,7 +444,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(always)]
#[inline]
#[must_use]
pub(crate) fn clone_visible(&self) -> Self {
let mut entries = Self::new();
@ -463,7 +463,7 @@ impl<'a> Scope<'a> {
entries
}
/// Get an iterator to entries in the [`Scope`].
#[inline(always)]
#[inline]
#[allow(dead_code)]
pub(crate) fn into_iter(
self,
@ -507,7 +507,7 @@ impl<'a> Scope<'a> {
}
/// Get an iterator to entries in the [`Scope`].
/// Shared values are not expanded.
#[inline(always)]
#[inline]
pub fn iter_raw(&self) -> impl Iterator<Item = (&str, bool, &Dynamic)> {
self.names
.iter()