mirror of
https://github.com/golang/go
synced 2024-11-11 18:21:40 -07:00
cmd/go/internal/toolchain: use sync.OnceValue
Rename initPathExts to pathExts, make it return the slice of extensions, and wrap into sync.OnceValue. While at it, return early if PATHEXT is empty. Change-Id: I33508762e87edd226e0a52df4063473c496c0210 Reviewed-on: https://go-review.googlesource.com/c/go/+/611017 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com>
This commit is contained in:
parent
ba2a16cb63
commit
4777fd3d31
@ -14,16 +14,13 @@ import (
|
|||||||
"cmd/go/internal/gover"
|
"cmd/go/internal/gover"
|
||||||
)
|
)
|
||||||
|
|
||||||
// pathExts is a cached PATHEXT list.
|
var pathExts = sync.OnceValue(func() []string {
|
||||||
var pathExts struct {
|
x := os.Getenv(`PATHEXT`)
|
||||||
once sync.Once
|
if x == "" {
|
||||||
list []string
|
return []string{".com", ".exe", ".bat", ".cmd"}
|
||||||
}
|
}
|
||||||
|
|
||||||
func initPathExts() {
|
|
||||||
var exts []string
|
var exts []string
|
||||||
x := os.Getenv(`PATHEXT`)
|
|
||||||
if x != "" {
|
|
||||||
for _, e := range strings.Split(strings.ToLower(x), `;`) {
|
for _, e := range strings.Split(strings.ToLower(x), `;`) {
|
||||||
if e == "" {
|
if e == "" {
|
||||||
continue
|
continue
|
||||||
@ -33,11 +30,8 @@ func initPathExts() {
|
|||||||
}
|
}
|
||||||
exts = append(exts, e)
|
exts = append(exts, e)
|
||||||
}
|
}
|
||||||
} else {
|
return exts
|
||||||
exts = []string{".com", ".exe", ".bat", ".cmd"}
|
})
|
||||||
}
|
|
||||||
pathExts.list = exts
|
|
||||||
}
|
|
||||||
|
|
||||||
// pathDirs returns the directories in the system search path.
|
// pathDirs returns the directories in the system search path.
|
||||||
func pathDirs() []string {
|
func pathDirs() []string {
|
||||||
@ -48,8 +42,7 @@ func pathDirs() []string {
|
|||||||
// described by de and info in directory dir.
|
// described by de and info in directory dir.
|
||||||
// The analysis only uses the name itself; it does not run the program.
|
// The analysis only uses the name itself; it does not run the program.
|
||||||
func pathVersion(dir string, de fs.DirEntry, info fs.FileInfo) (string, bool) {
|
func pathVersion(dir string, de fs.DirEntry, info fs.FileInfo) (string, bool) {
|
||||||
pathExts.once.Do(initPathExts)
|
name, _, ok := cutExt(de.Name(), pathExts())
|
||||||
name, _, ok := cutExt(de.Name(), pathExts.list)
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return "", false
|
return "", false
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user