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 @@ -4288,7 +4288,7 @@ internal bool Equals(MdUtf8String s)
}
else
{
return SpanHelpers.SequenceEqual<byte>(ref *s.m_pStringHeap, ref *m_pStringHeap, m_StringHeapByteLength);
return SpanHelpers.SequenceEqual(ref *s.m_pStringHeap, ref *m_pStringHeap, (uint)m_StringHeapByteLength);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@
using System.Threading.Tasks;
using System.Threading.Tasks.Sources;

#if !NETSTANDARD2_0
using Internal.Runtime.CompilerServices;
#endif

namespace System.Runtime.CompilerServices
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@
using System.Threading.Tasks;
using System.Threading.Tasks.Sources;

#if !NETSTANDARD2_0
using Internal.Runtime.CompilerServices;
#endif

namespace System.Runtime.CompilerServices
{
Expand Down
40 changes: 38 additions & 2 deletions src/libraries/System.Private.CoreLib/src/System/SpanHelpers.T.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,19 @@
// 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
{
internal static partial class SpanHelpers // .T
{
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);

Expand Down Expand Up @@ -49,6 +52,9 @@ public static int IndexOf<T>(ref T searchSpace, int searchSpaceLength, ref T val
// 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
Expand Down Expand Up @@ -119,6 +125,9 @@ public static unsafe bool Contains<T>(ref T searchSpace, T value, int length) wh

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
Expand Down Expand Up @@ -206,6 +215,9 @@ public static unsafe int IndexOf<T>(ref T searchSpace, T value, int length) wher

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;
Expand Down Expand Up @@ -310,6 +322,9 @@ public static int IndexOfAny<T>(ref T searchSpace, T value0, T value1, int lengt

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;
Expand Down Expand Up @@ -413,6 +428,9 @@ public static int IndexOfAny<T>(ref T searchSpace, T value0, T value1, T value2,

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);

Expand Down Expand Up @@ -472,6 +490,9 @@ public static int LastIndexOf<T>(ref T searchSpace, int searchSpaceLength, ref T

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)
Expand Down Expand Up @@ -553,6 +574,9 @@ public static int LastIndexOf<T>(ref T searchSpace, T value, int length) where T

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;
Expand Down Expand Up @@ -656,6 +680,9 @@ public static int LastIndexOfAny<T>(ref T searchSpace, T value0, T value1, int l

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;
Expand Down Expand Up @@ -759,6 +786,9 @@ public static int LastIndexOfAny<T>(ref T searchSpace, T value0, T value1, T val

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);

Expand All @@ -777,6 +807,9 @@ public static int LastIndexOfAny<T>(ref T searchSpace, int searchSpaceLength, re

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))
Expand Down Expand Up @@ -869,6 +902,9 @@ public static bool SequenceEqual<T>(ref T first, ref T second, int length) where
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);

Expand Down