From 35cee9f5d8cf9cdee2cb346f4a4ca1dd83bd2ca4 Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Tue, 15 Mar 2011 14:04:47 -0400 Subject: [PATCH] gofmt: simpler walkDir Swapping the goroutines lets them reuse the communication completion on v instead of needing a second channel (done). R=gri CC=golang-dev https://golang.org/cl/4287045 --- src/cmd/gofmt/gofmt.go | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/src/cmd/gofmt/gofmt.go b/src/cmd/gofmt/gofmt.go index 0262875413..a688c8184c 100644 --- a/src/cmd/gofmt/gofmt.go +++ b/src/cmd/gofmt/gofmt.go @@ -158,21 +158,16 @@ func (v fileVisitor) VisitFile(path string, f *os.FileInfo) { func walkDir(path string) { - // start an error handler - done := make(chan bool) v := make(fileVisitor) go func() { - for err := range v { - if err != nil { - report(err) - } - } - done <- true + filepath.Walk(path, v, v) + close(v) }() - // walk the tree - filepath.Walk(path, v, v) - close(v) // terminate error handler loop - <-done // wait for all errors to be reported + for err := range v { + if err != nil { + report(err) + } + } } -- 2.50.0