Minor refactors.

This commit is contained in:
Stephen Chung
2022-03-20 21:58:43 +08:00
parent 1b3d5aeb53
commit 99118fe2c3
14 changed files with 114 additions and 98 deletions

View File

@@ -35,9 +35,10 @@ impl<'x, 'px, 'm, 'pm, 'pt> EvalContext<'_, 'x, 'px, 'm, 'pm, '_, '_, '_, '_, 'p
#[inline(always)]
#[must_use]
pub fn source(&self) -> Option<&str> {
match self.global.source.as_str() {
"" => None,
s => Some(s),
if self.global.source.is_empty() {
None
} else {
Some(self.global.source.as_str())
}
}
/// The current [`Scope`].

View File

@@ -28,7 +28,7 @@ pub struct EvalState<'a> {
/// Stack of function resolution caches.
fn_resolution_caches: StaticVec<FnResolutionCache>,
/// Take care of the lifetime parameter
dummy: PhantomData<Option<&'a ()>>,
dummy: PhantomData<&'a ()>,
}
impl EvalState<'_> {

View File

@@ -244,9 +244,10 @@ impl GlobalRuntimeState<'_> {
#[inline]
#[must_use]
pub fn source(&self) -> Option<&str> {
match self.source.as_str() {
"" => None,
s => Some(s),
if self.source.is_empty() {
None
} else {
Some(self.source.as_str())
}
}
/// Get the pre-calculated index getter hash.

View File

@@ -952,9 +952,10 @@ impl Engine {
result => Some(result),
})
.or_else(|| {
self.module_resolver
.as_ref()
.map(|r| r.resolve_raw(self, global, &path, path_pos))
Some(
self.module_resolver
.resolve_raw(self, global, &path, path_pos),
)
})
.unwrap_or_else(|| {
Err(ERR::ErrorModuleNotFound(path.to_string(), path_pos).into())