Fine tune Engine size.

This commit is contained in:
Stephen Chung 2023-03-07 16:52:37 +08:00
parent 3e784d592d
commit fa4096e91e
8 changed files with 56 additions and 54 deletions

View File

@ -402,7 +402,8 @@ impl Engine {
parse: Box::new(parse),
func: Box::new(func),
scope_may_be_changed,
},
}
.into(),
);
self
}

View File

@ -363,7 +363,7 @@ impl Engine {
+ SendSync
+ 'static,
) -> &mut Self {
self.debugger_interface = Some(Box::new((Box::new(init), Box::new(callback))));
self.debugger_interface = Some((Box::new(init), Box::new(callback)));
self
}
}

View File

@ -115,7 +115,7 @@ pub struct Engine {
/// Custom syntax.
#[cfg(not(feature = "no_custom_syntax"))]
pub(crate) custom_syntax: Option<
Box<std::collections::BTreeMap<Identifier, crate::api::custom_syntax::CustomSyntax>>,
Box<std::collections::BTreeMap<Identifier, Box<crate::api::custom_syntax::CustomSyntax>>>,
>,
/// Callback closure for filtering variable definition.
pub(crate) def_var_filter: Option<Box<OnDefVarCallback>>,
@ -147,12 +147,10 @@ pub struct Engine {
/// Callback closure for debugging.
#[cfg(feature = "debugging")]
pub(crate) debugger_interface: Option<
Box<(
pub(crate) debugger_interface: Option<(
Box<crate::eval::OnDebuggingInit>,
Box<crate::eval::OnDebuggerCallback>,
)>,
>,
}
impl fmt::Debug for Engine {

View File

@ -205,9 +205,13 @@ impl Engine {
}
// Report progress
self.progress
.as_ref()
.and_then(|p| p(global.num_operations))
.map_or(Ok(()), |token| Err(ERR::ErrorTerminated(token, pos).into()))
if let Some(ref progress) = self.progress {
match progress(global.num_operations) {
None => Ok(()),
Some(token) => Err(ERR::ErrorTerminated(token, pos).into()),
}
} else {
Ok(())
}
}
}

View File

@ -510,7 +510,7 @@ impl Engine {
let src = global.source_raw().cloned();
let src = src.as_ref().map(|s| s.as_str());
let context = EvalContext::new(self, global, caches, scope, this_ptr);
let (.., ref on_debugger) = **x;
let (.., ref on_debugger) = *x;
let command = on_debugger(context, event, node, src, node.position());

View File

@ -464,7 +464,7 @@ impl Engine {
let t = self.map_type_name(type_name::<ImmutableString>()).into();
ERR::ErrorMismatchOutputType(t, typ.into(), pos)
})?;
((print)(&text).into(), false)
(print(&text).into(), false)
} else {
(Dynamic::UNIT, false)
}
@ -475,7 +475,7 @@ impl Engine {
let t = self.map_type_name(type_name::<ImmutableString>()).into();
ERR::ErrorMismatchOutputType(t, typ.into(), pos)
})?;
((debug)(&text, global.source(), pos).into(), false)
(debug(&text, global.source(), pos).into(), false)
} else {
(Dynamic::UNIT, false)
}

View File

@ -1139,7 +1139,7 @@ fn optimize_expr(expr: &mut Expr, state: &mut OptimizerState, _chaining: bool) {
.and_then(|(f, ctx)| {
let context = ctx.then(|| (state.engine, x.name.as_str(), None, &state.global, *pos).into());
let (first, second) = arg_values.split_first_mut().unwrap();
(f)(context, &mut [ first, &mut second[0] ]).ok()
f(context, &mut [ first, &mut second[0] ]).ok()
}) {
state.set_dirty();
*expr = Expr::from_dynamic(result, *pos);

View File

@ -13,6 +13,7 @@ fn check_struct_sizes() {
feature = "only_i32",
any(feature = "no_float", feature = "f32_float")
));
const WORD_SIZE: usize = size_of::<usize>();
assert_eq!(size_of::<Dynamic>(), if PACKED { 8 } else { 16 });
assert_eq!(size_of::<Option<Dynamic>>(), if PACKED { 8 } else { 16 });
@ -20,10 +21,7 @@ fn check_struct_sizes() {
size_of::<Position>(),
if cfg!(feature = "no_position") { 0 } else { 4 }
);
assert_eq!(
size_of::<tokenizer::Token>(),
if IS_32_BIT { 8 } else { 16 }
);
assert_eq!(size_of::<tokenizer::Token>(), 2 * WORD_SIZE);
assert_eq!(size_of::<ast::Expr>(), if PACKED { 12 } else { 16 });
assert_eq!(size_of::<Option<ast::Expr>>(), if PACKED { 12 } else { 16 });
assert_eq!(size_of::<ast::Stmt>(), if IS_32_BIT { 12 } else { 16 });
@ -34,40 +32,41 @@ fn check_struct_sizes() {
#[cfg(feature = "internals")]
{
assert_eq!(
size_of::<CallableFunction>(),
if IS_32_BIT { 12 } else { 24 }
);
assert_eq!(
size_of::<module::FuncInfo>(),
if IS_32_BIT { 16 } else { 32 }
);
assert_eq!(size_of::<CallableFunction>(), 3 * WORD_SIZE);
assert_eq!(size_of::<module::FuncInfo>(), 4 * WORD_SIZE);
}
// The following only on 64-bit platforms
if !cfg!(target_pointer_width = "64") {
return;
}
#[cfg(target_pointer_width = "64")]
{
assert_eq!(size_of::<Scope>(), 536);
assert_eq!(
size_of::<FnPtr>(),
if cfg!(feature = "no_function") {
72
80 - if cfg!(feature = "no_function") {
WORD_SIZE
} else {
80
0
}
);
assert_eq!(size_of::<LexError>(), 56);
assert_eq!(
size_of::<ParseError>(),
if cfg!(feature = "no_position") { 8 } else { 16 }
16 - if cfg!(feature = "no_position") {
WORD_SIZE
} else {
0
}
);
assert_eq!(size_of::<EvalAltResult>(), 64);
assert_eq!(
size_of::<NativeCallContext>(),
if cfg!(feature = "no_position") {
48
56 - if cfg!(feature = "no_position") {
WORD_SIZE
} else {
56
0
}
);
}
}