1
0
mirror of https://github.com/golang/go synced 2024-11-26 16:07:00 -07:00

cmd/go/internal/modload: don't use strings.TrimPrefix in *MainModuleSet.DirImportPath

To avoid calling strings.HasPrefix twice, don't use strings.TrimPrefix.
This commit is contained in:
Jes Cok 2023-11-02 14:53:05 +08:00
parent 6a7ef36466
commit 74bcfff3fb

View File

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