playing around with unique lines of code counts · boyter/scc@4782495

3 files changed

lines changed

Original file line numberDiff line numberDiff line change

@@ -56,7 +56,7 @@ func main() {

5656

&processor.UlocMode,

5757

"uloc",

5858

false,

59-

"flip into uloc mode and count the number of unique lines of code",

59+

"calculate the number of unique lines of code (ULOC) for the project",

6060

)

6161

flags.BoolVar(

6262

&processor.DisableCheckBinary,

Original file line numberDiff line numberDiff line change

@@ -613,17 +613,13 @@ func Process() {

613613

close(fileListQueue)

614614

}()

615615
616-

if UlocMode {

617-

fileProcessorWorkerUloc(fileListQueue, fileSummaryJobQueue)

618-

} else {

619-

go fileProcessorWorker(fileListQueue, fileSummaryJobQueue)

616+

go fileProcessorWorker(fileListQueue, fileSummaryJobQueue)

620617
621-

result := fileSummarize(fileSummaryJobQueue)

622-

if FileOutput == "" {

623-

fmt.Println(result)

624-

} else {

625-

_ = os.WriteFile(FileOutput, []byte(result), 0644)

626-

fmt.Println("results written to " + FileOutput)

627-

}

618+

result := fileSummarize(fileSummaryJobQueue)

619+

if FileOutput == "" {

620+

fmt.Println(result)

621+

} else {

622+

_ = os.WriteFile(FileOutput, []byte(result), 0644)

623+

fmt.Println("results written to " + FileOutput)

628624

}

629625

}

Original file line numberDiff line numberDiff line change

@@ -645,6 +645,8 @@ func fileProcessorWorker(input chan *FileJob, output chan *FileJob) {

645645

var fileCount int64

646646

var gcEnabled int64

647647

var wg sync.WaitGroup

648+

var ulocMutex = sync.Mutex{}

649+

uloc := map[string]struct{}{}

648650
649651

for i := 0; i < FileProcessJobWorkers; i++ {

650652

wg.Add(1)

@@ -680,6 +682,13 @@ func fileProcessorWorker(input chan *FileJob, output chan *FileJob) {

680682

if processFile(job) {

681683

output <- job

682684

}

685+

if UlocMode {

686+

ulocMutex.Lock()

687+

for _, l := range strings.Split(string(content), "\n") {

688+

uloc[l] = struct{}{}

689+

}

690+

ulocMutex.Unlock()

691+

}

683692

} else {

684693

if Verbose {

685694

printWarn(fmt.Sprintf("error reading: %s %s", job.Location, err))

@@ -694,6 +703,7 @@ func fileProcessorWorker(input chan *FileJob, output chan *FileJob) {

694703

go func() {

695704

wg.Wait()

696705

close(output)

706+

fmt.Println(ulocDisplay(len(uloc)))

697707
698708

if Debug {

699709

printDebug(fmt.Sprintf("milliseconds reading files into memory: %d", makeTimestampMilli()-startTime))