refactor(query): reuse matchAllRegex #18146
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
matchAllRegex is a global variable containing the precompiled regex that
matches ".+".
Prior to this commit, it was used in only one place and we called its
.Copy() method.
According to the docs, .Copy() is no longer needed for safe concurrent
access:
Deprecated: In earlier releases, when using a Regexp in multiple
goroutines, giving each goroutine its own copy helped to avoid lock
contention. As of Go 1.12, using Copy is no longer necessary to avoid
lock contention. Copy may still be appropriate if the reason for its
use is to make two copies with different Longest settings.
Since we require Go 1.13 or later now and we're not calling the
Longest() method, this patch removes the .Copy() call.
Now that we have a reusable matchAllRegex value, this patch then
replaces all instances of regexp.MustCompile(
.+
) with matchAllRegex.This will elminate runtime regex compilations.