@@ -64,7 +64,6 @@ internal abstract class RegexCompiler
64
64
private static readonly MethodInfo s_spanSliceIntIntMethod = typeof ( ReadOnlySpan < char > ) . GetMethod ( "Slice" , new Type [ ] { typeof ( int ) , typeof ( int ) } ) ! ;
65
65
private static readonly MethodInfo s_spanStartsWith = typeof ( MemoryExtensions ) . GetMethod ( "StartsWith" , new Type [ ] { typeof ( ReadOnlySpan < > ) . MakeGenericType ( Type . MakeGenericMethodParameter ( 0 ) ) , typeof ( ReadOnlySpan < > ) . MakeGenericType ( Type . MakeGenericMethodParameter ( 0 ) ) } ) ! . MakeGenericMethod ( typeof ( char ) ) ;
66
66
private static readonly MethodInfo s_stringAsSpanMethod = typeof ( MemoryExtensions ) . GetMethod ( "AsSpan" , new Type [ ] { typeof ( string ) } ) ! ;
67
- private static readonly MethodInfo s_spanLastIndexOfMethod = typeof ( MemoryExtensions ) . GetMethod ( "LastIndexOf" , new Type [ ] { typeof ( ReadOnlySpan < > ) . MakeGenericType ( Type . MakeGenericMethodParameter ( 0 ) ) , typeof ( ReadOnlySpan < > ) . MakeGenericType ( Type . MakeGenericMethodParameter ( 0 ) ) } ) ! . MakeGenericMethod ( typeof ( char ) ) ;
68
67
private static readonly MethodInfo s_stringAsSpanIntIntMethod = typeof ( MemoryExtensions ) . GetMethod ( "AsSpan" , new Type [ ] { typeof ( string ) , typeof ( int ) , typeof ( int ) } ) ! ;
69
68
private static readonly MethodInfo s_stringGetCharsMethod = typeof ( string ) . GetMethod ( "get_Chars" , new Type [ ] { typeof ( int ) } ) ! ;
70
69
private static readonly MethodInfo s_stringIndexOfCharInt = typeof ( string ) . GetMethod ( "IndexOf" , new Type [ ] { typeof ( char ) , typeof ( int ) } ) ! ;
@@ -91,7 +90,6 @@ internal abstract class RegexCompiler
91
90
private LocalBuilder ? _runstackLocal ;
92
91
private LocalBuilder ? _textInfoLocal ; // cached to avoid extraneous TLS hits from CurrentCulture and virtual calls to TextInfo
93
92
private LocalBuilder ? _loopTimeoutCounterLocal ; // timeout counter for setrep and setloop
94
- private LocalBuilder ? _maxBacktrackPositionLocal ;
95
93
96
94
protected RegexOptions _options ; // options
97
95
protected RegexCode ? _code ; // the RegexCode object
@@ -893,8 +891,6 @@ private void GenerateForwardSection()
893
891
Mvfldloc ( s_runtrackposField , _runtrackposLocal ! ) ;
894
892
Mvfldloc ( s_runstackField , _runstackLocal ! ) ;
895
893
Mvfldloc ( s_runstackposField , _runstackposLocal ! ) ;
896
- Ldc ( - 1 ) ;
897
- Stloc ( _maxBacktrackPositionLocal ! ) ;
898
894
899
895
_backpos = - 1 ;
900
896
@@ -1709,7 +1705,7 @@ protected void GenerateFindFirstChar()
1709
1705
// if (!CharInClass(textSpan[i + 2], prefix[2], "...")) goto returnFalse;
1710
1706
// ...
1711
1707
Debug . Assert ( charClassIndex == 0 || charClassIndex == 1 ) ;
1712
- for ( ; charClassIndex < _leadingCharClasses . Length ; charClassIndex ++ )
1708
+ for ( ; charClassIndex < _leadingCharClasses . Length ; charClassIndex ++ )
1713
1709
{
1714
1710
Debug . Assert ( needLoop ) ;
1715
1711
Ldloca ( textSpanLocal ) ;
@@ -3314,7 +3310,6 @@ protected void GenerateGo()
3314
3310
}
3315
3311
_runtextbegLocal = DeclareInt32 ( ) ;
3316
3312
_runtextendLocal = DeclareInt32 ( ) ;
3317
- _maxBacktrackPositionLocal = DeclareInt32 ( ) ;
3318
3313
3319
3314
InitializeCultureForGoIfNecessary ( ) ;
3320
3315
@@ -4263,61 +4258,7 @@ private void GenerateOneCode()
4263
4258
//: break Backward;
4264
4259
{
4265
4260
string str = _strings ! [ Operand ( 0 ) ] ;
4266
- Label multiCode = DefineLabel ( ) ;
4267
- if ( ! IsRightToLeft ( ) )
4268
- {
4269
- // if (runtextend - runtextpos < c)
4270
- Ldloc ( _runtextendLocal ! ) ;
4271
- Ldloc ( _runtextposLocal ! ) ;
4272
- Sub ( ) ;
4273
- Ldc ( str . Length ) ;
4274
- BgeFar ( multiCode ) ;
4275
- // if (!caseInsensitive && _maxBacktrackPosition != -1 && runtextpos > _maxBacktrackPosition)
4276
- if ( ! IsCaseInsensitive ( ) )
4277
- {
4278
- Ldloc ( _maxBacktrackPositionLocal ! ) ;
4279
- Ldc ( - 1 ) ;
4280
- BeqFar ( _backtrack ) ;
4281
- Ldloc ( _runtextposLocal ! ) ;
4282
- Ldloc ( _maxBacktrackPositionLocal ! ) ;
4283
- BleFar ( _backtrack ) ;
4284
- // runtextpos = _maxBacktrackPosition;
4285
- Ldloc ( _maxBacktrackPositionLocal ! ) ;
4286
- Stloc ( _runtextposLocal ! ) ;
4287
- // ReadOnlySpan<char> runtextSpan = runtext.AsSpan(_maxBacktrackPosition, runtextend - _maxBacktractPosition);
4288
- Ldloc ( _runtextLocal ! ) ;
4289
- Ldloc ( _maxBacktrackPositionLocal ! ) ;
4290
- Ldloc ( _runtextendLocal ! ) ;
4291
- Ldloc ( _maxBacktrackPositionLocal ! ) ;
4292
- Sub ( ) ;
4293
- using ( RentedLocalBuilder runtextSpanLocal = RentReadOnlySpanCharLocal ( ) )
4294
- {
4295
- Call ( s_stringAsSpanIntIntMethod ) ;
4296
- Stloc ( runtextSpanLocal ) ;
4297
- using ( RentedLocalBuilder lastIndexOfLocal = RentInt32Local ( ) )
4298
- {
4299
- // int lastIndexOf = runtextSpan.LastIndexOf(str.AsSpan());
4300
- Ldloc ( runtextSpanLocal ) ;
4301
- Ldstr ( str ) ;
4302
- Call ( s_stringAsSpanMethod ) ;
4303
- Call ( s_spanLastIndexOfMethod ) ;
4304
- Stloc ( lastIndexOfLocal ) ;
4305
- // if (lastIndexOf > -1)
4306
- Ldloc ( lastIndexOfLocal ) ;
4307
- Ldc ( - 1 ) ;
4308
- BleFar ( _backtrack ) ;
4309
- // runtextpos = lastIndexOf + _maxBacktrackPosition;
4310
- Ldloc ( lastIndexOfLocal ) ;
4311
- Ldloc ( _maxBacktrackPositionLocal ! ) ;
4312
- Add ( ) ;
4313
- Stloc ( _runtextposLocal ! ) ;
4314
- BrFar ( _backtrack ) ;
4315
- }
4316
- }
4317
- }
4318
- }
4319
4261
4320
- MarkLabel ( multiCode ) ;
4321
4262
Ldc ( str . Length ) ;
4322
4263
Ldloc ( _runtextendLocal ! ) ;
4323
4264
Ldloc ( _runtextposLocal ! ) ;
@@ -4657,9 +4598,6 @@ private void GenerateOneCode()
4657
4598
4658
4599
using RentedLocalBuilder lenLocal = RentInt32Local ( ) ;
4659
4600
using RentedLocalBuilder iLocal = RentInt32Local ( ) ;
4660
- using RentedLocalBuilder tempMaxBacktrackPositionLocal = RentInt32Local ( ) ;
4661
- Ldloc ( _runtextposLocal ! ) ;
4662
- Stloc ( tempMaxBacktrackPositionLocal ) ;
4663
4601
4664
4602
if ( ! IsRightToLeft ( ) )
4665
4603
{
@@ -4909,12 +4847,6 @@ private void GenerateOneCode()
4909
4847
DoPush ( ) ;
4910
4848
4911
4849
Track ( ) ;
4912
- // if (_operator == RegexCode.Notoneloop) maxBacktrackPosition = tempMaxBacktrackPosition
4913
- if ( _regexopcode == RegexCode . Notoneloop )
4914
- {
4915
- Ldloc ( tempMaxBacktrackPositionLocal ) ;
4916
- Stloc ( _maxBacktrackPositionLocal ! ) ;
4917
- }
4918
4850
}
4919
4851
break ;
4920
4852
}
@@ -4938,66 +4870,28 @@ private void GenerateOneCode()
4938
4870
//: if (i > 0)
4939
4871
//: Track(i - 1, pos - 1);
4940
4872
//: Advance(2);
4941
- Label noBacktrackPositionBranch = DefineLabel ( ) ;
4873
+ PopTrack ( ) ;
4874
+ Stloc ( _runtextposLocal ! ) ;
4942
4875
PopTrack ( ) ;
4943
4876
using ( RentedLocalBuilder posLocal = RentInt32Local ( ) )
4944
4877
{
4945
4878
Stloc ( posLocal ) ;
4946
- PopTrack ( ) ;
4947
- using ( RentedLocalBuilder iBacktrackLocal = RentInt32Local ( ) )
4948
- {
4949
- Stloc ( iBacktrackLocal ) ;
4950
- // if (!caseInsensitive && maxBacktrackPosition != -1 && pos > maxBacktrackPosition && runtextpos < pos && _operator == (RegexCode.Notoneloop | RegexCode.Back) && !_rightToLeft)
4951
- if ( ! IsCaseInsensitive ( ) && _regexopcode == ( RegexCode . Notoneloop | RegexCode . Back ) && ! IsRightToLeft ( ) )
4952
- {
4953
- Ldloc ( _maxBacktrackPositionLocal ! ) ;
4954
- Ldc ( - 1 ) ;
4955
- Beq ( noBacktrackPositionBranch ) ;
4956
- Ldloc ( posLocal ) ;
4957
- Ldloc ( _maxBacktrackPositionLocal ! ) ;
4958
- Ble ( noBacktrackPositionBranch ) ;
4959
- Ldloc ( _runtextposLocal ! ) ;
4960
- Ldloc ( posLocal ) ;
4961
- Bge ( noBacktrackPositionBranch ) ;
4962
- /*
4963
- int difference = pos - maxBacktrackPosition;
4964
- pos = runtextpos;
4965
- i -= difference;
4966
- maxBacktrackPosition = -1;
4967
- */
4968
- // int difference = pos - maxBacktrackPosition;
4969
- Ldloc ( iBacktrackLocal ) ;
4970
- Ldloc ( posLocal ) ;
4971
- Ldloc ( _maxBacktrackPositionLocal ! ) ;
4972
- Sub ( ) ;
4973
- Sub ( ) ;
4974
- Stloc ( iBacktrackLocal ) ;
4975
- Ldloc ( _runtextposLocal ! ) ;
4976
- Stloc ( posLocal ) ;
4977
- Ldc ( - 1 ) ;
4978
- Stloc ( _maxBacktrackPositionLocal ! ) ;
4979
- }
4980
-
4981
- MarkLabel ( noBacktrackPositionBranch ) ;
4982
- Ldloc ( posLocal ) ;
4983
- Stloc ( _runtextposLocal ! ) ;
4984
- Ldloc ( iBacktrackLocal ) ;
4985
- Ldc ( 0 ) ;
4986
- BleFar ( AdvanceLabel ( ) ) ;
4987
- ReadyPushTrack ( ) ;
4988
- Ldloc ( iBacktrackLocal ) ;
4989
- }
4990
- Ldc ( 1 ) ;
4991
- Sub ( ) ;
4992
- DoPush ( ) ;
4879
+ Ldloc ( posLocal ) ;
4880
+ Ldc ( 0 ) ;
4881
+ BleFar ( AdvanceLabel ( ) ) ;
4993
4882
ReadyPushTrack ( ) ;
4994
- Ldloc ( _runtextposLocal ! ) ;
4995
- Ldc ( 1 ) ;
4996
- Sub ( IsRightToLeft ( ) ) ;
4997
- DoPush ( ) ;
4998
- Trackagain ( ) ;
4999
- Advance ( ) ;
4883
+ Ldloc ( posLocal ) ;
5000
4884
}
4885
+ Ldc ( 1 ) ;
4886
+ Sub ( ) ;
4887
+ DoPush ( ) ;
4888
+ ReadyPushTrack ( ) ;
4889
+ Ldloc ( _runtextposLocal ! ) ;
4890
+ Ldc ( 1 ) ;
4891
+ Sub ( IsRightToLeft ( ) ) ;
4892
+ DoPush ( ) ;
4893
+ Trackagain ( ) ;
4894
+ Advance ( ) ;
5001
4895
break ;
5002
4896
5003
4897
case RegexCode . Onelazy :
0 commit comments