You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Today we only support conversion of loops to atomic loops for single-character loops (e.g. a* or [abc]*). This PR augments the logic to support arbitrary loops, enabling many more loops to become atomic.
if((existingChild.KindisRegexNodeKind.Alternate or RegexNodeKind.BackreferenceConditional or RegexNodeKind.ExpressionConditional or RegexNodeKind.Loop or RegexNodeKind.Lazyloop)&&
// If the node can be changed to atomic based on what comes after it, do so.
1877
1928
switch(node.Kind)
1878
1929
{
1879
-
caseRegexNodeKind.Oneloop or RegexNodeKind.Notoneloop or RegexNodeKind.SetloopwhenCanBeMadeAtomic(node,subsequent,iterateNullableSubsequent:true,allowLazy:false):
1930
+
caseRegexNodeKind.Oneloop or RegexNodeKind.Notoneloop or RegexNodeKind.Setloopor RegexNodeKind.LoopwhenCanBeMadeAtomic(node,subsequent,iterateNullableSubsequent:true,allowLazy:false):
1880
1931
// The greedy loop doesn't overlap with what comes after it, which means giving anything it matches back will not
1881
1932
// help the overall match to succeed, which means it can simply become atomic to match as much as possible. The call
1882
1933
// to CanBeMadeAtomic passes iterateNullableSubsequent=true because, in a pattern like a*b*c*, when analyzing a*, we
caseRegexNodeKind.Onelazy or RegexNodeKind.Notonelazy or RegexNodeKind.SetlazywhenCanBeMadeAtomic(node,subsequent,iterateNullableSubsequent:false,allowLazy:true):
1939
+
caseRegexNodeKind.Onelazy or RegexNodeKind.Notonelazy or RegexNodeKind.Setlazyor RegexNodeKind.LazyloopwhenCanBeMadeAtomic(node,subsequent,iterateNullableSubsequent:false,allowLazy:true):
1889
1940
// The lazy loop doesn't overlap with what comes after it, which means it needs to match as much as its allowed
1890
1941
// to match in order for there to be a possibility that what comes next matches (if it doesn't match as much
1891
1942
// as it's allowed and there was still more it could match, then what comes next is guaranteed to not match,
caseRegexNodeKind.NonBoundarywhennode.M>0&&(loopStartingSetisRegexCharClass.NotWordClass or RegexCharClass.NotDigitClass)&&(loopEndingSetisRegexCharClass.NotWordClass or RegexCharClass.NotDigitClass):
2286
+
caseRegexNodeKind.ECMABoundarywhennode.M>0&&(loopStartingSetisRegexCharClass.ECMAWordClass or RegexCharClass.ECMADigitClass)&&(loopEndingSetisRegexCharClass.ECMAWordClass or RegexCharClass.ECMADigitClass):
2287
+
caseRegexNodeKind.NonECMABoundarywhennode.M>0&&(loopStartingSetisRegexCharClass.NotECMAWordClass or RegexCharClass.NotDigitClass)&&(loopEndingSetisRegexCharClass.NotECMAWordClass or RegexCharClass.NotDigitClass):
2288
+
// The loop can be made atomic based on this subsequent node, but we'll need to evaluate the next one as well.
0 commit comments