Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.
/ corefx Public archive

Adding Span IndexOfAny APIs that take 2 and 3 bytes #17357

Merged
merged 6 commits into from
Mar 30, 2017
Merged
Show file tree
Hide file tree
Changes from 5 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
7 changes: 7 additions & 0 deletions src/System.Memory/ref/System.Memory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,13 @@ public static class SpanExtensions
public static int IndexOf<T>(this ReadOnlySpan<T> span, ReadOnlySpan<T> value) where T : struct, IEquatable<T> { throw null; }
public static int IndexOf(this ReadOnlySpan<byte> span, ReadOnlySpan<byte> value) { throw null; }

public static int IndexOfAny(this Span<byte> span, byte value0, byte value1) { throw null; }
public static int IndexOfAny(this Span<byte> span, byte value0, byte value1, byte value2) { throw null; }
public static int IndexOfAny(this Span<byte> span, ReadOnlySpan<byte> values) { throw null; }
public static int IndexOfAny(this ReadOnlySpan<byte> span, byte value0, byte value1) { throw null; }
public static int IndexOfAny(this ReadOnlySpan<byte> span, byte value0, byte value1, byte value2) { throw null; }
public static int IndexOfAny(this ReadOnlySpan<byte> span, ReadOnlySpan<byte> values) { throw null; }

public static bool SequenceEqual<T>(this Span<T> first, ReadOnlySpan<T> second) where T:struct, IEquatable<T> { throw null; }
public static bool SequenceEqual(this Span<byte> first, ReadOnlySpan<byte> second) { throw null; }

Expand Down
73 changes: 73 additions & 0 deletions src/System.Memory/src/System/SpanExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,79 @@ public static int IndexOf(this ReadOnlySpan<byte> span, ReadOnlySpan<byte> value
return SpanHelpers.IndexOf(ref span.DangerousGetPinnableReference(), span.Length, ref value.DangerousGetPinnableReference(), value.Length);
}


/// <summary>
/// Searches for the first index of any of the specified values similar to calling IndexOf several times with the logical OR operator. If not found, returns -1.
/// </summary>
/// <param name="span">The span to search.</param>
/// <param name="value0">One of the values to search for.</param>
/// <param name="value1">One of the values to search for.</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static int IndexOfAny(this Span<byte> span, byte value0, byte value1)
{
return SpanHelpers.IndexOfAny(ref span.DangerousGetPinnableReference(), value0, value1, span.Length);
}

/// <summary>
/// Searches for the first index of any of the specified values similar to calling IndexOf several times with the logical OR operator. If not found, returns -1.
/// </summary>
/// <param name="span">The span to search.</param>
/// <param name="value0">One of the values to search for.</param>
/// <param name="value1">One of the values to search for.</param>
/// <param name="value2">One of the values to search for.</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static int IndexOfAny(this Span<byte> span, byte value0, byte value1, byte value2)
{
return SpanHelpers.IndexOfAny(ref span.DangerousGetPinnableReference(), value0, value1, value2, span.Length);
}

/// <summary>
/// Searches for the first index of any of the specified values similar to calling IndexOf several times with the logical OR operator. If not found, returns -1.
/// </summary>
/// <param name="span">The span to search.</param>
/// <param name="values">The set of values to search for.</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static int IndexOfAny(this Span<byte> span, ReadOnlySpan<byte> values)
{
return SpanHelpers.IndexOfAny(ref span.DangerousGetPinnableReference(), span.Length, ref values.DangerousGetPinnableReference(), values.Length);
}

/// <summary>
/// Searches for the first index of any of the specified values similar to calling IndexOf several times with the logical OR operator. If not found, returns -1.
/// </summary>
/// <param name="span">The span to search.</param>
/// <param name="value0">One of the values to search for.</param>
/// <param name="value1">One of the values to search for.</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static int IndexOfAny(this ReadOnlySpan<byte> span, byte value0, byte value1)
{
return SpanHelpers.IndexOfAny(ref span.DangerousGetPinnableReference(), value0, value1, span.Length);
}

/// <summary>
/// Searches for the first index of any of the specified values similar to calling IndexOf several times with the logical OR operator. If not found, returns -1.
/// </summary>
/// <param name="span">The span to search.</param>
/// <param name="value0">One of the values to search for.</param>
/// <param name="value1">One of the values to search for.</param>
/// <param name="value2">One of the values to search for.</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static int IndexOfAny(this ReadOnlySpan<byte> span, byte value0, byte value1, byte value2)
{
return SpanHelpers.IndexOfAny(ref span.DangerousGetPinnableReference(), value0, value1, value2, span.Length);
}

/// <summary>
/// Searches for the first index of any of the specified values similar to calling IndexOf several times with the logical OR operator. If not found, returns -1.
/// </summary>
/// <param name="span">The span to search.</param>
/// <param name="values">The set of values to search for.</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static int IndexOfAny(this ReadOnlySpan<byte> span, ReadOnlySpan<byte> values)
{
return SpanHelpers.IndexOfAny(ref span.DangerousGetPinnableReference(), span.Length, ref values.DangerousGetPinnableReference(), values.Length);
}

/// <summary>
/// Determines whether two sequences are equal by comparing the elements using IEquatable&lt;T&gt;.Equals(T).
/// </summary>
Expand Down
Loading