Use MemoryExtensions.IndexOfAny in PSv2CompletionCompleter` (#18245)

This commit is contained in:
xtqqczze
2022-10-19 14:18:09 -07:00
committed by GitHub
parent 3e15fc5128
commit c1e6b41f98
@@ -691,8 +691,9 @@ namespace System.Management.Automation
/// </remarks>
private static class PSv2CompletionCompleter
{
private const string CharsRequiringQuotedString = "`&@'#{}()$,;|<> \t";
private static readonly Regex s_cmdletTabRegex = new Regex(@"^[\w\*\?]+-[\w\*\?]*");
private static readonly char[] s_charsRequiringQuotedString = "`&@'#{}()$,;|<> \t".ToCharArray();
#region "Handle Command"
@@ -939,7 +940,7 @@ namespace System.Management.Automation
private static string AddQuoteIfNecessary(string completionText, string quote, bool completingAtStartOfLine)
{
if (completionText.IndexOfAny(s_charsRequiringQuotedString) != -1)
if (completionText.AsSpan().IndexOfAny(CharsRequiringQuotedString) >= 0)
{
bool needAmpersand = quote.Length == 0 && completingAtStartOfLine;
string quoteInUse = quote.Length == 0 ? "'" : quote;