aboutsummaryrefslogtreecommitdiff
path: root/src/go
diff options
context:
space:
mode:
authorRuss Cox <rsc@golang.org>2020-11-04 18:20:17 -0500
committerRuss Cox <rsc@golang.org>2020-12-02 16:33:57 +0000
commitc32140fa94cfc51a2152855825f57e27ae3ba133 (patch)
treeb9777c7aff45d975f55b3987dfa440580bbb8f58 /src/go
parent0433845ad18a355413033bb3495ba3195f4c69ec (diff)
downloadgo-c32140fa94cfc51a2152855825f57e27ae3ba133.tar.gz
go-c32140fa94cfc51a2152855825f57e27ae3ba133.zip
all: update to use filepath.WalkDir instead of filepath.Walk
Now that filepath.WalkDir is available, it is more efficient and should be used in place of filepath.Walk. Update the tree to reflect best practices. As usual, the code compiled with Go 1.4 during bootstrap is excluded. (In this CL, that's only cmd/dist.) For #42027. Change-Id: Ib0f7b1e43e50b789052f9835a63ced701d8c411c Reviewed-on: https://go-review.googlesource.com/c/go/+/267719 Trust: Russ Cox <rsc@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Rob Pike <r@golang.org>
Diffstat (limited to 'src/go')
-rw-r--r--src/go/build/deps_test.go6
-rw-r--r--src/go/doc/headscan.go4
2 files changed, 5 insertions, 5 deletions
diff --git a/src/go/build/deps_test.go b/src/go/build/deps_test.go
index bf1367355d..e9ed26aa5f 100644
--- a/src/go/build/deps_test.go
+++ b/src/go/build/deps_test.go
@@ -510,8 +510,8 @@ func listStdPkgs(goroot string) ([]string, error) {
var pkgs []string
src := filepath.Join(goroot, "src") + string(filepath.Separator)
- walkFn := func(path string, fi fs.FileInfo, err error) error {
- if err != nil || !fi.IsDir() || path == src {
+ walkFn := func(path string, d fs.DirEntry, err error) error {
+ if err != nil || !d.IsDir() || path == src {
return nil
}
@@ -528,7 +528,7 @@ func listStdPkgs(goroot string) ([]string, error) {
pkgs = append(pkgs, strings.TrimPrefix(name, "vendor/"))
return nil
}
- if err := filepath.Walk(src, walkFn); err != nil {
+ if err := filepath.WalkDir(src, walkFn); err != nil {
return nil, err
}
return pkgs, nil
diff --git a/src/go/doc/headscan.go b/src/go/doc/headscan.go
index 8ea462366e..fe26a0ea84 100644
--- a/src/go/doc/headscan.go
+++ b/src/go/doc/headscan.go
@@ -69,8 +69,8 @@ func main() {
flag.Parse()
fset := token.NewFileSet()
nheadings := 0
- err := filepath.Walk(*root, func(path string, fi fs.FileInfo, err error) error {
- if !fi.IsDir() {
+ err := filepath.WalkDir(*root, func(path string, info fs.DirEntry, err error) error {
+ if !info.IsDir() {
return nil
}
pkgs, err := parser.ParseDir(fset, path, isGoFile, parser.ParseComments)