matchtree: Re-use regexpMatchTree.found
The code is already setup to reuse t.found, it just wasn't. We could make this
code a bit more complicated and re-allocate if cap(found) < len(idxs). But I
think this is unneccessary given we will reuse the slice now.
Change-Id: I47700abf6078c23b8cef6f23f25db01b84a21f26
diff --git a/matchtree.go b/matchtree.go
index b9438ba..165c309 100644
--- a/matchtree.go
+++ b/matchtree.go
@@ -419,14 +419,15 @@
}
idxs := t.regexp.FindAllIndex(cp.data(t.fileName), -1)
- t.found = make([]*candidateMatch, 0, len(idxs))
+ found := t.found[:0]
for _, idx := range idxs {
- t.found = append(t.found, &candidateMatch{
+ found = append(found, &candidateMatch{
byteOffset: uint32(idx[0]),
byteMatchSz: uint32(idx[1] - idx[0]),
fileName: t.fileName,
})
}
+ t.found = found
return len(t.found) > 0, true
}