Skip to content

Commit

Permalink
playing around with unique lines of code counts
Browse files Browse the repository at this point in the history
  • Loading branch information
boyter committed Apr 30, 2024
1 parent b4e6e71 commit 4782495
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 12 deletions.
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func main() {
&processor.UlocMode,
"uloc",
false,
"flip into uloc mode and count the number of unique lines of code",
"calculate the number of unique lines of code (ULOC) for the project",
)
flags.BoolVar(
&processor.DisableCheckBinary,
Expand Down
18 changes: 7 additions & 11 deletions processor/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -613,17 +613,13 @@ func Process() {
close(fileListQueue)
}()

if UlocMode {
fileProcessorWorkerUloc(fileListQueue, fileSummaryJobQueue)
} else {
go fileProcessorWorker(fileListQueue, fileSummaryJobQueue)
go fileProcessorWorker(fileListQueue, fileSummaryJobQueue)

result := fileSummarize(fileSummaryJobQueue)
if FileOutput == "" {
fmt.Println(result)
} else {
_ = os.WriteFile(FileOutput, []byte(result), 0644)
fmt.Println("results written to " + FileOutput)
}
result := fileSummarize(fileSummaryJobQueue)
if FileOutput == "" {
fmt.Println(result)
} else {
_ = os.WriteFile(FileOutput, []byte(result), 0644)
fmt.Println("results written to " + FileOutput)
}
}
10 changes: 10 additions & 0 deletions processor/workers.go
Original file line number Diff line number Diff line change
Expand Up @@ -645,6 +645,8 @@ func fileProcessorWorker(input chan *FileJob, output chan *FileJob) {
var fileCount int64
var gcEnabled int64
var wg sync.WaitGroup
var ulocMutex = sync.Mutex{}
uloc := map[string]struct{}{}

for i := 0; i < FileProcessJobWorkers; i++ {
wg.Add(1)
Expand Down Expand Up @@ -680,6 +682,13 @@ func fileProcessorWorker(input chan *FileJob, output chan *FileJob) {
if processFile(job) {
output <- job
}
if UlocMode {
ulocMutex.Lock()
for _, l := range strings.Split(string(content), "\n") {
uloc[l] = struct{}{}
}
ulocMutex.Unlock()
}
} else {
if Verbose {
printWarn(fmt.Sprintf("error reading: %s %s", job.Location, err))
Expand All @@ -694,6 +703,7 @@ func fileProcessorWorker(input chan *FileJob, output chan *FileJob) {
go func() {
wg.Wait()
close(output)
fmt.Println(ulocDisplay(len(uloc)))

if Debug {
printDebug(fmt.Sprintf("milliseconds reading files into memory: %d", makeTimestampMilli()-startTime))
Expand Down

0 comments on commit 4782495

Please sign in to comment.