From 29af775390c486b83e7b231e041c2a71d9814625 Mon Sep 17 00:00:00 2001 From: Fabian Boehm Date: Wed, 28 Feb 2024 18:46:01 +0100 Subject: [PATCH] abbr: Box the regex The regex struct is pretty large at 560 bytes, with the entire Abbreviation being 664 bytes. If it's an "Option", any abbr gets to pay the price. Boxing it means abbrs without a regex are over 500 bytes smaller. --- src/abbrs.rs | 2 +- src/builtins/abbr.rs | 10 ++++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/abbrs.rs b/src/abbrs.rs index 08477c0ab..beae2de24 100644 --- a/src/abbrs.rs +++ b/src/abbrs.rs @@ -48,7 +48,7 @@ pub struct Abbreviation { /// If unset, the key is to be interpreted literally. /// Note that the fish interface enforces that regexes match the entire token; /// we accomplish this by surrounding the regex in ^ and $. - pub regex: Option, + pub regex: Option>, /// Replacement string. pub replacement: WString, diff --git a/src/builtins/abbr.rs b/src/builtins/abbr.rs index 2fdf86c1d..0915c7125 100644 --- a/src/builtins/abbr.rs +++ b/src/builtins/abbr.rs @@ -302,7 +302,7 @@ fn abbr_add(opts: &Options, streams: &mut IoStreams) -> Option { } let key: &wstr; - let regex: Option; + let regex: Option>; if let Some(regex_pattern) = &opts.regex_pattern { // Compile the regex as given; if that succeeds then wrap it in our ^$ so it matches the // entire token. @@ -329,9 +329,11 @@ fn abbr_add(opts: &Options, streams: &mut IoStreams) -> Option { return STATUS_INVALID_ARGS; } let anchored = regex_make_anchored(regex_pattern); - let re = builder - .build(to_boxed_chars(&anchored)) - .expect("Anchored compilation should have succeeded"); + let re = Box::new( + builder + .build(to_boxed_chars(&anchored)) + .expect("Anchored compilation should have succeeded"), + ); key = regex_pattern; regex = Some(re);