From e3df6e523eab4ecf2dc097f700243187f0cc4104 Mon Sep 17 00:00:00 2001 From: timofey Date: Tue, 1 Aug 2023 20:14:46 +0000 Subject: [PATCH] remove allocations from `_next_composite` --- src/func/instances/stackless.rs | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/src/func/instances/stackless.rs b/src/func/instances/stackless.rs index 5d257fd..280ab07 100644 --- a/src/func/instances/stackless.rs +++ b/src/func/instances/stackless.rs @@ -47,15 +47,30 @@ enum EvalTree<'a> { type Oet<'a> = Option>; +struct Temp; + +impl Atom for Temp { + fn next<'t>(self: Box) -> Oet<'t> + where + Self: 't, + { + unreachable!() + } +} + impl<'a> EvalTree<'a> { - fn _next_composite(self, other: Box) -> Self { - match self { + fn _next_composite(mut self: Box, other: Box) -> Self { + match *self { Self::Atom(f) => match f.next() { - Some(newleft) => Self::Composite(Box::new(newleft), other), + Some(newleft) => { + *self = newleft; + Self::Composite(self, other) + } None => *other, }, Self::Composite(etll, etlr) => { - Self::Composite(etll, Box::new(Self::Composite(etlr, other))) + *self = Self::Composite(etlr, other); + Self::Composite(etll, self) } } }