From: penglei Date: Mon, 9 May 2022 08:55:41 +0000 (+0000) Subject: cmd/go/internal/mvs: Delete redundant searching for maximum version when building... X-Git-Tag: go1.19beta1~255 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=e755a5649aac75f43283a5ec160445b4478c8182;p=gostls13.git cmd/go/internal/mvs: Delete redundant searching for maximum version when building minimal requirement list mvs.Req performs an unnecessary search for the maximum version when building minimal requirement list. Someone may be confused when reading this piece of code. The comment of the BuildList function also states that the build list contains the maximum version of each module. We just need to create a maximum version cache that maps from path to version, in the beginning of the Req function body. Change-Id: I4b353e167f2dcc96bc13cc2e1c602bce47c72bc9 GitHub-Last-Rev: fce11d3c728450f71cb0b6e5478792f0133b8cfc GitHub-Pull-Request: golang/go#50345 Reviewed-on: https://go-review.googlesource.com/c/go/+/374277 Auto-Submit: Bryan Mills Run-TryBot: Bryan Mills Reviewed-by: Bryan Mills TryBot-Result: Gopher Robot Reviewed-by: Heschi Kreinick --- diff --git a/src/cmd/go/internal/mvs/mvs.go b/src/cmd/go/internal/mvs/mvs.go index d25d447b0e..a1b51557a3 100644 --- a/src/cmd/go/internal/mvs/mvs.go +++ b/src/cmd/go/internal/mvs/mvs.go @@ -194,6 +194,11 @@ func Req(mainModule module.Version, base []string, reqs Reqs) ([]module.Version, // that list came from a previous operation that paged // in all the requirements, so there's no I/O to overlap now. + max := map[string]string{} + for _, m := range list { + max[m.Path] = m.Version + } + // Compute postorder, cache requirements. var postorder []module.Version reqCache := map[module.Version][]module.Version{} @@ -236,14 +241,6 @@ func Req(mainModule module.Version, base []string, reqs Reqs) ([]module.Version, } return nil } - max := map[string]string{} - for _, m := range list { - if v, ok := max[m.Path]; ok { - max[m.Path] = reqs.Max(m.Version, v) - } else { - max[m.Path] = m.Version - } - } // First walk the base modules that must be listed. var min []module.Version haveBase := map[string]bool{}