ast: Box redirections in ArgumentOrRedirection

Redirections are bigger and less common.

Reduces ast size of __fish_complete_gpg.fish by ~28 KB.
This commit is contained in:
Peter Ammon
2025-05-04 14:46:32 -07:00
parent b98c5ee897
commit fe10f65587

View File

@@ -634,7 +634,7 @@ fn can_be_parsed(pop: &mut Populator<'_>) -> bool {
#[derive(Debug)]
pub enum ArgumentOrRedirection {
Argument(Argument),
Redirection(Redirection),
Redirection(Box<Redirection>), // Boxed because it's bigger
}
impl Default for ArgumentOrRedirection {
@@ -647,7 +647,7 @@ impl Acceptor for ArgumentOrRedirection {
fn accept<'a>(&'a self, visitor: &mut dyn NodeVisitor<'a>) {
match self {
Self::Argument(child) => visitor.visit(child),
Self::Redirection(child) => visitor.visit(child),
Self::Redirection(child) => visitor.visit(&**child),
};
}
}
@@ -2641,7 +2641,7 @@ fn visit_argument_or_redirection(&mut self, node: &mut ArgumentOrRedirection) {
if let Some(arg) = self.try_parse::<Argument>() {
*node = ArgumentOrRedirection::Argument(arg);
} else if let Some(redir) = self.try_parse::<Redirection>() {
*node = ArgumentOrRedirection::Redirection(redir);
*node = ArgumentOrRedirection::Redirection(Box::new(redir));
} else {
internal_error!(
self,