Skip to content

Commit

Permalink
Keep totals as pointer
Browse files Browse the repository at this point in the history
  • Loading branch information
timdp committed Apr 24, 2018
1 parent 917cb86 commit 79a02a8
Showing 1 changed file with 5 additions and 10 deletions.
15 changes: 5 additions & 10 deletions cmd/lwc/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,26 +239,21 @@ func processFiles(config *Config, processors []Processor) {
numCounts := len(processors)

// If more than one file given, also calculate totals
var totals []uint64
var totals *[]uint64
if len(config.files) > 1 {
totals = make([]uint64, numCounts)
} else {
totals = nil
totalsRaw := make([]uint64, numCounts)
totals = &totalsRaw
}

// Process files sequentially
for _, name := range config.files {
file := openFile(name)
var totalsPtr *[]uint64
if totals != nil {
totalsPtr = &totals
}
processFile(file, name, processors, totalsPtr, config.interval)
processFile(file, name, processors, totals, config.interval)
}

// If we were keeping totals, print them now
if totals != nil {
printCounts(&totals, "total\n", false)
printCounts(totals, "total\n", false)
}
}

Expand Down

0 comments on commit 79a02a8

Please sign in to comment.