Skip to content

Commit

Permalink
move uloc count after bail out conditions
Browse files Browse the repository at this point in the history
  • Loading branch information
boyter committed May 2, 2024
1 parent f06af57 commit c67ed09
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions processor/workers.go
Original file line number Diff line number Diff line change
Expand Up @@ -757,20 +757,6 @@ func processFile(job *FileJob) bool {

CountStats(job)

if UlocMode {
ulocMutex.Lock()
for _, l := range strings.Split(string(job.Content), "\n") {
ulocGlobalCount[l] = struct{}{}

_, ok := ulocLanguageCount[job.Language]
if !ok {
ulocLanguageCount[job.Language] = map[string]struct{}{}
}
ulocLanguageCount[job.Language][l] = struct{}{}
}
ulocMutex.Unlock()
}

if Duplicates {
duplicates.mux.Lock()
jobHash := job.Hash.Sum(nil)
Expand Down Expand Up @@ -819,6 +805,22 @@ func processFile(job *FileJob) bool {
return false
}

// This needs to be at the end so we can ensure duplicate detection et.al run first
// avoiding inflating the counts
if UlocMode {
ulocMutex.Lock()
for _, l := range strings.Split(string(job.Content), "\n") {
ulocGlobalCount[l] = struct{}{}

_, ok := ulocLanguageCount[job.Language]
if !ok {
ulocLanguageCount[job.Language] = map[string]struct{}{}
}
ulocLanguageCount[job.Language][l] = struct{}{}
}
ulocMutex.Unlock()
}

return true
}

Expand Down

0 comments on commit c67ed09

Please sign in to comment.