]> Cypherpunks repositories - gostls13.git/commitdiff
gofmt: simpler walkDir
authorRuss Cox <rsc@golang.org>
Tue, 15 Mar 2011 18:04:47 +0000 (14:04 -0400)
committerRuss Cox <rsc@golang.org>
Tue, 15 Mar 2011 18:04:47 +0000 (14:04 -0400)
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

index 0262875413291914c47d4e1839c7dd293e02cc4d..a688c8184c43ef289add02c3c14fadd1bec4f8ac 100644 (file)
@@ -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)
+               }
+       }
 }