diff --git a/src/CommunityToolkit.HighPerformance/Enumerables/SpanTokenizer{T}.cs b/src/CommunityToolkit.HighPerformance/Enumerables/SpanTokenizer{T}.cs index df06445ca..d2d7c33a6 100644 --- a/src/CommunityToolkit.HighPerformance/Enumerables/SpanTokenizer{T}.cs +++ b/src/CommunityToolkit.HighPerformance/Enumerables/SpanTokenizer{T}.cs @@ -73,7 +73,10 @@ public bool MoveNext() { this.start = newEnd; - int index = this.span.Slice(newEnd).IndexOf(this.separator); + // Here we're inside the 'CommunityToolkit.HighPerformance.Enumerables' namespace, so the + // 'MemoryExtensions' type from the .NET Community Toolkit would be bound instead. Because + // want the one from the BCL (to search by value), we can use its fully qualified name. + int index = System.MemoryExtensions.IndexOf(this.span.Slice(newEnd), this.separator); // Extract the current subsequence if (index >= 0) diff --git a/src/CommunityToolkit.HighPerformance/Extensions/ReadOnlySpanExtensions.cs b/src/CommunityToolkit.HighPerformance/Extensions/ReadOnlySpanExtensions.cs index dfae52a13..e7e64c788 100644 --- a/src/CommunityToolkit.HighPerformance/Extensions/ReadOnlySpanExtensions.cs +++ b/src/CommunityToolkit.HighPerformance/Extensions/ReadOnlySpanExtensions.cs @@ -210,7 +210,7 @@ public static ReadOnlySpan2D AsSpan2D(this ReadOnlySpan span, int offse /// The reference to the target item to get the index for. /// The index of within , or -1. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static unsafe int IndexOf(this ReadOnlySpan span, in T value) + public static unsafe int IndexOf(this ReadOnlySpan span, ref readonly T value) { ref T r0 = ref MemoryMarshal.GetReference(span); ref T r1 = ref Unsafe.AsRef(in value); diff --git a/src/CommunityToolkit.HighPerformance/Extensions/SpanExtensions.cs b/src/CommunityToolkit.HighPerformance/Extensions/SpanExtensions.cs index 7fb71727a..21f0725e7 100644 --- a/src/CommunityToolkit.HighPerformance/Extensions/SpanExtensions.cs +++ b/src/CommunityToolkit.HighPerformance/Extensions/SpanExtensions.cs @@ -148,10 +148,15 @@ public static Span Cast(this Span span) /// The reference to the target item to get the index for. /// The index of within , or -1. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static unsafe int IndexOf(this Span span, ref T value) + public static unsafe int IndexOf(this Span span, ref readonly T value) { ref T r0 = ref MemoryMarshal.GetReference(span); - IntPtr byteOffset = Unsafe.ByteOffset(ref r0, ref value); + IntPtr byteOffset = +#if NET8_0_OR_GREATER + Unsafe.ByteOffset(ref r0, in value); +#else + Unsafe.ByteOffset(ref r0, ref Unsafe.AsRef(in value)); +#endif nint elementOffset = byteOffset / (nint)(uint)sizeof(T);