Skip to content

Commit 7e74bb1

Browse files
authored
Reduce allocations in LicenseExpressionTokenizer.HasValidCharacters by caching Regex instance (#7237)
1 parent 31e377a commit 7e74bb1

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

src/NuGet.Core/NuGet.Packaging/Licenses/LicenseExpressionTokenizer.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ namespace NuGet.Packaging.Licenses
1010
{
1111
internal class LicenseExpressionTokenizer
1212
{
13+
private static readonly Regex ValidCharactersRegex = new Regex("^[a-zA-Z0-9\\.\\-\\s\\+\\(\\)]+$", RegexOptions.CultureInvariant);
1314
private readonly string _value;
1415

1516
/// <summary>
@@ -34,8 +35,7 @@ internal LicenseExpressionTokenizer(string value)
3435
/// <returns>Whether the value has valid characters.</returns>
3536
internal bool HasValidCharacters()
3637
{
37-
var regex = new Regex("^[a-zA-Z0-9\\.\\-\\s\\+\\(\\)]+$", RegexOptions.CultureInvariant);
38-
return regex.IsMatch(_value);
38+
return ValidCharactersRegex.IsMatch(_value);
3939
}
4040

4141
/// <summary>

0 commit comments

Comments
 (0)