From bbe10f4f7745000c121b629ff68e81bba5a497f6 Mon Sep 17 00:00:00 2001 From: Junegunn Choi Date: Tue, 18 Jul 2017 03:10:49 +0900 Subject: Consolidate Result and rank structs By not storing item index twice, we can cut down the size of Result struct and now it makes more sense to store and pass Results by values. Benchmarks show no degradation of performance by additional pointer indirection for looking up index. --- src/matcher.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/matcher.go') diff --git a/src/matcher.go b/src/matcher.go index 57c263ab..c29f2b6d 100644 --- a/src/matcher.go +++ b/src/matcher.go @@ -131,7 +131,7 @@ func (m *Matcher) sliceChunks(chunks []*Chunk) [][]*Chunk { type partialResult struct { index int - matches []*Result + matches []Result } func (m *Matcher) scan(request MatchRequest) (*Merger, bool) { @@ -162,7 +162,7 @@ func (m *Matcher) scan(request MatchRequest) (*Merger, bool) { go func(idx int, slab *util.Slab, chunks []*Chunk) { defer func() { waitGroup.Done() }() count := 0 - allMatches := make([][]*Result, len(chunks)) + allMatches := make([][]Result, len(chunks)) for idx, chunk := range chunks { matches := request.pattern.Match(chunk, slab) allMatches[idx] = matches @@ -172,7 +172,7 @@ func (m *Matcher) scan(request MatchRequest) (*Merger, bool) { } countChan <- len(matches) } - sliceMatches := make([]*Result, 0, count) + sliceMatches := make([]Result, 0, count) for _, matches := range allMatches { sliceMatches = append(sliceMatches, matches...) } @@ -212,7 +212,7 @@ func (m *Matcher) scan(request MatchRequest) (*Merger, bool) { } } - partialResults := make([][]*Result, numSlices) + partialResults := make([][]Result, numSlices) for _ = range slices { partialResult := <-resultChan partialResults[partialResult.index] = partialResult.matches -- cgit v1.2.3