Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ x.Options is CSharpCompilationOptions options ?
// a user's partial type. We can now rely on binding rules mapping to these usings and don't need to
// use global-qualified names for the rest of the implementation.
writer.WriteLine($" using System;");
writer.WriteLine($" using System.Buffers;");
writer.WriteLine($" using System.CodeDom.Compiler;");
writer.WriteLine($" using System.Collections;");
writer.WriteLine($" using System.ComponentModel;");
Expand Down Expand Up @@ -240,7 +241,7 @@ x.Options is CSharpCompilationOptions options ?
writer.WriteLine($"{{");
writer.Indent++;
bool sawFirst = false;
foreach (KeyValuePair<string, string[]> helper in requiredHelpers)
foreach (KeyValuePair<string, string[]> helper in requiredHelpers.OrderBy(h => h.Key, StringComparer.Ordinal))
{
if (sawFirst)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Buffers;
using System.Globalization;

namespace System.Text.RegularExpressions
{
internal sealed class CompiledRegexRunner : RegexRunner
{
private readonly ScanDelegate _scanMethod;

private readonly IndexOfAnyValues<char>[]? _indexOfAnyValues;

/// <summary>This field will only be set if the pattern contains backreferences and has RegexOptions.IgnoreCase</summary>
private readonly CultureInfo? _culture;

Expand All @@ -19,9 +23,10 @@ internal sealed class CompiledRegexRunner : RegexRunner

internal delegate void ScanDelegate(RegexRunner runner, ReadOnlySpan<char> text);

public CompiledRegexRunner(ScanDelegate scan, CultureInfo? culture)
public CompiledRegexRunner(ScanDelegate scan, IndexOfAnyValues<char>[]? indexOfAnyValues, CultureInfo? culture)
{
_scanMethod = scan;
_indexOfAnyValues = indexOfAnyValues;
_culture = culture;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Buffers;
using System.Globalization;
using System.Reflection.Emit;

Expand All @@ -9,20 +10,22 @@ namespace System.Text.RegularExpressions
internal sealed class CompiledRegexRunnerFactory : RegexRunnerFactory
{
private readonly DynamicMethod _scanMethod;
private readonly IndexOfAnyValues<char>[]? _indexOfAnyValues;
/// <summary>This field will only be set if the pattern has backreferences and uses RegexOptions.IgnoreCase</summary>
private readonly CultureInfo? _culture;

// Delegate is lazily created to avoid forcing JIT'ing until the regex is actually executed.
private CompiledRegexRunner.ScanDelegate? _scan;

public CompiledRegexRunnerFactory(DynamicMethod scanMethod, CultureInfo? culture)
public CompiledRegexRunnerFactory(DynamicMethod scanMethod, IndexOfAnyValues<char>[]? indexOfAnyValues, CultureInfo? culture)
{
_scanMethod = scanMethod;
_indexOfAnyValues = indexOfAnyValues;
_culture = culture;
}

protected internal override RegexRunner CreateInstance() =>
new CompiledRegexRunner(
_scan ??= _scanMethod.CreateDelegate<CompiledRegexRunner.ScanDelegate>(), _culture);
_scan ??= _scanMethod.CreateDelegate<CompiledRegexRunner.ScanDelegate>(), _indexOfAnyValues, _culture);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System.Collections.Generic;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.Numerics;
using System.Runtime.CompilerServices;
Expand Down Expand Up @@ -840,6 +841,22 @@ public static int GetSetChars(string set, Span<char> chars)
return count;
}

public static bool TryGetAsciiSetChars(string set, [NotNullWhen(true)] out char[]? asciiChars)
{
Span<char> chars = stackalloc char[128];

chars = chars.Slice(0, GetSetChars(set, chars));

if (chars.IsEmpty || !IsAscii(chars))
{
asciiChars = null;
return false;
}

asciiChars = chars.ToArray();
return true;
}

/// <summary>
/// Determines whether two sets may overlap.
/// </summary>
Expand Down
Loading