Add/remove #[inline] attributes.

This commit is contained in:
Stephen Chung
2020-10-08 22:25:50 +08:00
parent e34a370f33
commit 1272eeb81a
31 changed files with 328 additions and 114 deletions

View File

@@ -42,35 +42,43 @@ impl ModuleResolversCollection {
/// let mut engine = Engine::new();
/// engine.set_module_resolver(Some(collection));
/// ```
#[inline(always)]
pub fn new() -> Self {
Default::default()
}
/// Add a module keyed by its path.
#[inline(always)]
pub fn push(&mut self, resolver: impl ModuleResolver + 'static) {
self.0.push(Box::new(resolver));
}
/// Get an iterator of all the module resolvers.
#[inline(always)]
pub fn iter(&self) -> impl Iterator<Item = &dyn ModuleResolver> {
self.0.iter().map(|v| v.as_ref())
}
/// Get a mutable iterator of all the modules.
#[inline(always)]
pub fn into_iter(self) -> impl Iterator<Item = Box<dyn ModuleResolver>> {
self.0.into_iter()
}
/// Remove all module resolvers.
#[inline(always)]
pub fn clear(&mut self) {
self.0.clear();
}
/// Is this `ModuleResolversCollection` empty?
#[inline(always)]
pub fn is_empty(&self) -> bool {
self.0.is_empty()
}
/// Get the number of module resolvers in this `ModuleResolversCollection`.
#[inline(always)]
pub fn len(&self) -> usize {
self.0.len()
}
/// Add another `ModuleResolversCollection` to the end of this collection.
/// The other `ModuleResolversCollection` is consumed.
#[inline(always)]
pub fn append(&mut self, other: Self) {
if !other.is_empty() {
self.0.extend(other.0.into_iter());
@@ -101,6 +109,7 @@ impl ModuleResolver for ModuleResolversCollection {
}
impl<M: ModuleResolver + 'static> AddAssign<M> for ModuleResolversCollection {
#[inline(always)]
fn add_assign(&mut self, rhs: M) {
self.push(rhs);
}

View File

@@ -48,6 +48,7 @@ pub struct FileModuleResolver {
}
impl Default for FileModuleResolver {
#[inline(always)]
fn default() -> Self {
Self::new_with_path(PathBuf::default())
}
@@ -69,6 +70,7 @@ impl FileModuleResolver {
/// let mut engine = Engine::new();
/// engine.set_module_resolver(Some(resolver));
/// ```
#[inline(always)]
pub fn new_with_path<P: Into<PathBuf>>(path: P) -> Self {
Self::new_with_path_and_extension(path, "rhai")
}
@@ -90,6 +92,7 @@ impl FileModuleResolver {
/// let mut engine = Engine::new();
/// engine.set_module_resolver(Some(resolver));
/// ```
#[inline(always)]
pub fn new_with_path_and_extension<P: Into<PathBuf>, E: Into<String>>(
path: P,
extension: E,
@@ -116,11 +119,13 @@ impl FileModuleResolver {
/// let mut engine = Engine::new();
/// engine.set_module_resolver(Some(resolver));
/// ```
#[inline(always)]
pub fn new() -> Self {
Default::default()
}
/// Create a `Module` from a file path.
#[inline(always)]
pub fn create_module<P: Into<PathBuf>>(
&self,
engine: &Engine,

View File

@@ -42,59 +42,73 @@ impl StaticModuleResolver {
/// let mut engine = Engine::new();
/// engine.set_module_resolver(Some(resolver));
/// ```
#[inline(always)]
pub fn new() -> Self {
Default::default()
}
/// Add a module keyed by its path.
#[inline(always)]
pub fn insert<S: Into<String>>(&mut self, path: S, module: Module) {
self.0.insert(path.into(), module);
}
/// Remove a module given its path.
#[inline(always)]
pub fn remove(&mut self, path: &str) -> Option<Module> {
self.0.remove(path)
}
/// Does the path exist?
#[inline(always)]
pub fn contains_path(&self, path: &str) -> bool {
self.0.contains_key(path)
}
/// Get an iterator of all the modules.
#[inline(always)]
pub fn iter(&self) -> impl Iterator<Item = (&str, &Module)> {
self.0.iter().map(|(k, v)| (k.as_str(), v))
}
/// Get a mutable iterator of all the modules.
#[inline(always)]
pub fn iter_mut(&mut self) -> impl Iterator<Item = (&str, &mut Module)> {
self.0.iter_mut().map(|(k, v)| (k.as_str(), v))
}
/// Get a mutable iterator of all the modules.
#[inline(always)]
pub fn into_iter(self) -> impl Iterator<Item = (String, Module)> {
self.0.into_iter()
}
/// Get an iterator of all the module paths.
#[inline(always)]
pub fn paths(&self) -> impl Iterator<Item = &str> {
self.0.keys().map(String::as_str)
}
/// Get an iterator of all the modules.
#[inline(always)]
pub fn values(&self) -> impl Iterator<Item = &Module> {
self.0.values()
}
/// Get a mutable iterator of all the modules.
#[inline(always)]
pub fn values_mut(&mut self) -> impl Iterator<Item = &mut Module> {
self.0.values_mut()
}
/// Remove all modules.
#[inline(always)]
pub fn clear(&mut self) {
self.0.clear();
}
/// Is this `StaticModuleResolver` empty?
#[inline(always)]
pub fn is_empty(&self) -> bool {
self.0.is_empty()
}
/// Get the number of modules in this `StaticModuleResolver`.
#[inline(always)]
pub fn len(&self) -> usize {
self.0.len()
}
/// Merge another `StaticModuleResolver` into this.
/// The other `StaticModuleResolver` is consumed.
#[inline(always)]
pub fn merge(&mut self, other: Self) {
if !other.is_empty() {
self.0.extend(other.0.into_iter());
@@ -103,6 +117,7 @@ impl StaticModuleResolver {
}
impl ModuleResolver for StaticModuleResolver {
#[inline(always)]
fn resolve(&self, _: &Engine, path: &str, pos: Position) -> Result<Module, Box<EvalAltResult>> {
self.0
.get(path)
@@ -112,6 +127,7 @@ impl ModuleResolver for StaticModuleResolver {
}
impl AddAssign<Self> for StaticModuleResolver {
#[inline(always)]
fn add_assign(&mut self, rhs: Self) {
self.merge(rhs);
}