gopls/internal/hooks: compile URL regexp once
The URL regexp is apparently enormous and we spend 13 CPU-seconds
compiling it in the gopls version of the LSP tests.
Change-Id: Id291ce0f104aa02b5e38aad43fff8647ce1b5b98
Reviewed-on: https://go-review.googlesource.com/c/tools/+/297876
Trust: Heschi Kreinick <heschi@google.com>
Run-TryBot: Heschi Kreinick <heschi@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
diff --git a/gopls/internal/hooks/hooks.go b/gopls/internal/hooks/hooks.go
index 50e8f71..390967d 100644
--- a/gopls/internal/hooks/hooks.go
+++ b/gopls/internal/hooks/hooks.go
@@ -21,16 +21,17 @@
if options.GoDiff {
options.ComputeEdits = ComputeEdits
}
- options.URLRegexp = urlRegexp()
+ options.URLRegexp = relaxedFullWord
options.GofumptFormat = func(ctx context.Context, src []byte) ([]byte, error) {
return format.Source(src, format.Options{})
}
updateAnalyzers(options)
}
-func urlRegexp() *regexp.Regexp {
- // Ensure links are matched as full words, not anywhere.
- re := regexp.MustCompile(`\b(` + xurls.Relaxed().String() + `)\b`)
- re.Longest()
- return re
+var relaxedFullWord *regexp.Regexp
+
+// Ensure links are matched as full words, not anywhere.
+func init() {
+ relaxedFullWord = regexp.MustCompile(`\b(` + xurls.Relaxed().String() + `)\b`)
+ relaxedFullWord.Longest()
}