1
0
mirror of https://github.com/golang/go synced 2024-09-29 00:24:30 -06:00

cmd/go/internal/modload: avoid calling strings.HasPrefix twice in *MainModuleSet.DirImportPath

Since TrimPrefix uses HasPrefix internally.

Change-Id: Ifadb99dd9192578056636adacaccc9d88a1c1f32
GitHub-Last-Rev: 74bcfff3fb
GitHub-Pull-Request: golang/go#63893
Reviewed-on: https://go-review.googlesource.com/c/go/+/539096
Run-TryBot: Jes Cok <xigua67damn@gmail.com>
Auto-Submit: Bryan Mills <bcmills@google.com>
Reviewed-by: Heschi Kreinick <heschi@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Bryan Mills <bcmills@google.com>
This commit is contained in:
Jes Cok 2023-11-06 14:27:32 +00:00 committed by Gopher Robot
parent 374a56ca33
commit ba0dd3b328

View File

@ -777,7 +777,7 @@ func (mms *MainModuleSet) DirImportPath(ctx context.Context, dir string) (path s
longestPrefixVersion = v
suffix := filepath.ToSlash(str.TrimFilePathPrefix(dir, modRoot))
if strings.HasPrefix(suffix, "vendor/") {
longestPrefixPath = strings.TrimPrefix(suffix, "vendor/")
longestPrefixPath = suffix[len("vendor/"):]
continue
}
longestPrefixPath = pathpkg.Join(mms.PathPrefix(v), suffix)