From 8ea05739afdbe84fc50fe97d780cc6096d8df03d Mon Sep 17 00:00:00 2001 From: Laurenz Date: Mon, 28 Jun 2021 21:57:18 +0200 Subject: [PATCH] Make values smaller Reduced from 48 bytes to 32 bytes on 64-bit architectures. --- src/eval/value.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/eval/value.rs b/src/eval/value.rs index 28c7d5889..0da2a5be0 100644 --- a/src/eval/value.rs +++ b/src/eval/value.rs @@ -229,7 +229,9 @@ impl Debug for TemplateFunc { /// A wrapper around a reference-counted executable function. #[derive(Clone)] pub struct FuncValue { - name: Option, + /// The string is boxed to make the whole struct fit into 24 bytes, so that + /// a [`Value`] fits into 32 bytes. + name: Option>, f: Rc Value>, } @@ -239,12 +241,12 @@ impl FuncValue { where 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. pub fn name(&self) -> Option<&str> { - self.name.as_deref() + self.name.as_ref().map(|s| s.as_str()) } }