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

Method Loop

src/matcher.go:81–150  ·  view source on GitHub ↗

Loop puts Matcher in action

()

Source from the content-addressed store, hash-verified

79
80// Loop puts Matcher in action
81func (m *Matcher) Loop() {
82 prevCount := 0
83
84 for {
85 var request MatchRequest
86
87 stop := false
88 m.reqBox.Wait(func(events *util.Events) {
89 for t, val := range *events {
90 if t == reqQuit {
91 stop = true
92 return
93 }
94 switch val := val.(type) {
95 case MatchRequest:
96 request = val
97 default:
98 panic(fmt.Sprintf("Unexpected type: %T", val))
99 }
100 }
101 events.Clear()
102 })
103 if stop {
104 break
105 }
106
107 cacheCleared := false
108 if request.sort != m.sort || request.revision != m.revision {
109 m.sort = request.sort
110 m.mergerCache = make(map[string]MatchResult)
111 if !request.revision.compatible(m.revision) {
112 m.cache.Clear()
113 }
114 m.revision = request.revision
115 cacheCleared = true
116 }
117
118 // Restart search
119 patternString := request.pattern.AsString()
120 var result MatchResult
121 count := CountItems(request.chunks)
122
123 if !cacheCleared {
124 if count == prevCount {
125 // Look up mergerCache
126 if cached, found := m.mergerCache[patternString]; found && cached.final() == request.final {
127 result = cached
128 }
129 } else {
130 // Invalidate mergerCache
131 prevCount = count
132 m.mergerCache = make(map[string]MatchResult)
133 }
134 }
135
136 if result.merger == nil {
137 m.scanMutex.Lock()
138 result = m.scan(request)

Callers 1

RunFunction · 0.95

Calls 9

scanMethod · 0.95
cacheableMethod · 0.95
CountItemsFunction · 0.85
WaitMethod · 0.80
compatibleMethod · 0.80
finalMethod · 0.80
ClearMethod · 0.65
AsStringMethod · 0.45
SetMethod · 0.45

Tested by

no test coverage detected