mirror of
https://github.com/fish-shell/fish-shell.git
synced 2025-01-19 18:13:00 +08:00
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.
This commit is contained in:
parent
3d1e8a6106
commit
29af775390
|
@ -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<Regex>,
|
||||
pub regex: Option<Box<Regex>>,
|
||||
|
||||
/// Replacement string.
|
||||
pub replacement: WString,
|
||||
|
|
|
@ -302,7 +302,7 @@ fn abbr_add(opts: &Options, streams: &mut IoStreams) -> Option<c_int> {
|
|||
}
|
||||
|
||||
let key: &wstr;
|
||||
let regex: Option<Regex>;
|
||||
let regex: Option<Box<Regex>>;
|
||||
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<c_int> {
|
|||
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);
|
||||
|
|
Loading…
Reference in New Issue
Block a user