From 18e5ee2c5ab17a0977507ccb0caecdfc735718f0 Mon Sep 17 00:00:00 2001 From: brian-reichle <18721383+brian-reichle@users.noreply.github.com> Date: Wed, 18 Feb 2026 21:22:45 +1000 Subject: [PATCH] Prefer ContainsAny over IndexOfAny where available. --- .../FrameworkExtensions/SpanExtensions.cs | 11 +++++++++++ src/TypeNameInterpretation/InsFormatter.cs | 4 ++-- 2 files changed, 13 insertions(+), 2 deletions(-) create mode 100644 src/TypeNameInterpretation/FrameworkExtensions/SpanExtensions.cs diff --git a/src/TypeNameInterpretation/FrameworkExtensions/SpanExtensions.cs b/src/TypeNameInterpretation/FrameworkExtensions/SpanExtensions.cs new file mode 100644 index 0000000..7996ec1 --- /dev/null +++ b/src/TypeNameInterpretation/FrameworkExtensions/SpanExtensions.cs @@ -0,0 +1,11 @@ +// Copyright (c) Brian Reichle. All Rights Reserved. Licensed under the MIT License. See LICENSE in the project root for license information. + +#if !NET +namespace System; + +static class SpanExtensions +{ + public static bool ContainsAny(this ReadOnlySpan haystack, ReadOnlySpan needle) + => haystack.IndexOfAny(needle) >= 0; +} +#endif diff --git a/src/TypeNameInterpretation/InsFormatter.cs b/src/TypeNameInterpretation/InsFormatter.cs index 6aa54d6..67d8525 100644 --- a/src/TypeNameInterpretation/InsFormatter.cs +++ b/src/TypeNameInterpretation/InsFormatter.cs @@ -31,7 +31,7 @@ public static string Format(InsAssembly assembly) { ArgumentNullException.ThrowIfNull(assembly); - if (assembly.Qualifications.Length == 0 && assembly.Name.AsSpan().IndexOfAny(Delimiters.All) < 0) + if (assembly.Qualifications.Length == 0 && !assembly.Name.AsSpan().ContainsAny(Delimiters.All)) { return assembly.Name; } @@ -188,7 +188,7 @@ static void WriteWithEscapedDelimiters(StringBuilder builder, string identifier, } static bool RequiresQuoting(string identifier) - => string.IsNullOrEmpty(identifier) || identifier.AsSpan().IndexOfAny(Delimiters.All) >= 0; + => string.IsNullOrEmpty(identifier) || identifier.AsSpan().ContainsAny(Delimiters.All); } sealed class AssemblyLocator : IInsTypeVisitor