Skip to content

Commit 655836e

Browse files
authored
Fix Regex source generator multithreading issue (#118086)
1 parent 82d6d46 commit 655836e

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/libraries/System.Text.RegularExpressions/gen/RegexGenerator.Emitter.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -403,13 +403,15 @@ private static string EmitSearchValuesOrLiteral(ReadOnlySpan<char> chars, Dictio
403403
// - There are only 4 or 5 characters in the needle and they're all ASCII.
404404

405405
return chars.Length > 5 || RegexCharClass.IsAscii(chars)
406-
? EmitSearchValues(chars.ToArray(), requiredHelpers)
406+
? EmitSearchValues(chars, requiredHelpers)
407407
: Literal(chars.ToString());
408408
}
409409

410410
/// <summary>Adds a SearchValues instance declaration to the required helpers collection.</summary>
411-
private static string EmitSearchValues(char[] chars, Dictionary<string, string[]> requiredHelpers, string? fieldName = null)
411+
private static string EmitSearchValues(ReadOnlySpan<char> charsSpan, Dictionary<string, string[]> requiredHelpers, string? fieldName = null)
412412
{
413+
char[] chars = charsSpan.ToArray();
414+
413415
Array.Sort(chars);
414416

415417
if (fieldName is null)

0 commit comments

Comments
 (0)