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>
This commit is contained in:
Heschi Kreinick 2021-03-02 12:47:31 -05:00
parent 94327d32cf
commit 303d8bbb5c
1 changed files with 7 additions and 6 deletions

View File

@ -21,16 +21,17 @@ func Options(options *source.Options) {
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()
}