// See the LICENSE file in the project root for more information.
using System.Diagnostics;
-#if !NETSTANDARD2_0
+using System.Runtime.CompilerServices;
+
using Internal.Runtime.CompilerServices;
-#endif
namespace System
{
{
public static int IndexOf<T>(ref T searchSpace, int searchSpaceLength, ref T value, int valueLength) where T : IEquatable<T>
{
+ // The optimized implementation should be used for these types
+ Debug.Assert(!RuntimeHelpers.IsBitwiseEquatable<T>() || !(Unsafe.SizeOf<T>() == sizeof(byte) || Unsafe.SizeOf<T>() == sizeof(char)));
+
Debug.Assert(searchSpaceLength >= 0);
Debug.Assert(valueLength >= 0);
// Adapted from IndexOf(...)
public static unsafe bool Contains<T>(ref T searchSpace, T value, int length) where T : IEquatable<T>
{
+ // The optimized implementation should be used for these types
+ Debug.Assert(!RuntimeHelpers.IsBitwiseEquatable<T>() || !(Unsafe.SizeOf<T>() == sizeof(byte) || Unsafe.SizeOf<T>() == sizeof(char)));
+
Debug.Assert(length >= 0);
IntPtr index = (IntPtr)0; // Use IntPtr for arithmetic to avoid unnecessary 64->32->64 truncations
public static unsafe int IndexOf<T>(ref T searchSpace, T value, int length) where T : IEquatable<T>
{
+ // The optimized implementation should be used for these types
+ Debug.Assert(!RuntimeHelpers.IsBitwiseEquatable<T>() || !(Unsafe.SizeOf<T>() == sizeof(byte) || Unsafe.SizeOf<T>() == sizeof(char)));
+
Debug.Assert(length >= 0);
IntPtr index = (IntPtr)0; // Use IntPtr for arithmetic to avoid unnecessary 64->32->64 truncations
public static int IndexOfAny<T>(ref T searchSpace, T value0, T value1, int length) where T : IEquatable<T>
{
+ // The optimized implementation should be used for these types
+ Debug.Assert(!RuntimeHelpers.IsBitwiseEquatable<T>() || !(Unsafe.SizeOf<T>() == sizeof(byte) || Unsafe.SizeOf<T>() == sizeof(char)));
+
Debug.Assert(length >= 0);
T lookUp;
public static int IndexOfAny<T>(ref T searchSpace, T value0, T value1, T value2, int length) where T : IEquatable<T>
{
+ // The optimized implementation should be used for these types
+ Debug.Assert(!RuntimeHelpers.IsBitwiseEquatable<T>() || !(Unsafe.SizeOf<T>() == sizeof(byte) || Unsafe.SizeOf<T>() == sizeof(char)));
+
Debug.Assert(length >= 0);
T lookUp;
public static int IndexOfAny<T>(ref T searchSpace, int searchSpaceLength, ref T value, int valueLength) where T : IEquatable<T>
{
+ // The optimized implementation should be used for these types
+ Debug.Assert(!RuntimeHelpers.IsBitwiseEquatable<T>() || !(Unsafe.SizeOf<T>() == sizeof(byte) || Unsafe.SizeOf<T>() == sizeof(char)));
+
Debug.Assert(searchSpaceLength >= 0);
Debug.Assert(valueLength >= 0);
public static int LastIndexOf<T>(ref T searchSpace, T value, int length) where T : IEquatable<T>
{
+ // The optimized implementation should be used for these types
+ Debug.Assert(!RuntimeHelpers.IsBitwiseEquatable<T>() || !(Unsafe.SizeOf<T>() == sizeof(byte) || Unsafe.SizeOf<T>() == sizeof(char)));
+
Debug.Assert(length >= 0);
if (default(T)! != null || (object)value != null) // TODO-NULLABLE: default(T) == null warning (https://github.com/dotnet/roslyn/issues/34757)
public static int LastIndexOfAny<T>(ref T searchSpace, T value0, T value1, int length) where T : IEquatable<T>
{
+ // The optimized implementation should be used for these types
+ Debug.Assert(!RuntimeHelpers.IsBitwiseEquatable<T>() || !(Unsafe.SizeOf<T>() == sizeof(byte) || Unsafe.SizeOf<T>() == sizeof(char)));
+
Debug.Assert(length >= 0);
T lookUp;
public static int LastIndexOfAny<T>(ref T searchSpace, T value0, T value1, T value2, int length) where T : IEquatable<T>
{
+ // The optimized implementation should be used for these types
+ Debug.Assert(!RuntimeHelpers.IsBitwiseEquatable<T>() || !(Unsafe.SizeOf<T>() == sizeof(byte) || Unsafe.SizeOf<T>() == sizeof(char)));
+
Debug.Assert(length >= 0);
T lookUp;
public static int LastIndexOfAny<T>(ref T searchSpace, int searchSpaceLength, ref T value, int valueLength) where T : IEquatable<T>
{
+ // The optimized implementation should be used for these types
+ Debug.Assert(!RuntimeHelpers.IsBitwiseEquatable<T>() || !(Unsafe.SizeOf<T>() == sizeof(byte) || Unsafe.SizeOf<T>() == sizeof(char)));
+
Debug.Assert(searchSpaceLength >= 0);
Debug.Assert(valueLength >= 0);
public static bool SequenceEqual<T>(ref T first, ref T second, int length) where T : IEquatable<T>
{
+ // The optimized implementation should be used for these types
+ Debug.Assert(!RuntimeHelpers.IsBitwiseEquatable<T>() || !(Unsafe.SizeOf<T>() == sizeof(byte) || Unsafe.SizeOf<T>() == sizeof(char)));
+
Debug.Assert(length >= 0);
if (Unsafe.AreSame(ref first, ref second))
public static int SequenceCompareTo<T>(ref T first, int firstLength, ref T second, int secondLength)
where T : IComparable<T>
{
+ // The optimized implementation should be used for these types
+ Debug.Assert(typeof(T) != typeof(byte) && typeof(T) != typeof(char));
+
Debug.Assert(firstLength >= 0);
Debug.Assert(secondLength >= 0);