Tweak Regex compiler's FindFirstChar code gen (#2342)
authorStephen Toub <stoub@microsoft.com>
Thu, 30 Jan 2020 16:08:25 +0000 (11:08 -0500)
committerGitHub <noreply@github.com>
Thu, 30 Jan 2020 16:08:25 +0000 (11:08 -0500)
commit75705f9a304b8cbc7872c02f0dbab68078592bd7
tree2401675a786daeed09d660cf27e54f151fef0d60
parent1c34f4c298631c4c92f0aece0ff97003dc5eb066
Tweak Regex compiler's FindFirstChar code gen (#2342)

* Tweak Regex compiler's FindFirstChar code gen

- If we're able to use IndexOf{Any} and we don't have any information on subsequent characters, we can avoid spitting the code related to looping, avoid unnecessary slicing, etc.
- If the Boyer-Moore prefix contains non-ASCII text, we currently don't use it when compiling FindFirstChar, but we previously made a change to also skip computing other prefix information if we got a Boyer-Moore prefix, which ends up making FindFirstChar terrible when there's Unicode in the prefix string.  This fixes that to still compute the other prefix information in that case.
- We're currently often generating multiple "this.runtextpos = runtextend; return false" blocks.  We can consolidate them.
- Makes a few cleanliness changes to the assembly generator, e.g. ensuring the internal types are sealed, the types are all beforefieldinit as the C# compiler would do, etc.

Also added/tweaked a few tests.

* Address PR feedback
src/libraries/System.Text.RegularExpressions/src/System/Text/RegularExpressions/RegexAssemblyCompiler.cs
src/libraries/System.Text.RegularExpressions/src/System/Text/RegularExpressions/RegexCompiler.cs
src/libraries/System.Text.RegularExpressions/src/System/Text/RegularExpressions/RegexWriter.cs
src/libraries/System.Text.RegularExpressions/tests/MonoRegexTests.cs
src/libraries/System.Text.RegularExpressions/tests/Regex.Match.Tests.cs