mirror of
https://github.com/typst/typst
synced 2025-05-15 01:25:28 +08:00
Make values smaller
Reduced from 48 bytes to 32 bytes on 64-bit architectures.
This commit is contained in:
parent
d8d60207ef
commit
8ea05739af
@ -229,7 +229,9 @@ impl Debug for TemplateFunc {
|
|||||||
/// A wrapper around a reference-counted executable function.
|
/// A wrapper around a reference-counted executable function.
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct FuncValue {
|
pub struct FuncValue {
|
||||||
name: Option<String>,
|
/// The string is boxed to make the whole struct fit into 24 bytes, so that
|
||||||
|
/// a [`Value`] fits into 32 bytes.
|
||||||
|
name: Option<Box<String>>,
|
||||||
f: Rc<dyn Fn(&mut EvalContext, &mut FuncArgs) -> Value>,
|
f: Rc<dyn Fn(&mut EvalContext, &mut FuncArgs) -> Value>,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -239,12 +241,12 @@ impl FuncValue {
|
|||||||
where
|
where
|
||||||
F: Fn(&mut EvalContext, &mut FuncArgs) -> Value + 'static,
|
F: Fn(&mut EvalContext, &mut FuncArgs) -> Value + 'static,
|
||||||
{
|
{
|
||||||
Self { name, f: Rc::new(f) }
|
Self { name: name.map(Box::new), f: Rc::new(f) }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The name of the function.
|
/// The name of the function.
|
||||||
pub fn name(&self) -> Option<&str> {
|
pub fn name(&self) -> Option<&str> {
|
||||||
self.name.as_deref()
|
self.name.as_ref().map(|s| s.as_str())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user