MCPcopy
hub / github.com/junegunn/fzf / scan

Method scan

src/matcher.go:157–240  ·  view source on GitHub ↗
(request MatchRequest)

Source from the content-addressed store, hash-verified

155}
156
157func (m *Matcher) scan(request MatchRequest) MatchResult {
158 startedAt := time.Now()
159
160 numChunks := len(request.chunks)
161 if numChunks == 0 {
162 m := EmptyMerger(request.revision)
163 return MatchResult{m, m, false}
164 }
165 pattern := request.pattern
166 passMerger := PassMerger(&request.chunks, m.tac, request.revision, pattern.startIndex)
167 if pattern.IsEmpty() {
168 return MatchResult{passMerger, passMerger, false}
169 }
170
171 minIndex := request.chunks[0].items[0].Index()
172 maxIndex := request.chunks[numChunks-1].lastIndex(minIndex)
173 cancelled := util.NewAtomicBool(false)
174
175 numWorkers := min(m.partitions, numChunks)
176 var nextChunk atomic.Int32
177 resultChan := make(chan partialResult, numWorkers)
178 countChan := make(chan int, numChunks)
179 waitGroup := sync.WaitGroup{}
180
181 for idx := range numWorkers {
182 waitGroup.Add(1)
183 if m.slab[idx] == nil {
184 m.slab[idx] = util.MakeSlab(slab16Size, slab32Size)
185 }
186 go func(idx int, slab *util.Slab) {
187 defer waitGroup.Done()
188 var matches []Result
189 for {
190 ci := int(nextChunk.Add(1)) - 1
191 if ci >= numChunks {
192 break
193 }
194 chunkMatches := request.pattern.Match(request.chunks[ci], slab)
195 matches = append(matches, chunkMatches...)
196 if cancelled.Get() {
197 return
198 }
199 countChan <- len(chunkMatches)
200 }
201 if m.sort && request.pattern.sortable {
202 m.sortBuf[idx] = radixSortResults(matches, m.tac, m.sortBuf[idx])
203 }
204 resultChan <- partialResult{idx, matches}
205 }(idx, m.slab[idx])
206 }
207
208 wait := func() bool {
209 cancelled.Set(true)
210 waitGroup.Wait()
211 return true
212 }
213
214 count := 0

Callers 2

LoopMethod · 0.95
RunFunction · 0.95

Calls 15

GetMethod · 0.95
SetMethod · 0.95
NewAtomicBoolFunction · 0.92
MakeSlabFunction · 0.92
EmptyMergerFunction · 0.85
PassMergerFunction · 0.85
radixSortResultsFunction · 0.85
NewMergerFunction · 0.85
IsEmptyMethod · 0.80
lastIndexMethod · 0.80
MatchMethod · 0.80
WaitMethod · 0.80

Tested by

no test coverage detected