From 51ad26c781c149c08017ffee2bb4906c9bb39282 Mon Sep 17 00:00:00 2001 From: Adam Scarr Date: Sun, 13 Aug 2017 20:25:41 +1000 Subject: [PATCH] Optimize allocs in many --- combinator.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/combinator.go b/combinator.go index 7bcb907..ca62f30 100644 --- a/combinator.go +++ b/combinator.go @@ -108,19 +108,20 @@ func manyImpl(min int, op Parserish, sep ...Parserish) Parser { } return func(ps *State, node *Result) { - var result Result + node.Child = make([]Result, 0, 5) startpos := ps.Pos for { - opParser(ps, &result) + node.Child = append(node.Child, Result{}) + opParser(ps, &node.Child[len(node.Child)-1]) if ps.Errored() { - if len(node.Child) < min || ps.Cut > ps.Pos { + if len(node.Child)-1 < min || ps.Cut > ps.Pos { ps.Pos = startpos return } ps.Recover() + node.Child = node.Child[0 : len(node.Child)-1] return } - node.Child = append(node.Child, result) if sepParser != nil { sepParser(ps, TrashResult)