Minor RegexCompiler codegen tweak for text[pos++]
authorStephen Toub <stoub@microsoft.com>
Fri, 20 Dec 2019 15:25:55 +0000 (10:25 -0500)
committerStephen Toub <stoub@microsoft.com>
Thu, 9 Jan 2020 03:50:08 +0000 (22:50 -0500)
The JIT generates slightly better code for:
```C#
text[pos] = ....;
pos++;
```
instead of:
```C#
text[pos++] = ...;
```
so use the IL equivalent of the former.

src/libraries/System.Text.RegularExpressions/src/System/Text/RegularExpressions/RegexCompiler.cs

index 331df61..f18ea32 100644 (file)
@@ -444,11 +444,11 @@ namespace System.Text.RegularExpressions
         {
             Ldloc(_runtextLocal!);
             Ldloc(_runtextposLocal!);
-            Dup();
+            Callvirt(s_stringGetCharsMethod);
+            Ldloc(_runtextposLocal!);
             Ldc(1);
             Add();
             Stloc(_runtextposLocal!);
-            Callvirt(s_stringGetCharsMethod);
         }
 
         /// <summary>Loads the char to the left of the current position.</summary>
@@ -539,11 +539,11 @@ namespace System.Text.RegularExpressions
         {
             Ldloc(_runtrackLocal!);
             Ldloc(_runtrackposLocal!);
-            Dup();
+            LdelemI4();
+            Ldloc(_runtrackposLocal!);
             Ldc(1);
             Add();
             Stloc(_runtrackposLocal!);
-            LdelemI4();
         }
 
         /// <summary>Retrieves the top entry on the tracking stack without popping.</summary>
@@ -598,11 +598,11 @@ namespace System.Text.RegularExpressions
         {
             Ldloc(_runstackLocal!);
             Ldloc(_runstackposLocal!);
-            Dup();
+            LdelemI4();
+            Ldloc(_runstackposLocal!);
             Ldc(1);
             Add();
             Stloc(_runstackposLocal!);
-            LdelemI4();
         }
 
         /// <summary>Pops 1 element off the grouping stack and discards it.</summary>