Skip to content

Commit

Permalink
Fix inconsistency in Regex infinite timeout usages (#77560)
Browse files Browse the repository at this point in the history
In the Regex source generator, there is an inconsistency in which "timeout constant" we are comparing against vs. which constant we are setting when the timeout isn't specified.

Fixing it to always use Regex.InfiniteMatchTimeout.
  • Loading branch information
eerhardt authored Oct 31, 2022
1 parent 22ecd7e commit 30d8593
Showing 1 changed file with 2 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ private static void EmitRegexDerivedTypeRunnerFactory(IndentedTextWriter writer,
$"internal static readonly TimeSpan {DefaultTimeoutFieldName} = AppContext.GetData(\"REGEX_DEFAULT_MATCH_TIMEOUT\") is TimeSpan timeout ? timeout : Regex.InfiniteMatchTimeout;",
$"",
$"/// <summary>Whether <see cref=\"{DefaultTimeoutFieldName}\"/> is non-infinite.</summary>",
$"internal static readonly bool {HasDefaultTimeoutFieldName} = {DefaultTimeoutFieldName} != Timeout.InfiniteTimeSpan;",
$"internal static readonly bool {HasDefaultTimeoutFieldName} = {DefaultTimeoutFieldName} != Regex.InfiniteMatchTimeout;",
});
}
}
Expand Down Expand Up @@ -248,7 +248,7 @@ private static void EmitRegexDerivedTypeRunnerFactory(IndentedTextWriter writer,
/// <summary>Gets a C# expression representing the specified timeout value.</summary>
private static string GetTimeoutExpression(int matchTimeout) =>
matchTimeout == Timeout.Infinite ?
"Timeout.InfiniteTimeSpan" :
"Regex.InfiniteMatchTimeout" :
$"TimeSpan.FromMilliseconds({matchTimeout.ToString(CultureInfo.InvariantCulture)})";

/// <summary>Adds the IsWordChar helper to the required helpers collection.</summary>
Expand Down

0 comments on commit 30d8593

Please sign in to comment.