Skip to content

Commit 29af775

Browse files
committed
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<Regex>", any abbr gets to pay the price. Boxing it means abbrs without a regex are over 500 bytes smaller.
1 parent 3d1e8a6 commit 29af775

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

src/abbrs.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ pub struct Abbreviation {
4848
/// If unset, the key is to be interpreted literally.
4949
/// Note that the fish interface enforces that regexes match the entire token;
5050
/// we accomplish this by surrounding the regex in ^ and $.
51-
pub regex: Option<Regex>,
51+
pub regex: Option<Box<Regex>>,
5252

5353
/// Replacement string.
5454
pub replacement: WString,

src/builtins/abbr.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ fn abbr_add(opts: &Options, streams: &mut IoStreams) -> Option<c_int> {
302302
}
303303

304304
let key: &wstr;
305-
let regex: Option<Regex>;
305+
let regex: Option<Box<Regex>>;
306306
if let Some(regex_pattern) = &opts.regex_pattern {
307307
// Compile the regex as given; if that succeeds then wrap it in our ^$ so it matches the
308308
// entire token.
@@ -329,9 +329,11 @@ fn abbr_add(opts: &Options, streams: &mut IoStreams) -> Option<c_int> {
329329
return STATUS_INVALID_ARGS;
330330
}
331331
let anchored = regex_make_anchored(regex_pattern);
332-
let re = builder
333-
.build(to_boxed_chars(&anchored))
334-
.expect("Anchored compilation should have succeeded");
332+
let re = Box::new(
333+
builder
334+
.build(to_boxed_chars(&anchored))
335+
.expect("Anchored compilation should have succeeded"),
336+
);
335337

336338
key = regex_pattern;
337339
regex = Some(re);

0 commit comments

Comments
 (0)