Skip to content

Use static Regex.IsMatch in ValueMatchFilter to take advantage of caching #4055

Description

@stevenaw

The static Regex functions internally cache parsed regex instances based on the provided pattern on .NET 5+. ValueMatchFilter can be used to filter tests based on a regex and will apply the same regex to all potential candidates to see if it matches. This means that on a large test suite there could be measurable savings by using an overload which caches the regex.

Something like this:
https://github.com/nunit/nunit/blob/master/src%2FNUnitFramework%2Fframework%2FInternal%2FFilters%2FValueMatchFilter.cs#L43

-return input != null && new Regex(ExpectedValue).IsMatch(input);
+return input != null && Regex.IsMatch(input, ExpectedValue);

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions