Minor code refactor.
This commit is contained in:
parent
d1fc362eec
commit
3116a39331
@ -19,7 +19,7 @@ Breaking changes
|
||||
New features
|
||||
------------
|
||||
|
||||
* Each `Dynamic` value can now contain arbitrary data (type `i16`) in the form of a _tag_. This is to use up otherwise wasted space in the `Dynamic` type.
|
||||
* Each `Dynamic` value can now contain arbitrary data (type `i32`) in the form of a _tag_. This is to use up otherwise wasted space in the `Dynamic` type.
|
||||
* A new internal feature `no_smartstring` to turn off `SmartString` for those rare cases that it is needed.
|
||||
* `DynamicReadLock` and `DynamicWriteLoc` are exposed under `internals`.
|
||||
* `From<Shared<Locked<Dynamic>>>` is added for `Dynamic` mapping directly to a shared value, together with support for `Dynamic::from`.
|
||||
|
@ -899,11 +899,7 @@ impl Engine {
|
||||
progress: None,
|
||||
|
||||
// optimization level
|
||||
optimization_level: if cfg!(feature = "no_optimize") {
|
||||
OptimizationLevel::None
|
||||
} else {
|
||||
OptimizationLevel::Simple
|
||||
},
|
||||
optimization_level: Default::default(),
|
||||
|
||||
#[cfg(not(feature = "unchecked"))]
|
||||
limits: Limits {
|
||||
@ -956,11 +952,7 @@ impl Engine {
|
||||
#[cfg(not(feature = "unchecked"))]
|
||||
progress: None,
|
||||
|
||||
optimization_level: if cfg!(feature = "no_optimize") {
|
||||
OptimizationLevel::None
|
||||
} else {
|
||||
OptimizationLevel::Simple
|
||||
},
|
||||
optimization_level: Default::default(),
|
||||
|
||||
#[cfg(not(feature = "unchecked"))]
|
||||
limits: Limits {
|
||||
|
@ -477,9 +477,7 @@ impl Engine {
|
||||
set_fn: impl Fn(&mut T, V) -> Result<(), Box<EvalAltResult>> + SendSync + 'static,
|
||||
) -> &mut Self {
|
||||
use crate::engine::make_setter;
|
||||
self.register_result_fn(&make_setter(name), move |obj: &mut T, value: V| {
|
||||
set_fn(obj, value)
|
||||
})
|
||||
self.register_result_fn(&make_setter(name), set_fn)
|
||||
}
|
||||
/// Short-hand for registering both getter and setter functions
|
||||
/// of a registered type with the [`Engine`].
|
||||
@ -807,12 +805,9 @@ impl Engine {
|
||||
panic!("Cannot register indexer for strings.");
|
||||
}
|
||||
|
||||
self.register_result_fn(
|
||||
crate::engine::FN_IDX_SET,
|
||||
move |obj: &mut T, index: X, value: V| set_fn(obj, index, value),
|
||||
)
|
||||
self.register_result_fn(crate::engine::FN_IDX_SET, set_fn)
|
||||
}
|
||||
/// Short-hand for register both index getter and setter functions for a custom type with the [`Engine`].
|
||||
/// Short-hand for registering both index getter and setter functions for a custom type with the [`Engine`].
|
||||
///
|
||||
/// Not available under `no_index`.
|
||||
///
|
||||
|
@ -156,20 +156,7 @@ pub struct Module {
|
||||
impl Default for Module {
|
||||
#[inline(always)]
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
id: None,
|
||||
internal: false,
|
||||
modules: Default::default(),
|
||||
variables: Default::default(),
|
||||
all_variables: Default::default(),
|
||||
functions: Default::default(),
|
||||
all_functions: Default::default(),
|
||||
type_iterators: Default::default(),
|
||||
all_type_iterators: Default::default(),
|
||||
indexed: true,
|
||||
contains_indexed_global_functions: false,
|
||||
identifiers: Default::default(),
|
||||
}
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
@ -257,7 +244,20 @@ impl Module {
|
||||
/// ```
|
||||
#[inline(always)]
|
||||
pub fn new() -> Self {
|
||||
Default::default()
|
||||
Self {
|
||||
id: None,
|
||||
internal: false,
|
||||
modules: Default::default(),
|
||||
variables: Default::default(),
|
||||
all_variables: Default::default(),
|
||||
functions: Default::default(),
|
||||
all_functions: Default::default(),
|
||||
type_iterators: Default::default(),
|
||||
all_type_iterators: Default::default(),
|
||||
indexed: true,
|
||||
contains_indexed_global_functions: false,
|
||||
identifiers: Default::default(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Get the ID of the [`Module`], if any.
|
||||
|
@ -31,8 +31,8 @@ impl DummyModuleResolver {
|
||||
/// engine.set_module_resolver(resolver);
|
||||
/// ```
|
||||
#[inline(always)]
|
||||
pub fn new() -> Self {
|
||||
Default::default()
|
||||
pub const fn new() -> Self {
|
||||
Self
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -31,24 +31,14 @@ pub enum OptimizationLevel {
|
||||
Full,
|
||||
}
|
||||
|
||||
impl OptimizationLevel {
|
||||
/// Is the `OptimizationLevel` [`None`][OptimizationLevel::None]?
|
||||
#[allow(dead_code)]
|
||||
impl Default for OptimizationLevel {
|
||||
#[inline(always)]
|
||||
pub fn is_none(self) -> bool {
|
||||
self == Self::None
|
||||
fn default() -> Self {
|
||||
if cfg!(feature = "no_optimize") {
|
||||
Self::None
|
||||
} else {
|
||||
Self::Simple
|
||||
}
|
||||
/// Is the `OptimizationLevel` [`Simple`][OptimizationLevel::Simple]?
|
||||
#[allow(dead_code)]
|
||||
#[inline(always)]
|
||||
pub fn is_simple(self) -> bool {
|
||||
self == Self::Simple
|
||||
}
|
||||
/// Is the `OptimizationLevel` [`Full`][OptimizationLevel::Full]?
|
||||
#[allow(dead_code)]
|
||||
#[inline(always)]
|
||||
pub fn is_full(self) -> bool {
|
||||
self == Self::Full
|
||||
}
|
||||
}
|
||||
|
||||
@ -1078,7 +1068,7 @@ pub fn optimize_into_ast(
|
||||
optimization_level: OptimizationLevel,
|
||||
) -> AST {
|
||||
let level = if cfg!(feature = "no_optimize") {
|
||||
OptimizationLevel::None
|
||||
Default::default()
|
||||
} else {
|
||||
optimization_level
|
||||
};
|
||||
@ -1087,7 +1077,7 @@ pub fn optimize_into_ast(
|
||||
let lib = {
|
||||
let mut module = Module::new();
|
||||
|
||||
if !level.is_none() {
|
||||
if level != OptimizationLevel::None {
|
||||
// We only need the script library's signatures for optimization purposes
|
||||
let mut lib2 = Module::new();
|
||||
|
||||
|
10
src/scope.rs
10
src/scope.rs
@ -62,10 +62,7 @@ pub struct Scope<'a> {
|
||||
impl Default for Scope<'_> {
|
||||
#[inline(always)]
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
values: Default::default(),
|
||||
names: Vec::with_capacity(SCOPE_SIZE),
|
||||
}
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
@ -99,7 +96,10 @@ impl<'a> Scope<'a> {
|
||||
/// ```
|
||||
#[inline(always)]
|
||||
pub fn new() -> Self {
|
||||
Default::default()
|
||||
Self {
|
||||
values: Default::default(),
|
||||
names: Vec::with_capacity(SCOPE_SIZE),
|
||||
}
|
||||
}
|
||||
/// Empty the [`Scope`].
|
||||
///
|
||||
|
Loading…
Reference in New Issue
Block a user