未验证 提交 ad3847ca 编写于 作者: S Stephen Toub 提交者: GitHub

Change regex source generator to emit returns rather than jumps to NoMatch (#65599)

上级 26b91db7
......@@ -1096,7 +1096,6 @@ protected void EmitTryMatchAtCurrentPosition()
LocalBuilder pos = DeclareInt32();
LocalBuilder slice = DeclareReadOnlySpanChar();
LocalBuilder end = DeclareInt32();
Label stopSuccessLabel = DefineLabel();
Label doneLabel = DefineLabel();
Label originalDoneLabel = doneLabel;
if (_hasTimeout)
......@@ -1105,7 +1104,7 @@ protected void EmitTryMatchAtCurrentPosition()
}
// CultureInfo culture = CultureInfo.CurrentCulture; // only if the whole expression or any subportion is ignoring case, and we're not using invariant
InitializeCultureForGoIfNecessary();
InitializeCultureForTryMatchAtCurrentPositionIfNecessary();
// ReadOnlySpan<char> inputSpan = input;
// int end = base.runtextend;
......@@ -1143,11 +1142,10 @@ protected void EmitTryMatchAtCurrentPosition()
// Emit the code for all nodes in the tree.
EmitNode(node);
// Success:
// pos += sliceStaticPos;
// base.runtextpos = pos;
// Capture(0, originalpos, pos);
MarkLabel(stopSuccessLabel);
// return true;
Ldthis();
Ldloc(pos);
if (sliceStaticPos > 0)
......@@ -1163,10 +1161,17 @@ protected void EmitTryMatchAtCurrentPosition()
Ldloc(originalPos);
Ldloc(pos);
Call(s_captureMethod);
// return true;
Ldc(1);
Ret();
// NOTE: The following is a difference from the source generator. The source generator emits:
// UncaptureUntil(0);
// return false;
// at every location where the all-up match is known to fail. In contrast, the compiler currently
// emits this uncapture/return code in one place and jumps to it upon match failure. The difference
// stems primarily from the return-at-each-location pattern resulting in cleaner / easier to read
// source code, which is not an issue for RegexCompiler emitting IL instead of C#.
// If the graph contained captures, undo any remaining to handle failed matches.
if (expressionHasCaptures)
{
......@@ -4011,7 +4016,7 @@ protected void EmitScan(DynamicMethod tryFindNextStartingPositionMethod, Dynamic
Ret();
}
private void InitializeCultureForGoIfNecessary()
private void InitializeCultureForTryMatchAtCurrentPositionIfNecessary()
{
_textInfo = null;
if ((_options & RegexOptions.CultureInvariant) == 0)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册