remove allocations from _next_composite

This commit is contained in:
AF 2023-08-01 20:14:46 +00:00
parent 0748b30593
commit e3df6e523e

View File

@ -47,15 +47,30 @@ enum EvalTree<'a> {
type Oet<'a> = Option<EvalTree<'a>>; type Oet<'a> = Option<EvalTree<'a>>;
struct Temp;
impl Atom for Temp {
fn next<'t>(self: Box<Self>) -> Oet<'t>
where
Self: 't,
{
unreachable!()
}
}
impl<'a> EvalTree<'a> { impl<'a> EvalTree<'a> {
fn _next_composite(self, other: Box<Self>) -> Self { fn _next_composite(mut self: Box<Self>, other: Box<Self>) -> Self {
match self { match *self {
Self::Atom(f) => match f.next() { Self::Atom(f) => match f.next() {
Some(newleft) => Self::Composite(Box::new(newleft), other), Some(newleft) => {
*self = newleft;
Self::Composite(self, other)
}
None => *other, None => *other,
}, },
Self::Composite(etll, etlr) => { Self::Composite(etll, etlr) => {
Self::Composite(etll, Box::new(Self::Composite(etlr, other))) *self = Self::Composite(etlr, other);
Self::Composite(etll, self)
} }
} }
} }