Skip to content

Commit

Permalink
cmd/xurls: use atomic.Uint32
Browse files Browse the repository at this point in the history
  • Loading branch information
mvdan committed May 19, 2023
1 parent 253af42 commit 2648508
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions cmd/xurls/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func scanPath(re *regexp.Regexp, path string) error {
scanner := bufio.NewScanner(in)

// Doesn't need to be part of reporterState as order doesn't matter.
var atomicFixedCount uint32
var fixedCount atomic.Uint32

for scanner.Scan() {
line := scanner.Text() + "\n"
Expand Down Expand Up @@ -177,7 +177,7 @@ func scanPath(re *regexp.Regexp, path string) error {
newLine := line[:pair[0]] + fixed + line[pair[1]:]
offsetWithinLine += len(newLine) - len(line)
line = newLine
atomic.AddUint32(&atomicFixedCount, 1)
fixedCount.Add(1)
}
}
io.WriteString(r, line) // add the fixed line to outBuf
Expand All @@ -192,7 +192,7 @@ func scanPath(re *regexp.Regexp, path string) error {
panic("we aren't using sequencer for any errors")
}
// Note that all goroutines have stopped at this point.
if atomicFixedCount > 0 && path != "-" {
if fixedCount.Load() > 0 && path != "-" {
in.Close()
// Overwrite the file, if we weren't reading stdin. Report its
// path too.
Expand Down

0 comments on commit 2648508

Please sign in to comment.