mirror of
https://github.com/siyuan-note/siyuan
synced 2026-04-21 13:37:52 +00:00
♻️ kernel/search/find: modernize with wg.Go (#17289)
This commit is contained in:
parent
440f9e29ec
commit
c3808f4e77
1 changed files with 5 additions and 9 deletions
|
|
@ -71,19 +71,15 @@ func FindAllMatches(root string, targets []string) []Match {
|
|||
var collectWg sync.WaitGroup
|
||||
|
||||
var matches []Match
|
||||
collectWg.Add(1)
|
||||
go func() {
|
||||
defer collectWg.Done()
|
||||
collectWg.Go(func() {
|
||||
for m := range results {
|
||||
matches = append(matches, m)
|
||||
}
|
||||
}()
|
||||
})
|
||||
|
||||
numWorkers := runtime.NumCPU()
|
||||
for i := 0; i < numWorkers; i++ {
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
for range numWorkers {
|
||||
wg.Go(func() {
|
||||
for p := range jobs {
|
||||
hits := scanFileForTargets(p, patternIndex, maxLen)
|
||||
if len(hits) > 0 {
|
||||
|
|
@ -92,7 +88,7 @@ func FindAllMatches(root string, targets []string) []Match {
|
|||
}
|
||||
}
|
||||
}
|
||||
}()
|
||||
})
|
||||
}
|
||||
|
||||
_ = filepath.WalkDir(root, func(path string, d os.DirEntry, err error) error {
|
||||
|
|
|
|||
Loading…
Reference in a new issue