Reduce call to Module::is_empty.
This commit is contained in:
parent
013ee223ee
commit
fca71b5ed2
@ -253,9 +253,7 @@ impl Engine {
|
|||||||
let orig_lib_len = global.lib.len();
|
let orig_lib_len = global.lib.len();
|
||||||
|
|
||||||
#[cfg(not(feature = "no_function"))]
|
#[cfg(not(feature = "no_function"))]
|
||||||
if ast.has_functions() {
|
global.lib.push(ast.shared_lib().clone());
|
||||||
global.lib.push(ast.functions().clone());
|
|
||||||
}
|
|
||||||
|
|
||||||
let mut no_this_ptr = Dynamic::NULL;
|
let mut no_this_ptr = Dynamic::NULL;
|
||||||
let this_ptr = this_ptr.unwrap_or(&mut no_this_ptr);
|
let this_ptr = this_ptr.unwrap_or(&mut no_this_ptr);
|
||||||
|
@ -212,9 +212,7 @@ impl Engine {
|
|||||||
let orig_lib_len = global.lib.len();
|
let orig_lib_len = global.lib.len();
|
||||||
|
|
||||||
#[cfg(not(feature = "no_function"))]
|
#[cfg(not(feature = "no_function"))]
|
||||||
if ast.has_functions() {
|
global.lib.push(ast.shared_lib().clone());
|
||||||
global.lib.push(ast.functions().clone());
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(not(feature = "no_module"))]
|
#[cfg(not(feature = "no_module"))]
|
||||||
let orig_embedded_module_resolver = mem::replace(
|
let orig_embedded_module_resolver = mem::replace(
|
||||||
|
@ -116,9 +116,8 @@ impl Engine {
|
|||||||
global.source = ast.source_raw().cloned();
|
global.source = ast.source_raw().cloned();
|
||||||
|
|
||||||
#[cfg(not(feature = "no_function"))]
|
#[cfg(not(feature = "no_function"))]
|
||||||
if ast.has_functions() {
|
global.lib.push(ast.shared_lib().clone());
|
||||||
global.lib.push(ast.functions().clone());
|
|
||||||
}
|
|
||||||
#[cfg(not(feature = "no_module"))]
|
#[cfg(not(feature = "no_module"))]
|
||||||
{
|
{
|
||||||
global.embedded_module_resolver = ast.resolver().cloned();
|
global.embedded_module_resolver = ast.resolver().cloned();
|
||||||
|
@ -57,12 +57,11 @@ impl fmt::Debug for AST {
|
|||||||
fp.field("body", &self.body.as_slice());
|
fp.field("body", &self.body.as_slice());
|
||||||
|
|
||||||
#[cfg(not(feature = "no_function"))]
|
#[cfg(not(feature = "no_function"))]
|
||||||
if !self.lib.is_empty() {
|
for (.., fn_def) in self.lib.iter_script_fn() {
|
||||||
for (.., fn_def) in self.lib.iter_script_fn() {
|
let sig = fn_def.to_string();
|
||||||
let sig = fn_def.to_string();
|
fp.field(&sig, &fn_def.body.as_slice());
|
||||||
fp.field(&sig, &fn_def.body.as_slice());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fp.finish()
|
fp.finish()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -231,23 +230,6 @@ impl AST {
|
|||||||
pub(crate) fn set_doc(&mut self, doc: impl Into<crate::SmartString>) {
|
pub(crate) fn set_doc(&mut self, doc: impl Into<crate::SmartString>) {
|
||||||
self.doc = doc.into();
|
self.doc = doc.into();
|
||||||
}
|
}
|
||||||
/// Get the shared [module][crate::Module] containing script-defined functions.
|
|
||||||
#[cfg(not(feature = "no_function"))]
|
|
||||||
#[cfg(not(feature = "internals"))]
|
|
||||||
#[inline(always)]
|
|
||||||
#[must_use]
|
|
||||||
pub(crate) fn functions(&self) -> &crate::SharedModule {
|
|
||||||
&self.lib
|
|
||||||
}
|
|
||||||
/// _(internals)_ Get the shared [module][crate::Module] containing script-defined functions.
|
|
||||||
/// Exported under the `internals` feature only.
|
|
||||||
#[cfg(not(feature = "no_function"))]
|
|
||||||
#[cfg(feature = "internals")]
|
|
||||||
#[inline(always)]
|
|
||||||
#[must_use]
|
|
||||||
pub fn functions(&self) -> &crate::SharedModule {
|
|
||||||
&self.lib
|
|
||||||
}
|
|
||||||
/// Get the statements.
|
/// Get the statements.
|
||||||
#[cfg(not(feature = "internals"))]
|
#[cfg(not(feature = "internals"))]
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
@ -756,7 +738,7 @@ impl AST {
|
|||||||
&mut self,
|
&mut self,
|
||||||
filter: impl Fn(FnNamespace, FnAccess, &str, usize) -> bool,
|
filter: impl Fn(FnNamespace, FnAccess, &str, usize) -> bool,
|
||||||
) -> &mut Self {
|
) -> &mut Self {
|
||||||
if !self.lib.is_empty() {
|
if self.has_functions() {
|
||||||
crate::func::shared_make_mut(&mut self.lib).retain_script_functions(filter);
|
crate::func::shared_make_mut(&mut self.lib).retain_script_functions(filter);
|
||||||
}
|
}
|
||||||
self
|
self
|
||||||
|
@ -1445,7 +1445,7 @@ impl Engine {
|
|||||||
|
|
||||||
// If new functions are defined within the eval string, it is an error
|
// If new functions are defined within the eval string, it is an error
|
||||||
#[cfg(not(feature = "no_function"))]
|
#[cfg(not(feature = "no_function"))]
|
||||||
if !ast.shared_lib().is_empty() {
|
if ast.has_functions() {
|
||||||
return Err(crate::PERR::WrongFnDefinition.into());
|
return Err(crate::PERR::WrongFnDefinition.into());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -118,9 +118,7 @@ impl Engine {
|
|||||||
.cloned()
|
.cloned()
|
||||||
.for_each(|(n, m)| global.push_import(n, m));
|
.for_each(|(n, m)| global.push_import(n, m));
|
||||||
|
|
||||||
if !lib.is_empty() {
|
global.lib.push(lib.clone());
|
||||||
global.lib.push(lib.clone());
|
|
||||||
}
|
|
||||||
|
|
||||||
Some(mem::replace(&mut global.constants, constants.clone()))
|
Some(mem::replace(&mut global.constants, constants.clone()))
|
||||||
} else {
|
} else {
|
||||||
|
@ -543,14 +543,13 @@ impl Module {
|
|||||||
#[inline]
|
#[inline]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn is_empty(&self) -> bool {
|
pub fn is_empty(&self) -> bool {
|
||||||
self.indexed
|
!self.contains_indexed_global_functions
|
||||||
&& !self.contains_indexed_global_functions
|
|
||||||
&& self.functions.is_empty()
|
&& self.functions.is_empty()
|
||||||
&& self.all_functions.as_ref().map_or(true, |m| m.is_empty())
|
|
||||||
&& self.variables.as_ref().map_or(true, |m| m.is_empty())
|
&& self.variables.as_ref().map_or(true, |m| m.is_empty())
|
||||||
&& self.all_variables.as_ref().map_or(true, |m| m.is_empty())
|
|
||||||
&& self.modules.as_ref().map_or(true, |m| m.is_empty())
|
&& self.modules.as_ref().map_or(true, |m| m.is_empty())
|
||||||
&& self.type_iterators.as_ref().map_or(true, |t| t.is_empty())
|
&& self.type_iterators.as_ref().map_or(true, |t| t.is_empty())
|
||||||
|
&& self.all_functions.as_ref().map_or(true, |m| m.is_empty())
|
||||||
|
&& self.all_variables.as_ref().map_or(true, |m| m.is_empty())
|
||||||
&& self
|
&& self
|
||||||
.all_type_iterators
|
.all_type_iterators
|
||||||
.as_ref()
|
.as_ref()
|
||||||
|
@ -154,9 +154,7 @@ impl FnPtr {
|
|||||||
let global = &mut GlobalRuntimeState::new(engine);
|
let global = &mut GlobalRuntimeState::new(engine);
|
||||||
|
|
||||||
#[cfg(not(feature = "no_function"))]
|
#[cfg(not(feature = "no_function"))]
|
||||||
if _ast.has_functions() {
|
global.lib.push(_ast.shared_lib().clone());
|
||||||
global.lib.push(_ast.functions().clone());
|
|
||||||
}
|
|
||||||
|
|
||||||
let ctx = (engine, self.fn_name(), None, &*global, Position::NONE).into();
|
let ctx = (engine, self.fn_name(), None, &*global, Position::NONE).into();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user