From c67ed09108ff0d302fb1b3190f4c94a191da0059 Mon Sep 17 00:00:00 2001 From: Ben Boyter Date: Thu, 2 May 2024 11:10:49 +1000 Subject: [PATCH] move uloc count after bail out conditions --- processor/workers.go | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/processor/workers.go b/processor/workers.go index e0b1da8b3..93e5c0bdb 100644 --- a/processor/workers.go +++ b/processor/workers.go @@ -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) @@ -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 }