Repository: PowerShell/PowerShell
File: src/System.Management.Automation/engine/regex.cs (C#)

Code before:
        /// <summary>
        /// Specifies culture-invariant matching.
        /// </summary>
        CultureInvariant = 4
    }

    /// <summary>
    /// Represents a wildcard pattern.
    /// </summary>
    public sealed class WildcardPattern
    {
        // char that escapes special chars
        private const char escapeChar = '`';

        // Threshold for stack allocation.
        // The size is less than MaxShortPath = 260.
        private const int StackAllocThreshold = 256;

        // chars that are considered special in a wildcard pattern
        private const string SpecialChars = "*?[]`";

        // we convert a wildcard pattern to a predicate
        private Predicate<string> _isMatch;

        // cached regex for ToRegex() method
        private Regex _regex;

        // static match-all delegate that is shared by all WildcardPattern instances
        private static readonly Predicate<string> s_matchAll = _ => true;

        // wildcard pattern
        internal string Pattern { get; }

        // Options that control match behavior.
        // Default is WildcardOptions.None.
        internal WildcardOptions Options { get; }

        /// <summary>
        /// Initializes and instance of the WildcardPattern class
        /// for the specified wildcard pattern.
        /// </summary>
        /// <param name="pattern">The wildcard pattern to match.</param>
        /// <returns>The constructed WildcardPattern object.</returns>
        public WildcardPattern(string pattern) : this(pattern, WildcardOptions.None)
        {
        }

        /// <summary>
        /// Initializes an instance of the WildcardPattern class for
        /// the specified wildcard pattern expression, with options
        /// that modify the pattern.

Review comment (performance):
Do we really need the cache? For example `ToWql()` doesn't use cache.
I believe the cache is needed only for multiple retrieves in high performance scenarios, but it is not our case.

Code after:
        /// <summary>
        /// Specifies culture-invariant matching.
        /// </summary>
        CultureInvariant = 4
    }

    /// <summary>
    /// Represents a wildcard pattern.
    /// </summary>
    public sealed class WildcardPattern
    {
        // char that escapes special chars
        private const char escapeChar = '`';

        // Threshold for stack allocation.
        // The size is less than MaxShortPath = 260.
        private const int StackAllocThreshold = 256;

        // chars that are considered special in a wildcard pattern
        private const string SpecialChars = "*?[]`";

        // we convert a wildcard pattern to a predicate
        private Predicate<string> _isMatch;

        // static match-all delegate that is shared by all WildcardPattern instances
        private static readonly Predicate<string> s_matchAll = _ => true;

        // wildcard pattern
        internal string Pattern { get; }

        // Options that control match behavior.
        // Default is WildcardOptions.None.
        internal WildcardOptions Options { get; }

        /// <summary>
        /// Initializes and instance of the WildcardPattern class
        /// for the specified wildcard pattern.
        /// </summary>
        /// <param name="pattern">The wildcard pattern to match.</param>
        /// <returns>The constructed WildcardPattern object.</returns>
        public WildcardPattern(string pattern) : this(pattern, WildcardOptions.None)
        {
        }

        /// <summary>
        /// Initializes an instance of the WildcardPattern class for
        /// the specified wildcard pattern expression, with options
        /// that modify the pattern.
        /// </summary>
        /// <param name="pattern">The wildcard pattern to match.</param>
        /// <param name="options">Wildcard options.</param>