Skip to content

Commit e1b0705

Browse files
Copilotjeffkl
andcommitted
Replace Regex with ReadOnlySpan char check in HasNonstandardCharacters
Co-authored-by: jeffkl <[email protected]>
1 parent a9de1db commit e1b0705

1 file changed

Lines changed: 9 additions & 4 deletions

File tree

src/NuGet.Clients/NuGet.VisualStudio.Common/Telemetry/PackageSourceTelemetry.cs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
using System.Collections.Generic;
99
using System.Globalization;
1010
using System.Linq;
11-
using System.Text.RegularExpressions;
11+
1212
using System.Threading;
1313
using System.Threading.Tasks;
1414
using NuGet.Common;
@@ -30,8 +30,6 @@ public sealed class PackageSourceTelemetry : IDisposable
3030

3131
internal const string EventName = "PackageSourceDiagnostics";
3232

33-
private static readonly Regex s_nonstandardIdCharRegex = new Regex(@"[^A-Za-z0-9.\-]", RegexOptions.Compiled);
34-
3533
public enum TelemetryAction
3634
{
3735
Unknown = 0,
@@ -216,7 +214,14 @@ internal static void AddNupkgCopiedData(ProtocolDiagnosticNupkgCopiedEvent ncEve
216214

217215
private static bool HasNonstandardCharacters(string packageId)
218216
{
219-
return s_nonstandardIdCharRegex.IsMatch(packageId);
217+
foreach (char c in packageId.AsSpan())
218+
{
219+
if (!((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || (c >= '0' && c <= '9') || c == '.' || c == '-'))
220+
{
221+
return true;
222+
}
223+
}
224+
return false;
220225
}
221226

222227
public void Dispose()

0 commit comments

Comments
 (0)