From d42ad790d9ef7052a59eceecc4e55f8f5672fc35 Mon Sep 17 00:00:00 2001 From: qiulaidongfeng <2645477756@qq.com> Date: Tue, 2 Apr 2024 22:10:09 +0800 Subject: [PATCH] n Change-Id: I654e6254bc37403f69e3762886f339537eb4b452 --- src/cmd/api/main_test.go | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/src/cmd/api/main_test.go b/src/cmd/api/main_test.go index dd091d623a7..d104f087cf1 100644 --- a/src/cmd/api/main_test.go +++ b/src/cmd/api/main_test.go @@ -17,6 +17,7 @@ import ( "go/parser" "go/token" "go/types" + "internal/singleflight" "internal/testenv" "io" "log" @@ -385,6 +386,7 @@ func (w *Walker) Features() (fs []string) { var parsedFileCache struct { lock sync.RWMutex m map[string]*ast.File + wg singleflight.Group } func init() { @@ -405,9 +407,10 @@ func (w *Walker) parseFile(dir, file string) (*ast.File, error) { return nil, err } parsedFileCache.lock.Lock() - parsedFileCache.m[filename] = f + if _, ok := parsedFileCache.m[filename]; !ok { + parsedFileCache.m[filename] = f + } parsedFileCache.lock.Unlock() - return f, nil } @@ -473,10 +476,6 @@ type listImports struct { var listCache sync.Map // map[string]listImports, keyed by contextName -var listSem = make(chan semToken, runtime.GOMAXPROCS(0)) - -type semToken struct{} - // loadImports populates w with information about the packages in the standard // library and the packages they themselves import in w's build context. // @@ -501,9 +500,6 @@ func (w *Walker) loadImports() { imports, ok := listCache.Load(name) if !ok { - listSem <- semToken{} - defer func() { <-listSem }() - cmd := exec.Command(goCmd(), "list", "-e", "-deps", "-json", "std") cmd.Env = listEnv(w.context) if w.context.Dir != "" {