summaryrefslogtreecommitdiff
path: root/combinator.go
diff options
context:
space:
mode:
authorAdam Scarr <adam@vektah.net>2017-08-13 20:25:41 +1000
committerAdam Scarr <adam@vektah.net>2017-08-13 20:25:41 +1000
commit51ad26c781c149c08017ffee2bb4906c9bb39282 (patch)
treeb01070af9c72e8c08e85e55e67a10ea716d80752 /combinator.go
parenta733d0ae1391dc8642d21f8784696e95047b7923 (diff)
Optimize allocs in many
Diffstat (limited to 'combinator.go')
-rw-r--r--combinator.go9
1 files 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)