Skip to content

Commit b7f61ca

Browse files
authored
Use MemoryExtensions.IndexOfAny in WildcardPattern (PowerShell#18242)
1 parent 028eeb0 commit b7f61ca

File tree

1 file changed

+5
-5
lines changed
  • src/System.Management.Automation/engine

1 file changed

+5
-5
lines changed

src/System.Management.Automation/engine/regex.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,12 @@ public sealed class WildcardPattern
5757
// The size is less than MaxShortPath = 260.
5858
private const int StackAllocThreshold = 256;
5959

60+
// chars that are considered special in a wildcard pattern
61+
private const string SpecialChars = "*?[]`";
62+
6063
// we convert a wildcard pattern to a predicate
6164
private Predicate<string> _isMatch;
6265

63-
// chars that are considered special in a wildcard pattern
64-
private static readonly char[] s_specialChars = new[] { '*', '?', '[', ']', '`' };
65-
6666
// static match-all delegate that is shared by all WildcardPattern instances
6767
private static readonly Predicate<string> s_matchAll = _ => true;
6868

@@ -173,8 +173,8 @@ StringComparison GetStringComparison()
173173
return;
174174
}
175175

176-
int index = Pattern.IndexOfAny(s_specialChars);
177-
if (index == -1)
176+
int index = Pattern.AsSpan().IndexOfAny(SpecialChars);
177+
if (index < 0)
178178
{
179179
// No special characters present in the pattern, so we can just do a string comparison.
180180
_isMatch = str => string.Equals(str, Pattern, GetStringComparison());

0 commit comments

Comments
 (0)