Box Term in Expression to save memory

Expression: 152 to 64
Statement: 216 to 128
This commit is contained in:
Tad Hardesty 2020-11-22 20:51:40 -08:00
parent a28255e972
commit e1ff16ef78
3 changed files with 5 additions and 9 deletions

View file

@ -336,7 +336,7 @@ pub enum Expression {
/// The unary operations applied to this value, in reverse order.
unary: Vec<UnaryOp>,
/// The term of the expression.
term: Spanned<Term>,
term: Box<Spanned<Term>>,
/// The follow operations applied to this value.
follow: Vec<Spanned<Follow>>,
},
@ -486,7 +486,7 @@ impl From<Term> for Expression {
term => Expression::Base {
unary: vec![],
follow: vec![],
term: Spanned::new(Default::default(), term),
term: Box::new(Spanned::new(Default::default(), term)),
},
}
}

View file

@ -760,12 +760,8 @@ impl<'a> ConstantFolder<'a> {
if args.len() != 1 {
return Err(self.error(format!("malformed defined() call, must have 1 argument and instead has {}", args.len())));
}
match args[0] {
Expression::Base {
ref unary,
term: Spanned { elem: Term::Ident(ref ident), .. },
ref follow
} if unary.is_empty() && follow.is_empty() => {
match args[0].as_term() {
Some(Term::Ident(ref ident)) => {
Constant::Int(if defines.contains_key(ident) { 1 } else { 0 })
},
_ => return Err(self.error("malformed defined() call, argument given isn't an Ident.")),

View file

@ -1879,7 +1879,7 @@ impl<'ctx, 'an, 'inp> Parser<'ctx, 'an, 'inp> {
success(Expression::Base {
unary: unary_ops,
term,
term: Box::new(term),
follow,
})
}