Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ public static ReadOnlySpan2D<T> AsSpan2D<T>(this ReadOnlySpan<T> span, int offse
/// <param name="value">The reference to the target item to get the index for.</param>
/// <returns>The index of <paramref name="value"/> within <paramref name="span"/>, or <c>-1</c>.</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static unsafe int IndexOf<T>(this ReadOnlySpan<T> span, in T value)
public static unsafe int IndexOf<T>(this ReadOnlySpan<T> span, ref readonly T value)
{
ref T r0 = ref MemoryMarshal.GetReference(span);
ref T r1 = ref Unsafe.AsRef(in value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,15 @@ public static Span<TTo> Cast<TFrom, TTo>(this Span<TFrom> span)
/// <param name="value">The reference to the target item to get the index for.</param>
/// <returns>The index of <paramref name="value"/> within <paramref name="span"/>, or <c>-1</c>.</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static unsafe int IndexOf<T>(this Span<T> span, ref T value)
public static unsafe int IndexOf<T>(this Span<T> 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);

Expand Down