Refine inlining.
This commit is contained in:
parent
82b64e9c7a
commit
6c777e68d3
@ -36,6 +36,8 @@ fn main() -> Result<(), Box<EvalAltResult>> {
|
|||||||
type Item = i64;
|
type Item = i64;
|
||||||
type IntoIter = std::vec::IntoIter<Self::Item>;
|
type IntoIter = std::vec::IntoIter<Self::Item>;
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
#[must_use]
|
||||||
fn into_iter(self) -> Self::IntoIter {
|
fn into_iter(self) -> Self::IntoIter {
|
||||||
vec![self.x - 1, self.x, self.x + 1].into_iter()
|
vec![self.x - 1, self.x, self.x + 1].into_iter()
|
||||||
}
|
}
|
||||||
|
@ -157,7 +157,6 @@ impl Deref for Expression<'_> {
|
|||||||
type Target = Expr;
|
type Target = Expr;
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
#[must_use]
|
|
||||||
fn deref(&self) -> &Self::Target {
|
fn deref(&self) -> &Self::Target {
|
||||||
self.0
|
self.0
|
||||||
}
|
}
|
||||||
|
@ -77,6 +77,7 @@ pub struct DefinitionsConfig {
|
|||||||
|
|
||||||
impl Default for DefinitionsConfig {
|
impl Default for DefinitionsConfig {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
|
#[must_use]
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self {
|
Self {
|
||||||
write_headers: false,
|
write_headers: false,
|
||||||
|
@ -75,6 +75,7 @@ impl Limits {
|
|||||||
|
|
||||||
impl Default for Limits {
|
impl Default for Limits {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
|
#[must_use]
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self::new()
|
Self::new()
|
||||||
}
|
}
|
||||||
|
@ -36,6 +36,7 @@ pub struct AST {
|
|||||||
|
|
||||||
impl Default for AST {
|
impl Default for AST {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
|
#[must_use]
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self::empty()
|
Self::empty()
|
||||||
}
|
}
|
||||||
|
@ -75,8 +75,8 @@ impl CustomExpr {
|
|||||||
/// Is this custom syntax self-terminated (i.e. no need for a semicolon terminator)?
|
/// Is this custom syntax self-terminated (i.e. no need for a semicolon terminator)?
|
||||||
///
|
///
|
||||||
/// A self-terminated custom syntax always ends in `$block$`, `}` or `;`
|
/// A self-terminated custom syntax always ends in `$block$`, `}` or `;`
|
||||||
#[must_use]
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
|
#[must_use]
|
||||||
pub const fn is_self_terminated(&self) -> bool {
|
pub const fn is_self_terminated(&self) -> bool {
|
||||||
self.self_terminated
|
self.self_terminated
|
||||||
}
|
}
|
||||||
@ -281,7 +281,6 @@ impl<F: Float> Deref for FloatWrapper<F> {
|
|||||||
type Target = F;
|
type Target = F;
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
#[must_use]
|
|
||||||
fn deref(&self) -> &Self::Target {
|
fn deref(&self) -> &Self::Target {
|
||||||
&self.0
|
&self.0
|
||||||
}
|
}
|
||||||
@ -290,7 +289,6 @@ impl<F: Float> Deref for FloatWrapper<F> {
|
|||||||
#[cfg(not(feature = "no_float"))]
|
#[cfg(not(feature = "no_float"))]
|
||||||
impl<F: Float> DerefMut for FloatWrapper<F> {
|
impl<F: Float> DerefMut for FloatWrapper<F> {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
#[must_use]
|
|
||||||
fn deref_mut(&mut self) -> &mut Self::Target {
|
fn deref_mut(&mut self) -> &mut Self::Target {
|
||||||
&mut self.0
|
&mut self.0
|
||||||
}
|
}
|
||||||
@ -447,6 +445,7 @@ pub enum Expr {
|
|||||||
|
|
||||||
impl Default for Expr {
|
impl Default for Expr {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
|
#[must_use]
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self::Unit(Position::NONE)
|
Self::Unit(Position::NONE)
|
||||||
}
|
}
|
||||||
|
@ -40,7 +40,6 @@ impl Deref for Ident {
|
|||||||
type Target = ImmutableString;
|
type Target = ImmutableString;
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
#[must_use]
|
|
||||||
fn deref(&self) -> &Self::Target {
|
fn deref(&self) -> &Self::Target {
|
||||||
&self.name
|
&self.name
|
||||||
}
|
}
|
||||||
@ -48,7 +47,6 @@ impl Deref for Ident {
|
|||||||
|
|
||||||
impl DerefMut for Ident {
|
impl DerefMut for Ident {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
#[must_use]
|
|
||||||
fn deref_mut(&mut self) -> &mut Self::Target {
|
fn deref_mut(&mut self) -> &mut Self::Target {
|
||||||
&mut self.name
|
&mut self.name
|
||||||
}
|
}
|
||||||
|
@ -72,7 +72,6 @@ impl Deref for Namespace {
|
|||||||
type Target = StaticVec<Ident>;
|
type Target = StaticVec<Ident>;
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
#[must_use]
|
|
||||||
fn deref(&self) -> &Self::Target {
|
fn deref(&self) -> &Self::Target {
|
||||||
&self.path
|
&self.path
|
||||||
}
|
}
|
||||||
@ -80,7 +79,6 @@ impl Deref for Namespace {
|
|||||||
|
|
||||||
impl DerefMut for Namespace {
|
impl DerefMut for Namespace {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
#[must_use]
|
|
||||||
fn deref_mut(&mut self) -> &mut Self::Target {
|
fn deref_mut(&mut self) -> &mut Self::Target {
|
||||||
&mut self.path
|
&mut self.path
|
||||||
}
|
}
|
||||||
|
@ -209,6 +209,7 @@ impl IntoIterator for RangeCase {
|
|||||||
type IntoIter = Box<dyn Iterator<Item = Self::Item>>;
|
type IntoIter = Box<dyn Iterator<Item = Self::Item>>;
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
|
#[must_use]
|
||||||
fn into_iter(self) -> Self::IntoIter {
|
fn into_iter(self) -> Self::IntoIter {
|
||||||
match self {
|
match self {
|
||||||
Self::ExclusiveInt(r, ..) => Box::new(r),
|
Self::ExclusiveInt(r, ..) => Box::new(r),
|
||||||
@ -426,7 +427,6 @@ impl Deref for StmtBlock {
|
|||||||
type Target = StmtBlockContainer;
|
type Target = StmtBlockContainer;
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
#[must_use]
|
|
||||||
fn deref(&self) -> &Self::Target {
|
fn deref(&self) -> &Self::Target {
|
||||||
&self.block
|
&self.block
|
||||||
}
|
}
|
||||||
@ -434,7 +434,6 @@ impl Deref for StmtBlock {
|
|||||||
|
|
||||||
impl DerefMut for StmtBlock {
|
impl DerefMut for StmtBlock {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
#[must_use]
|
|
||||||
fn deref_mut(&mut self) -> &mut Self::Target {
|
fn deref_mut(&mut self) -> &mut Self::Target {
|
||||||
&mut self.block
|
&mut self.block
|
||||||
}
|
}
|
||||||
@ -607,6 +606,7 @@ pub enum Stmt {
|
|||||||
|
|
||||||
impl Default for Stmt {
|
impl Default for Stmt {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
|
#[must_use]
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self::Noop(Position::NONE)
|
Self::Noop(Position::NONE)
|
||||||
}
|
}
|
||||||
|
@ -190,6 +190,7 @@ impl fmt::Debug for Engine {
|
|||||||
|
|
||||||
impl Default for Engine {
|
impl Default for Engine {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
|
#[must_use]
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self::new()
|
Self::new()
|
||||||
}
|
}
|
||||||
|
@ -48,6 +48,7 @@ pub enum DebuggerCommand {
|
|||||||
|
|
||||||
impl Default for DebuggerCommand {
|
impl Default for DebuggerCommand {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
|
#[must_use]
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self::Continue
|
Self::Continue
|
||||||
}
|
}
|
||||||
|
@ -316,7 +316,6 @@ impl IntoIterator for GlobalRuntimeState<'_> {
|
|||||||
std::iter::Rev<smallvec::IntoIter<[crate::Shared<crate::Module>; 3]>>,
|
std::iter::Rev<smallvec::IntoIter<[crate::Shared<crate::Module>; 3]>>,
|
||||||
>;
|
>;
|
||||||
|
|
||||||
#[inline]
|
|
||||||
fn into_iter(self) -> Self::IntoIter {
|
fn into_iter(self) -> Self::IntoIter {
|
||||||
self.keys
|
self.keys
|
||||||
.into_iter()
|
.into_iter()
|
||||||
@ -333,10 +332,8 @@ impl<'a> IntoIterator for &'a GlobalRuntimeState<'_> {
|
|||||||
std::iter::Rev<std::slice::Iter<'a, crate::Shared<crate::Module>>>,
|
std::iter::Rev<std::slice::Iter<'a, crate::Shared<crate::Module>>>,
|
||||||
>;
|
>;
|
||||||
|
|
||||||
#[inline]
|
|
||||||
fn into_iter(self) -> Self::IntoIter {
|
fn into_iter(self) -> Self::IntoIter {
|
||||||
let x = self.keys.iter().rev().zip(self.modules.iter().rev());
|
self.keys.iter().rev().zip(self.modules.iter().rev())
|
||||||
x
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -399,7 +399,6 @@ impl Deref for Target<'_> {
|
|||||||
type Target = Dynamic;
|
type Target = Dynamic;
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
#[must_use]
|
|
||||||
fn deref(&self) -> &Dynamic {
|
fn deref(&self) -> &Dynamic {
|
||||||
match self {
|
match self {
|
||||||
Self::RefMut(r) => r,
|
Self::RefMut(r) => r,
|
||||||
@ -425,7 +424,6 @@ impl AsRef<Dynamic> for Target<'_> {
|
|||||||
|
|
||||||
impl DerefMut for Target<'_> {
|
impl DerefMut for Target<'_> {
|
||||||
#[inline]
|
#[inline]
|
||||||
#[must_use]
|
|
||||||
fn deref_mut(&mut self) -> &mut Dynamic {
|
fn deref_mut(&mut self) -> &mut Dynamic {
|
||||||
match self {
|
match self {
|
||||||
Self::RefMut(r) => r,
|
Self::RefMut(r) => r,
|
||||||
|
@ -46,6 +46,7 @@ pub trait Func<ARGS, RET> {
|
|||||||
/// func(123, "hello")? == false; // call the anonymous function
|
/// func(123, "hello")? == false; // call the anonymous function
|
||||||
/// # Ok(())
|
/// # Ok(())
|
||||||
/// # }
|
/// # }
|
||||||
|
#[must_use]
|
||||||
fn create_from_ast(self, ast: AST, entry_point: &str) -> Self::Output;
|
fn create_from_ast(self, ast: AST, entry_point: &str) -> Self::Output;
|
||||||
|
|
||||||
/// Create a Rust closure from a script.
|
/// Create a Rust closure from a script.
|
||||||
@ -79,6 +80,7 @@ pub trait Func<ARGS, RET> {
|
|||||||
/// # Ok(())
|
/// # Ok(())
|
||||||
/// # }
|
/// # }
|
||||||
/// ```
|
/// ```
|
||||||
|
#[must_use]
|
||||||
fn create_from_script(self, script: &str, entry_point: &str) -> ParseResult<Self::Output>;
|
fn create_from_script(self, script: &str, entry_point: &str) -> ParseResult<Self::Output>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -41,6 +41,7 @@ pub struct StraightHasher(u64);
|
|||||||
|
|
||||||
impl Hasher for StraightHasher {
|
impl Hasher for StraightHasher {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
|
#[must_use]
|
||||||
fn finish(&self) -> u64 {
|
fn finish(&self) -> u64 {
|
||||||
self.0
|
self.0
|
||||||
}
|
}
|
||||||
@ -66,6 +67,7 @@ impl BuildHasher for StraightHasherBuilder {
|
|||||||
type Hasher = StraightHasher;
|
type Hasher = StraightHasher;
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
|
#[must_use]
|
||||||
fn build_hasher(&self) -> Self::Hasher {
|
fn build_hasher(&self) -> Self::Hasher {
|
||||||
StraightHasher(ALT_ZERO_HASH)
|
StraightHasher(ALT_ZERO_HASH)
|
||||||
}
|
}
|
||||||
|
@ -86,8 +86,11 @@ pub trait RegisterNativeFunction<ARGS, RET, RESULT> {
|
|||||||
/// _(metadata)_ Get the type name of this function's return value.
|
/// _(metadata)_ Get the type name of this function's return value.
|
||||||
/// Exported under the `metadata` feature only.
|
/// Exported under the `metadata` feature only.
|
||||||
#[cfg(feature = "metadata")]
|
#[cfg(feature = "metadata")]
|
||||||
|
#[inline(always)]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
fn return_type_name() -> &'static str;
|
fn return_type_name() -> &'static str {
|
||||||
|
std::any::type_name::<RET>()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const EXPECT_ARGS: &str = "arguments";
|
const EXPECT_ARGS: &str = "arguments";
|
||||||
@ -138,7 +141,6 @@ macro_rules! def_register {
|
|||||||
#[inline(always)] fn param_types() -> Box<[TypeId]> { vec![$(TypeId::of::<$par>()),*].into_boxed_slice() }
|
#[inline(always)] fn param_types() -> Box<[TypeId]> { vec![$(TypeId::of::<$par>()),*].into_boxed_slice() }
|
||||||
#[cfg(feature = "metadata")] #[inline(always)] fn param_names() -> Box<[&'static str]> { vec![$(std::any::type_name::<$param>()),*].into_boxed_slice() }
|
#[cfg(feature = "metadata")] #[inline(always)] fn param_names() -> Box<[&'static str]> { vec![$(std::any::type_name::<$param>()),*].into_boxed_slice() }
|
||||||
#[cfg(feature = "metadata")] #[inline(always)] fn return_type() -> TypeId { TypeId::of::<RET>() }
|
#[cfg(feature = "metadata")] #[inline(always)] fn return_type() -> TypeId { TypeId::of::<RET>() }
|
||||||
#[cfg(feature = "metadata")] #[inline(always)] fn return_type_name() -> &'static str { std::any::type_name::<RET>() }
|
|
||||||
#[inline(always)] fn into_callable_function(self) -> CallableFunction {
|
#[inline(always)] fn into_callable_function(self) -> CallableFunction {
|
||||||
CallableFunction::$abi(Shared::new(move |_ctx: NativeCallContext, args: &mut FnCallArgs| {
|
CallableFunction::$abi(Shared::new(move |_ctx: NativeCallContext, args: &mut FnCallArgs| {
|
||||||
// The arguments are assumed to be of the correct number and types!
|
// The arguments are assumed to be of the correct number and types!
|
||||||
@ -164,7 +166,6 @@ macro_rules! def_register {
|
|||||||
#[inline(always)] fn param_types() -> Box<[TypeId]> { vec![$(TypeId::of::<$par>()),*].into_boxed_slice() }
|
#[inline(always)] fn param_types() -> Box<[TypeId]> { vec![$(TypeId::of::<$par>()),*].into_boxed_slice() }
|
||||||
#[cfg(feature = "metadata")] #[inline(always)] fn param_names() -> Box<[&'static str]> { vec![$(std::any::type_name::<$param>()),*].into_boxed_slice() }
|
#[cfg(feature = "metadata")] #[inline(always)] fn param_names() -> Box<[&'static str]> { vec![$(std::any::type_name::<$param>()),*].into_boxed_slice() }
|
||||||
#[cfg(feature = "metadata")] #[inline(always)] fn return_type() -> TypeId { TypeId::of::<RET>() }
|
#[cfg(feature = "metadata")] #[inline(always)] fn return_type() -> TypeId { TypeId::of::<RET>() }
|
||||||
#[cfg(feature = "metadata")] #[inline(always)] fn return_type_name() -> &'static str { std::any::type_name::<RET>() }
|
|
||||||
#[inline(always)] fn into_callable_function(self) -> CallableFunction {
|
#[inline(always)] fn into_callable_function(self) -> CallableFunction {
|
||||||
CallableFunction::$abi(Shared::new(move |ctx: NativeCallContext, args: &mut FnCallArgs| {
|
CallableFunction::$abi(Shared::new(move |ctx: NativeCallContext, args: &mut FnCallArgs| {
|
||||||
// The arguments are assumed to be of the correct number and types!
|
// The arguments are assumed to be of the correct number and types!
|
||||||
|
@ -251,13 +251,10 @@ impl Engine {
|
|||||||
// Then check sub-modules
|
// Then check sub-modules
|
||||||
|| self.global_sub_modules.values().any(|m| m.contains_qualified_fn(hash_script));
|
|| self.global_sub_modules.values().any(|m| m.contains_qualified_fn(hash_script));
|
||||||
|
|
||||||
if !result {
|
if !result && !cache.filter.is_absent_and_set(hash_script) {
|
||||||
if cache.filter.is_absent(hash_script) {
|
// Do not cache "one-hit wonders"
|
||||||
cache.filter.mark(hash_script);
|
|
||||||
} else {
|
|
||||||
cache.map.insert(hash_script, None);
|
cache.map.insert(hash_script, None);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
result
|
result
|
||||||
}
|
}
|
||||||
|
@ -196,6 +196,7 @@ pub struct Module {
|
|||||||
|
|
||||||
impl Default for Module {
|
impl Default for Module {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
|
#[must_use]
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self::new()
|
Self::new()
|
||||||
}
|
}
|
||||||
|
@ -42,7 +42,7 @@ impl ModuleResolversCollection {
|
|||||||
/// ```
|
/// ```
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn new() -> Self {
|
pub const fn new() -> Self {
|
||||||
Self(Vec::new())
|
Self(Vec::new())
|
||||||
}
|
}
|
||||||
/// Append a [module resolver][ModuleResolver] to the end.
|
/// Append a [module resolver][ModuleResolver] to the end.
|
||||||
@ -112,6 +112,7 @@ impl IntoIterator for ModuleResolversCollection {
|
|||||||
type IntoIter = IntoIter<Box<dyn ModuleResolver>>;
|
type IntoIter = IntoIter<Box<dyn ModuleResolver>>;
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
|
#[must_use]
|
||||||
fn into_iter(self) -> Self::IntoIter {
|
fn into_iter(self) -> Self::IntoIter {
|
||||||
self.0.into_iter()
|
self.0.into_iter()
|
||||||
}
|
}
|
||||||
|
@ -56,6 +56,7 @@ pub struct FileModuleResolver {
|
|||||||
|
|
||||||
impl Default for FileModuleResolver {
|
impl Default for FileModuleResolver {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
|
#[must_use]
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self::new()
|
Self::new()
|
||||||
}
|
}
|
||||||
|
@ -134,6 +134,7 @@ impl IntoIterator for StaticModuleResolver {
|
|||||||
type IntoIter = IntoIter<SmartString, Shared<Module>>;
|
type IntoIter = IntoIter<SmartString, Shared<Module>>;
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
|
#[must_use]
|
||||||
fn into_iter(self) -> Self::IntoIter {
|
fn into_iter(self) -> Self::IntoIter {
|
||||||
self.0.into_iter()
|
self.0.into_iter()
|
||||||
}
|
}
|
||||||
|
@ -38,6 +38,7 @@ pub enum OptimizationLevel {
|
|||||||
|
|
||||||
impl Default for OptimizationLevel {
|
impl Default for OptimizationLevel {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
|
#[must_use]
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self::Simple
|
Self::Simple
|
||||||
}
|
}
|
||||||
|
@ -45,11 +45,14 @@ pub use time_basic::BasicTimePackage;
|
|||||||
pub trait Package {
|
pub trait Package {
|
||||||
/// Initialize the package.
|
/// Initialize the package.
|
||||||
/// Functions should be registered into `module` here.
|
/// Functions should be registered into `module` here.
|
||||||
|
#[cold]
|
||||||
fn init(module: &mut Module);
|
fn init(module: &mut Module);
|
||||||
|
|
||||||
/// Initialize the package with an [`Engine`].
|
/// Initialize the package with an [`Engine`].
|
||||||
///
|
///
|
||||||
/// Perform tasks such as registering custom operators/syntax.
|
/// Perform tasks such as registering custom operators/syntax.
|
||||||
|
#[cold]
|
||||||
|
#[inline]
|
||||||
#[allow(unused_variables)]
|
#[allow(unused_variables)]
|
||||||
fn init_engine(engine: &mut Engine) {}
|
fn init_engine(engine: &mut Engine) {}
|
||||||
|
|
||||||
@ -65,6 +68,8 @@ pub trait Package {
|
|||||||
///
|
///
|
||||||
/// package.register_into_engine(&mut engine);
|
/// package.register_into_engine(&mut engine);
|
||||||
/// ```
|
/// ```
|
||||||
|
#[cold]
|
||||||
|
#[inline]
|
||||||
fn register_into_engine(&self, engine: &mut Engine) -> &Self {
|
fn register_into_engine(&self, engine: &mut Engine) -> &Self {
|
||||||
Self::init_engine(engine);
|
Self::init_engine(engine);
|
||||||
engine.register_global_module(self.as_shared_module());
|
engine.register_global_module(self.as_shared_module());
|
||||||
@ -84,6 +89,8 @@ pub trait Package {
|
|||||||
/// package.register_into_engine_as(&mut engine, "core");
|
/// package.register_into_engine_as(&mut engine, "core");
|
||||||
/// ```
|
/// ```
|
||||||
#[cfg(not(feature = "no_module"))]
|
#[cfg(not(feature = "no_module"))]
|
||||||
|
#[cold]
|
||||||
|
#[inline]
|
||||||
fn register_into_engine_as(&self, engine: &mut Engine, name: &str) -> &Self {
|
fn register_into_engine_as(&self, engine: &mut Engine, name: &str) -> &Self {
|
||||||
Self::init_engine(engine);
|
Self::init_engine(engine);
|
||||||
engine.register_static_module(name, self.as_shared_module());
|
engine.register_static_module(name, self.as_shared_module());
|
||||||
@ -133,7 +140,6 @@ macro_rules! def_package {
|
|||||||
fn as_shared_module(&self) -> $crate::Shared<$crate::Module> {
|
fn as_shared_module(&self) -> $crate::Shared<$crate::Module> {
|
||||||
self.0.clone()
|
self.0.clone()
|
||||||
}
|
}
|
||||||
#[inline]
|
|
||||||
fn init($lib: &mut $crate::Module) {
|
fn init($lib: &mut $crate::Module) {
|
||||||
$($(
|
$($(
|
||||||
$(#[$base_meta])* { <$base_pkg>::init($lib); }
|
$(#[$base_meta])* { <$base_pkg>::init($lib); }
|
||||||
@ -141,7 +147,6 @@ macro_rules! def_package {
|
|||||||
|
|
||||||
$block
|
$block
|
||||||
}
|
}
|
||||||
#[inline]
|
|
||||||
fn init_engine(_engine: &mut $crate::Engine) {
|
fn init_engine(_engine: &mut $crate::Engine) {
|
||||||
$($(
|
$($(
|
||||||
$(#[$base_meta])* { <$base_pkg>::init_engine(_engine); }
|
$(#[$base_meta])* { <$base_pkg>::init_engine(_engine); }
|
||||||
@ -156,6 +161,7 @@ macro_rules! def_package {
|
|||||||
|
|
||||||
impl Default for $package {
|
impl Default for $package {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
|
#[must_use]
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self::new()
|
Self::new()
|
||||||
}
|
}
|
||||||
@ -193,12 +199,16 @@ macro_rules! def_package {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Default for $package {
|
impl Default for $package {
|
||||||
|
#[inline(always)]
|
||||||
|
#[must_use]
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self::new()
|
Self::new()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl $package {
|
impl $package {
|
||||||
|
#[inline]
|
||||||
|
#[must_use]
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
let mut module = $root::Module::new();
|
let mut module = $root::Module::new();
|
||||||
<Self as $root::packages::Package>::init(&mut module);
|
<Self as $root::packages::Package>::init(&mut module);
|
||||||
@ -229,12 +239,16 @@ macro_rules! def_package {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Default for $package {
|
impl Default for $package {
|
||||||
|
#[inline(always)]
|
||||||
|
#[must_use]
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self::new()
|
Self::new()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl $package {
|
impl $package {
|
||||||
|
#[inline]
|
||||||
|
#[must_use]
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
let mut module = $root::Module::new();
|
let mut module = $root::Module::new();
|
||||||
<Self as $root::packages::Package>::init(&mut module);
|
<Self as $root::packages::Package>::init(&mut module);
|
||||||
|
@ -110,7 +110,7 @@ impl fmt::Debug for ParseState<'_> {
|
|||||||
|
|
||||||
impl<'e> ParseState<'e> {
|
impl<'e> ParseState<'e> {
|
||||||
/// Create a new [`ParseState`].
|
/// Create a new [`ParseState`].
|
||||||
#[inline(always)]
|
#[inline]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn new(
|
pub fn new(
|
||||||
engine: &Engine,
|
engine: &Engine,
|
||||||
@ -183,7 +183,6 @@ impl<'e> ParseState<'e> {
|
|||||||
///
|
///
|
||||||
/// * `is_func_name`: `true` if the variable is actually the name of a function
|
/// * `is_func_name`: `true` if the variable is actually the name of a function
|
||||||
/// (in which case it will be converted into a function pointer).
|
/// (in which case it will be converted into a function pointer).
|
||||||
#[inline]
|
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn access_var(
|
pub fn access_var(
|
||||||
&mut self,
|
&mut self,
|
||||||
@ -235,7 +234,6 @@ impl<'e> ParseState<'e> {
|
|||||||
///
|
///
|
||||||
/// Panics when called under `no_module`.
|
/// Panics when called under `no_module`.
|
||||||
#[cfg(not(feature = "no_module"))]
|
#[cfg(not(feature = "no_module"))]
|
||||||
#[inline]
|
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn find_module(&self, name: &str) -> Option<NonZeroUsize> {
|
pub fn find_module(&self, name: &str) -> Option<NonZeroUsize> {
|
||||||
self.imports
|
self.imports
|
||||||
@ -258,7 +256,7 @@ impl<'e> ParseState<'e> {
|
|||||||
|
|
||||||
/// Get an interned property getter, creating one if it is not yet interned.
|
/// Get an interned property getter, creating one if it is not yet interned.
|
||||||
#[cfg(not(feature = "no_object"))]
|
#[cfg(not(feature = "no_object"))]
|
||||||
#[inline(always)]
|
#[inline]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn get_interned_getter(
|
pub fn get_interned_getter(
|
||||||
&mut self,
|
&mut self,
|
||||||
@ -273,7 +271,7 @@ impl<'e> ParseState<'e> {
|
|||||||
|
|
||||||
/// Get an interned property setter, creating one if it is not yet interned.
|
/// Get an interned property setter, creating one if it is not yet interned.
|
||||||
#[cfg(not(feature = "no_object"))]
|
#[cfg(not(feature = "no_object"))]
|
||||||
#[inline(always)]
|
#[inline]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn get_interned_setter(
|
pub fn get_interned_setter(
|
||||||
&mut self,
|
&mut self,
|
||||||
@ -313,7 +311,7 @@ struct ParseSettings {
|
|||||||
|
|
||||||
impl ParseSettings {
|
impl ParseSettings {
|
||||||
/// Create a new `ParseSettings` with one higher expression level.
|
/// Create a new `ParseSettings` with one higher expression level.
|
||||||
#[inline(always)]
|
#[inline]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub const fn level_up(&self) -> Self {
|
pub const fn level_up(&self) -> Self {
|
||||||
Self {
|
Self {
|
||||||
@ -417,7 +415,6 @@ impl Expr {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Make sure that the next expression is not a statement expression (i.e. wrapped in `{}`).
|
/// Make sure that the next expression is not a statement expression (i.e. wrapped in `{}`).
|
||||||
#[inline]
|
|
||||||
fn ensure_not_statement_expr(
|
fn ensure_not_statement_expr(
|
||||||
input: &mut TokenStream,
|
input: &mut TokenStream,
|
||||||
type_name: &(impl ToString + ?Sized),
|
type_name: &(impl ToString + ?Sized),
|
||||||
@ -429,7 +426,6 @@ fn ensure_not_statement_expr(
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Make sure that the next expression is not a mis-typed assignment (i.e. `a = b` instead of `a == b`).
|
/// Make sure that the next expression is not a mis-typed assignment (i.e. `a = b` instead of `a == b`).
|
||||||
#[inline]
|
|
||||||
fn ensure_not_assignment(input: &mut TokenStream) -> ParseResult<()> {
|
fn ensure_not_assignment(input: &mut TokenStream) -> ParseResult<()> {
|
||||||
match input.peek().expect(NEVER_ENDS) {
|
match input.peek().expect(NEVER_ENDS) {
|
||||||
(Token::Equals, pos) => Err(LexError::ImproperSymbol(
|
(Token::Equals, pos) => Err(LexError::ImproperSymbol(
|
||||||
@ -446,7 +442,6 @@ fn ensure_not_assignment(input: &mut TokenStream) -> ParseResult<()> {
|
|||||||
/// # Panics
|
/// # Panics
|
||||||
///
|
///
|
||||||
/// Panics if the next token is not the expected one.
|
/// Panics if the next token is not the expected one.
|
||||||
#[inline]
|
|
||||||
fn eat_token(input: &mut TokenStream, expected_token: Token) -> Position {
|
fn eat_token(input: &mut TokenStream, expected_token: Token) -> Position {
|
||||||
let (t, pos) = input.next().expect(NEVER_ENDS);
|
let (t, pos) = input.next().expect(NEVER_ENDS);
|
||||||
|
|
||||||
@ -462,7 +457,6 @@ fn eat_token(input: &mut TokenStream, expected_token: Token) -> Position {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Match a particular [token][Token], consuming it if matched.
|
/// Match a particular [token][Token], consuming it if matched.
|
||||||
#[inline]
|
|
||||||
fn match_token(input: &mut TokenStream, token: Token) -> (bool, Position) {
|
fn match_token(input: &mut TokenStream, token: Token) -> (bool, Position) {
|
||||||
let (t, pos) = input.peek().expect(NEVER_ENDS);
|
let (t, pos) = input.peek().expect(NEVER_ENDS);
|
||||||
if *t == token {
|
if *t == token {
|
||||||
@ -473,7 +467,6 @@ fn match_token(input: &mut TokenStream, token: Token) -> (bool, Position) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Parse a variable name.
|
/// Parse a variable name.
|
||||||
#[inline]
|
|
||||||
fn parse_var_name(input: &mut TokenStream) -> ParseResult<(SmartString, Position)> {
|
fn parse_var_name(input: &mut TokenStream) -> ParseResult<(SmartString, Position)> {
|
||||||
match input.next().expect(NEVER_ENDS) {
|
match input.next().expect(NEVER_ENDS) {
|
||||||
// Variable name
|
// Variable name
|
||||||
@ -491,7 +484,6 @@ fn parse_var_name(input: &mut TokenStream) -> ParseResult<(SmartString, Position
|
|||||||
|
|
||||||
/// Parse a symbol.
|
/// Parse a symbol.
|
||||||
#[cfg(not(feature = "no_custom_syntax"))]
|
#[cfg(not(feature = "no_custom_syntax"))]
|
||||||
#[inline]
|
|
||||||
fn parse_symbol(input: &mut TokenStream) -> ParseResult<(SmartString, Position)> {
|
fn parse_symbol(input: &mut TokenStream) -> ParseResult<(SmartString, Position)> {
|
||||||
match input.next().expect(NEVER_ENDS) {
|
match input.next().expect(NEVER_ENDS) {
|
||||||
// Symbol
|
// Symbol
|
||||||
|
@ -32,7 +32,7 @@ pub struct TokenizerControlBlock {
|
|||||||
|
|
||||||
impl TokenizerControlBlock {
|
impl TokenizerControlBlock {
|
||||||
/// Create a new `TokenizerControlBlock`.
|
/// Create a new `TokenizerControlBlock`.
|
||||||
#[inline(always)]
|
#[inline]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub const fn new() -> Self {
|
pub const fn new() -> Self {
|
||||||
Self {
|
Self {
|
||||||
@ -97,7 +97,7 @@ impl Position {
|
|||||||
/// # Panics
|
/// # Panics
|
||||||
///
|
///
|
||||||
/// Panics if `line` is zero.
|
/// Panics if `line` is zero.
|
||||||
#[inline(always)]
|
#[inline]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub const fn new(line: u16, position: u16) -> Self {
|
pub const fn new(line: u16, position: u16) -> Self {
|
||||||
assert!(line != 0, "line cannot be zero");
|
assert!(line != 0, "line cannot be zero");
|
||||||
@ -220,6 +220,7 @@ impl Position {
|
|||||||
|
|
||||||
impl Default for Position {
|
impl Default for Position {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
|
#[must_use]
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self::START
|
Self::START
|
||||||
}
|
}
|
||||||
@ -299,6 +300,8 @@ pub struct Span {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Default for Span {
|
impl Default for Span {
|
||||||
|
#[inline(always)]
|
||||||
|
#[must_use]
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self::NONE
|
Self::NONE
|
||||||
}
|
}
|
||||||
@ -315,7 +318,7 @@ impl Span {
|
|||||||
Self { start, end }
|
Self { start, end }
|
||||||
}
|
}
|
||||||
/// Is this [`Span`] non-existent?
|
/// Is this [`Span`] non-existent?
|
||||||
#[inline(always)]
|
#[inline]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub const fn is_none(&self) -> bool {
|
pub const fn is_none(&self) -> bool {
|
||||||
self.start.is_none() && self.end.is_none()
|
self.start.is_none() && self.end.is_none()
|
||||||
|
@ -153,7 +153,6 @@ impl<'d, T: Any + Clone> Deref for DynamicWriteLock<'d, T> {
|
|||||||
type Target = T;
|
type Target = T;
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
#[must_use]
|
|
||||||
fn deref(&self) -> &Self::Target {
|
fn deref(&self) -> &Self::Target {
|
||||||
match self.0 {
|
match self.0 {
|
||||||
DynamicWriteLockInner::Reference(ref reference) => *reference,
|
DynamicWriteLockInner::Reference(ref reference) => *reference,
|
||||||
@ -165,7 +164,6 @@ impl<'d, T: Any + Clone> Deref for DynamicWriteLock<'d, T> {
|
|||||||
|
|
||||||
impl<'d, T: Any + Clone> DerefMut for DynamicWriteLock<'d, T> {
|
impl<'d, T: Any + Clone> DerefMut for DynamicWriteLock<'d, T> {
|
||||||
#[inline]
|
#[inline]
|
||||||
#[must_use]
|
|
||||||
fn deref_mut(&mut self) -> &mut Self::Target {
|
fn deref_mut(&mut self) -> &mut Self::Target {
|
||||||
match self.0 {
|
match self.0 {
|
||||||
DynamicWriteLockInner::Reference(ref mut reference) => *reference,
|
DynamicWriteLockInner::Reference(ref mut reference) => *reference,
|
||||||
|
@ -53,7 +53,6 @@ impl Deref for ImmutableString {
|
|||||||
type Target = SmartString;
|
type Target = SmartString;
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
#[must_use]
|
|
||||||
fn deref(&self) -> &Self::Target {
|
fn deref(&self) -> &Self::Target {
|
||||||
&self.0
|
&self.0
|
||||||
}
|
}
|
||||||
@ -148,6 +147,7 @@ impl FromStr for ImmutableString {
|
|||||||
type Err = ();
|
type Err = ();
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
|
#[must_use]
|
||||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||||
let s: SmartString = s.into();
|
let s: SmartString = s.into();
|
||||||
Ok(Self(s.into()))
|
Ok(Self(s.into()))
|
||||||
@ -156,6 +156,7 @@ impl FromStr for ImmutableString {
|
|||||||
|
|
||||||
impl FromIterator<char> for ImmutableString {
|
impl FromIterator<char> for ImmutableString {
|
||||||
#[inline]
|
#[inline]
|
||||||
|
#[must_use]
|
||||||
fn from_iter<T: IntoIterator<Item = char>>(iter: T) -> Self {
|
fn from_iter<T: IntoIterator<Item = char>>(iter: T) -> Self {
|
||||||
Self(iter.into_iter().collect::<SmartString>().into())
|
Self(iter.into_iter().collect::<SmartString>().into())
|
||||||
}
|
}
|
||||||
@ -163,6 +164,7 @@ impl FromIterator<char> for ImmutableString {
|
|||||||
|
|
||||||
impl<'a> FromIterator<&'a char> for ImmutableString {
|
impl<'a> FromIterator<&'a char> for ImmutableString {
|
||||||
#[inline]
|
#[inline]
|
||||||
|
#[must_use]
|
||||||
fn from_iter<T: IntoIterator<Item = &'a char>>(iter: T) -> Self {
|
fn from_iter<T: IntoIterator<Item = &'a char>>(iter: T) -> Self {
|
||||||
Self(iter.into_iter().copied().collect::<SmartString>().into())
|
Self(iter.into_iter().copied().collect::<SmartString>().into())
|
||||||
}
|
}
|
||||||
@ -170,6 +172,7 @@ impl<'a> FromIterator<&'a char> for ImmutableString {
|
|||||||
|
|
||||||
impl<'a> FromIterator<&'a str> for ImmutableString {
|
impl<'a> FromIterator<&'a str> for ImmutableString {
|
||||||
#[inline]
|
#[inline]
|
||||||
|
#[must_use]
|
||||||
fn from_iter<T: IntoIterator<Item = &'a str>>(iter: T) -> Self {
|
fn from_iter<T: IntoIterator<Item = &'a str>>(iter: T) -> Self {
|
||||||
Self(iter.into_iter().collect::<SmartString>().into())
|
Self(iter.into_iter().collect::<SmartString>().into())
|
||||||
}
|
}
|
||||||
@ -177,6 +180,7 @@ impl<'a> FromIterator<&'a str> for ImmutableString {
|
|||||||
|
|
||||||
impl FromIterator<String> for ImmutableString {
|
impl FromIterator<String> for ImmutableString {
|
||||||
#[inline]
|
#[inline]
|
||||||
|
#[must_use]
|
||||||
fn from_iter<T: IntoIterator<Item = String>>(iter: T) -> Self {
|
fn from_iter<T: IntoIterator<Item = String>>(iter: T) -> Self {
|
||||||
Self(iter.into_iter().collect::<SmartString>().into())
|
Self(iter.into_iter().collect::<SmartString>().into())
|
||||||
}
|
}
|
||||||
@ -184,6 +188,7 @@ impl FromIterator<String> for ImmutableString {
|
|||||||
|
|
||||||
impl FromIterator<SmartString> for ImmutableString {
|
impl FromIterator<SmartString> for ImmutableString {
|
||||||
#[inline]
|
#[inline]
|
||||||
|
#[must_use]
|
||||||
fn from_iter<T: IntoIterator<Item = SmartString>>(iter: T) -> Self {
|
fn from_iter<T: IntoIterator<Item = SmartString>>(iter: T) -> Self {
|
||||||
Self(iter.into_iter().collect::<SmartString>().into())
|
Self(iter.into_iter().collect::<SmartString>().into())
|
||||||
}
|
}
|
||||||
|
@ -39,6 +39,7 @@ pub struct StringsInterner<'a> {
|
|||||||
|
|
||||||
impl Default for StringsInterner<'_> {
|
impl Default for StringsInterner<'_> {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
|
#[must_use]
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self::new()
|
Self::new()
|
||||||
}
|
}
|
||||||
|
@ -128,7 +128,7 @@ impl IntoIterator for Scope<'_> {
|
|||||||
type Item = (String, Dynamic, Vec<Identifier>);
|
type Item = (String, Dynamic, Vec<Identifier>);
|
||||||
type IntoIter = Box<dyn Iterator<Item = Self::Item>>;
|
type IntoIter = Box<dyn Iterator<Item = Self::Item>>;
|
||||||
|
|
||||||
#[inline]
|
#[must_use]
|
||||||
fn into_iter(self) -> Self::IntoIter {
|
fn into_iter(self) -> Self::IntoIter {
|
||||||
Box::new(
|
Box::new(
|
||||||
self.values
|
self.values
|
||||||
@ -143,7 +143,7 @@ impl<'a> IntoIterator for &'a Scope<'_> {
|
|||||||
type Item = (&'a Identifier, &'a Dynamic, &'a Vec<Identifier>);
|
type Item = (&'a Identifier, &'a Dynamic, &'a Vec<Identifier>);
|
||||||
type IntoIter = Box<dyn Iterator<Item = Self::Item> + 'a>;
|
type IntoIter = Box<dyn Iterator<Item = Self::Item> + 'a>;
|
||||||
|
|
||||||
#[inline]
|
#[must_use]
|
||||||
fn into_iter(self) -> Self::IntoIter {
|
fn into_iter(self) -> Self::IntoIter {
|
||||||
Box::new(
|
Box::new(
|
||||||
self.values
|
self.values
|
||||||
@ -719,7 +719,6 @@ impl Scope<'_> {
|
|||||||
scope
|
scope
|
||||||
}
|
}
|
||||||
/// Get an iterator to entries in the [`Scope`].
|
/// Get an iterator to entries in the [`Scope`].
|
||||||
#[inline]
|
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
pub(crate) fn into_iter(self) -> impl Iterator<Item = (Identifier, Dynamic, Vec<Identifier>)> {
|
pub(crate) fn into_iter(self) -> impl Iterator<Item = (Identifier, Dynamic, Vec<Identifier>)> {
|
||||||
self.names
|
self.names
|
||||||
|
@ -49,6 +49,8 @@ fn build_type() -> Result<(), Box<EvalAltResult>> {
|
|||||||
type Item = INT;
|
type Item = INT;
|
||||||
type IntoIter = std::vec::IntoIter<Self::Item>;
|
type IntoIter = std::vec::IntoIter<Self::Item>;
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
#[must_use]
|
||||||
fn into_iter(self) -> Self::IntoIter {
|
fn into_iter(self) -> Self::IntoIter {
|
||||||
vec![self.x, self.y, self.z].into_iter()
|
vec![self.x, self.y, self.z].into_iter()
|
||||||
}
|
}
|
||||||
|
@ -337,6 +337,8 @@ impl IntoIterator for MyIterableType {
|
|||||||
type Item = char;
|
type Item = char;
|
||||||
type IntoIter = std::vec::IntoIter<Self::Item>;
|
type IntoIter = std::vec::IntoIter<Self::Item>;
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
#[must_use]
|
||||||
fn into_iter(self) -> Self::IntoIter {
|
fn into_iter(self) -> Self::IntoIter {
|
||||||
self.0.chars().collect::<Vec<_>>().into_iter()
|
self.0.chars().collect::<Vec<_>>().into_iter()
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user