Skip to content

Automatically anchor regexes beginning with .* - #1706

Merged
stephentoub merged 1 commit into
dotnet:masterfrom
stephentoub:starloop
Jan 17, 2020
Merged

Automatically anchor regexes beginning with .*#1706
stephentoub merged 1 commit into
dotnet:masterfrom
stephentoub:starloop

Conversation

@stephentoub

@stephentoubstephentoub commented Jan 14, 2020

Copy link
Copy Markdown
Member

Avoid unnecessary backtracking by adding an implicit ^ when

usingBenchmarkDotNet.Attributes;usingBenchmarkDotNet.Diagnosers;usingBenchmarkDotNet.Running;usingSystem.Text.RegularExpressions;[MemoryDiagnoser]publicclassProgram{staticvoidMain(string[]args)=>BenchmarkSwitcher.FromAssemblies(new[]{typeof(Program).Assembly}).Run(args);privatereadonlyRegex_regex=newRegex(@".*text",RegexOptions.Compiled);[Benchmark]publicboolIsNotMatch()=>_regex.IsMatch("this is a test to see how well this does when trying to match this tex");}
MethodToolchainMeanErrorStdDevRatioGen 0Gen 1Gen 2Allocated
IsNotMatch\master\corerun.exe10.796 us0.0597 us0.0498 us1.00----
IsNotMatch\pr\corerun.exe1.131 us0.0008 us0.0007 us0.10----

Without whitespace: https://github.com/dotnet/runtime/pull/1706/files?w=1

Contributes to #1349
cc: @danmosemsft, @eerhardt, @ViktorHofer, @pgovind

@stephentoub

Copy link
Copy Markdown
MemberAuthor

Thanks for reviewing, @danmosemsft.

@stephentoub
stephentoub merged commit 4c5e56b into dotnet:masterJan 17, 2020
@stephentoub
stephentoub deleted the starloop branch January 17, 2020 02:19
@ghostghost locked as resolved and limited conversation to collaborators Dec 11, 2020
Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

@stephentoub@danmoseley