From 74bcfff3fb5eaee281796ccb5bc84c6941d44615 Mon Sep 17 00:00:00 2001 From: Jes Cok Date: Thu, 2 Nov 2023 14:53:05 +0800 Subject: [PATCH] cmd/go/internal/modload: don't use strings.TrimPrefix in *MainModuleSet.DirImportPath To avoid calling strings.HasPrefix twice, don't use strings.TrimPrefix. --- src/cmd/go/internal/modload/load.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cmd/go/internal/modload/load.go b/src/cmd/go/internal/modload/load.go index 9b4cb19ebfd..51eb141d4b3 100644 --- a/src/cmd/go/internal/modload/load.go +++ b/src/cmd/go/internal/modload/load.go @@ -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)