diff --git a/src/coreclr/System.Private.CoreLib/src/System/Collections/Generic/EqualityComparer.CoreCLR.cs b/src/coreclr/System.Private.CoreLib/src/System/Collections/Generic/EqualityComparer.CoreCLR.cs index 9d35ae81313b6e..03b7ab1011cfe8 100644 --- a/src/coreclr/System.Private.CoreLib/src/System/Collections/Generic/EqualityComparer.CoreCLR.cs +++ b/src/coreclr/System.Private.CoreLib/src/System/Collections/Generic/EqualityComparer.CoreCLR.cs @@ -14,7 +14,7 @@ public abstract partial class EqualityComparer : IEqualityComparer, IEquality public static EqualityComparer Default { [Intrinsic] get; } = (EqualityComparer)ComparerHelpers.CreateDefaultEqualityComparer(typeof(T)); } - public sealed partial class GenericEqualityComparer : EqualityComparer where T : IEquatable + public sealed partial class GenericEqualityComparer : EqualityComparer where T : IEquatable? { internal override int IndexOf(T[] array, T value, int startIndex, int count) { @@ -30,7 +30,7 @@ internal override int IndexOf(T[] array, T value, int startIndex, int count) { for (int i = startIndex; i < endIndex; i++) { - if (array[i] != null && array[i].Equals(value)) return i; + if (array[i] != null && array[i]!.Equals(value)) return i; } } return -1; @@ -50,7 +50,7 @@ internal override int LastIndexOf(T[] array, T value, int startIndex, int count) { for (int i = startIndex; i >= endIndex; i--) { - if (array[i] != null && array[i].Equals(value)) return i; + if (array[i] != null && array[i]!.Equals(value)) return i; } } return -1; diff --git a/src/libraries/System.Memory/ref/System.Memory.cs b/src/libraries/System.Memory/ref/System.Memory.cs index 86eb011bf1a20a..467ea9b3ec4b88 100644 --- a/src/libraries/System.Memory/ref/System.Memory.cs +++ b/src/libraries/System.Memory/ref/System.Memory.cs @@ -42,7 +42,7 @@ public void Clear() { } public static partial class BuffersExtensions { public static void CopyTo(this in System.Buffers.ReadOnlySequence source, System.Span destination) { } - public static System.SequencePosition? PositionOf(this in System.Buffers.ReadOnlySequence source, T value) where T : System.IEquatable { throw null; } + public static System.SequencePosition? PositionOf(this in System.Buffers.ReadOnlySequence source, T value) where T : System.IEquatable? { throw null; } public static T[] ToArray(this in System.Buffers.ReadOnlySequence sequence) { throw null; } public static void Write(this System.Buffers.IBufferWriter writer, System.ReadOnlySpan value) { } } @@ -230,66 +230,66 @@ public static partial class MemoryExtensions public static int CommonPrefixLength(this System.ReadOnlySpan span, System.ReadOnlySpan other, System.Collections.Generic.IEqualityComparer? comparer) { throw null; } public static int CompareTo(this System.ReadOnlySpan span, System.ReadOnlySpan other, System.StringComparison comparisonType) { throw null; } public static bool Contains(this System.ReadOnlySpan span, System.ReadOnlySpan value, System.StringComparison comparisonType) { throw null; } - public static bool Contains(this System.ReadOnlySpan span, T value) where T : System.IEquatable { throw null; } - public static bool Contains(this System.Span span, T value) where T : System.IEquatable { throw null; } + public static bool Contains(this System.ReadOnlySpan span, T value) where T : System.IEquatable? { throw null; } + public static bool Contains(this System.Span span, T value) where T : System.IEquatable? { throw null; } public static void CopyTo(this T[]? source, System.Memory destination) { } public static void CopyTo(this T[]? source, System.Span destination) { } public static bool EndsWith(this System.ReadOnlySpan span, System.ReadOnlySpan value, System.StringComparison comparisonType) { throw null; } - public static bool EndsWith(this System.ReadOnlySpan span, System.ReadOnlySpan value) where T : System.IEquatable { throw null; } - public static bool EndsWith(this System.Span span, System.ReadOnlySpan value) where T : System.IEquatable { throw null; } + public static bool EndsWith(this System.ReadOnlySpan span, System.ReadOnlySpan value) where T : System.IEquatable? { throw null; } + public static bool EndsWith(this System.Span span, System.ReadOnlySpan value) where T : System.IEquatable? { throw null; } public static System.Text.SpanLineEnumerator EnumerateLines(this System.ReadOnlySpan span) { throw null; } public static System.Text.SpanLineEnumerator EnumerateLines(this System.Span span) { throw null; } public static System.Text.SpanRuneEnumerator EnumerateRunes(this System.ReadOnlySpan span) { throw null; } public static System.Text.SpanRuneEnumerator EnumerateRunes(this System.Span span) { throw null; } public static bool Equals(this System.ReadOnlySpan span, System.ReadOnlySpan other, System.StringComparison comparisonType) { throw null; } public static int IndexOf(this System.ReadOnlySpan span, System.ReadOnlySpan value, System.StringComparison comparisonType) { throw null; } - public static int IndexOfAny(this System.ReadOnlySpan span, System.ReadOnlySpan values) where T : System.IEquatable { throw null; } - public static int IndexOfAny(this System.ReadOnlySpan span, T value0, T value1) where T : System.IEquatable { throw null; } - public static int IndexOfAny(this System.ReadOnlySpan span, T value0, T value1, T value2) where T : System.IEquatable { throw null; } - public static int IndexOfAny(this System.Span span, System.ReadOnlySpan values) where T : System.IEquatable { throw null; } - public static int IndexOfAny(this System.Span span, T value0, T value1) where T : System.IEquatable { throw null; } - public static int IndexOfAny(this System.Span span, T value0, T value1, T value2) where T : System.IEquatable { throw null; } - public static int IndexOfAnyExcept(this System.Span span, T value) where T : System.IEquatable { throw null; } - public static int IndexOfAnyExcept(this System.Span span, T value0, T value1) where T : System.IEquatable { throw null; } - public static int IndexOfAnyExcept(this System.Span span, T value0, T value1, T value2) where T : System.IEquatable { throw null; } - public static int IndexOfAnyExcept(this System.Span span, System.ReadOnlySpan values) where T : System.IEquatable { throw null; } - public static int IndexOfAnyExcept(this System.ReadOnlySpan span, T value) where T : System.IEquatable { throw null; } - public static int IndexOfAnyExcept(this System.ReadOnlySpan span, T value0, T value1) where T : System.IEquatable { throw null; } - public static int IndexOfAnyExcept(this System.ReadOnlySpan span, T value0, T value1, T value2) where T : System.IEquatable { throw null; } - public static int IndexOfAnyExcept(this System.ReadOnlySpan span, System.ReadOnlySpan values) where T : System.IEquatable { throw null; } - public static int IndexOf(this System.ReadOnlySpan span, System.ReadOnlySpan value) where T : System.IEquatable { throw null; } - public static int IndexOf(this System.ReadOnlySpan span, T value) where T : System.IEquatable { throw null; } - public static int IndexOf(this System.Span span, System.ReadOnlySpan value) where T : System.IEquatable { throw null; } - public static int IndexOf(this System.Span span, T value) where T : System.IEquatable { throw null; } + public static int IndexOfAny(this System.ReadOnlySpan span, System.ReadOnlySpan values) where T : System.IEquatable? { throw null; } + public static int IndexOfAny(this System.ReadOnlySpan span, T value0, T value1) where T : System.IEquatable? { throw null; } + public static int IndexOfAny(this System.ReadOnlySpan span, T value0, T value1, T value2) where T : System.IEquatable? { throw null; } + public static int IndexOfAny(this System.Span span, System.ReadOnlySpan values) where T : System.IEquatable? { throw null; } + public static int IndexOfAny(this System.Span span, T value0, T value1) where T : System.IEquatable? { throw null; } + public static int IndexOfAny(this System.Span span, T value0, T value1, T value2) where T : System.IEquatable? { throw null; } + public static int IndexOfAnyExcept(this System.Span span, T value) where T : System.IEquatable? { throw null; } + public static int IndexOfAnyExcept(this System.Span span, T value0, T value1) where T : System.IEquatable? { throw null; } + public static int IndexOfAnyExcept(this System.Span span, T value0, T value1, T value2) where T : System.IEquatable? { throw null; } + public static int IndexOfAnyExcept(this System.Span span, System.ReadOnlySpan values) where T : System.IEquatable? { throw null; } + public static int IndexOfAnyExcept(this System.ReadOnlySpan span, T value) where T : System.IEquatable? { throw null; } + public static int IndexOfAnyExcept(this System.ReadOnlySpan span, T value0, T value1) where T : System.IEquatable? { throw null; } + public static int IndexOfAnyExcept(this System.ReadOnlySpan span, T value0, T value1, T value2) where T : System.IEquatable? { throw null; } + public static int IndexOfAnyExcept(this System.ReadOnlySpan span, System.ReadOnlySpan values) where T : System.IEquatable? { throw null; } + public static int IndexOf(this System.ReadOnlySpan span, System.ReadOnlySpan value) where T : System.IEquatable? { throw null; } + public static int IndexOf(this System.ReadOnlySpan span, T value) where T : System.IEquatable? { throw null; } + public static int IndexOf(this System.Span span, System.ReadOnlySpan value) where T : System.IEquatable? { throw null; } + public static int IndexOf(this System.Span span, T value) where T : System.IEquatable? { throw null; } public static bool IsWhiteSpace(this System.ReadOnlySpan span) { throw null; } public static int LastIndexOf(this System.ReadOnlySpan span, System.ReadOnlySpan value, System.StringComparison comparisonType) { throw null; } - public static int LastIndexOfAny(this System.ReadOnlySpan span, System.ReadOnlySpan values) where T : System.IEquatable { throw null; } - public static int LastIndexOfAny(this System.ReadOnlySpan span, T value0, T value1) where T : System.IEquatable { throw null; } - public static int LastIndexOfAny(this System.ReadOnlySpan span, T value0, T value1, T value2) where T : System.IEquatable { throw null; } - public static int LastIndexOfAny(this System.Span span, System.ReadOnlySpan values) where T : System.IEquatable { throw null; } - public static int LastIndexOfAny(this System.Span span, T value0, T value1) where T : System.IEquatable { throw null; } - public static int LastIndexOfAny(this System.Span span, T value0, T value1, T value2) where T : System.IEquatable { throw null; } - public static int LastIndexOfAnyExcept(this System.Span span, T value) where T : System.IEquatable { throw null; } - public static int LastIndexOfAnyExcept(this System.Span span, T value0, T value1) where T : System.IEquatable { throw null; } - public static int LastIndexOfAnyExcept(this System.Span span, T value0, T value1, T value2) where T : System.IEquatable { throw null; } - public static int LastIndexOfAnyExcept(this System.Span span, System.ReadOnlySpan values) where T : System.IEquatable { throw null; } - public static int LastIndexOfAnyExcept(this System.ReadOnlySpan span, T value) where T : System.IEquatable { throw null; } - public static int LastIndexOfAnyExcept(this System.ReadOnlySpan span, T value0, T value1) where T : System.IEquatable { throw null; } - public static int LastIndexOfAnyExcept(this System.ReadOnlySpan span, T value0, T value1, T value2) where T : System.IEquatable { throw null; } - public static int LastIndexOfAnyExcept(this System.ReadOnlySpan span, System.ReadOnlySpan values) where T : System.IEquatable { throw null; } - public static int LastIndexOf(this System.ReadOnlySpan span, System.ReadOnlySpan value) where T : System.IEquatable { throw null; } - public static int LastIndexOf(this System.ReadOnlySpan span, T value) where T : System.IEquatable { throw null; } - public static int LastIndexOf(this System.Span span, System.ReadOnlySpan value) where T : System.IEquatable { throw null; } - public static int LastIndexOf(this System.Span span, T value) where T : System.IEquatable { throw null; } + public static int LastIndexOfAny(this System.ReadOnlySpan span, System.ReadOnlySpan values) where T : System.IEquatable? { throw null; } + public static int LastIndexOfAny(this System.ReadOnlySpan span, T value0, T value1) where T : System.IEquatable? { throw null; } + public static int LastIndexOfAny(this System.ReadOnlySpan span, T value0, T value1, T value2) where T : System.IEquatable? { throw null; } + public static int LastIndexOfAny(this System.Span span, System.ReadOnlySpan values) where T : System.IEquatable? { throw null; } + public static int LastIndexOfAny(this System.Span span, T value0, T value1) where T : System.IEquatable? { throw null; } + public static int LastIndexOfAny(this System.Span span, T value0, T value1, T value2) where T : System.IEquatable? { throw null; } + public static int LastIndexOfAnyExcept(this System.Span span, T value) where T : System.IEquatable? { throw null; } + public static int LastIndexOfAnyExcept(this System.Span span, T value0, T value1) where T : System.IEquatable? { throw null; } + public static int LastIndexOfAnyExcept(this System.Span span, T value0, T value1, T value2) where T : System.IEquatable? { throw null; } + public static int LastIndexOfAnyExcept(this System.Span span, System.ReadOnlySpan values) where T : System.IEquatable? { throw null; } + public static int LastIndexOfAnyExcept(this System.ReadOnlySpan span, T value) where T : System.IEquatable? { throw null; } + public static int LastIndexOfAnyExcept(this System.ReadOnlySpan span, T value0, T value1) where T : System.IEquatable? { throw null; } + public static int LastIndexOfAnyExcept(this System.ReadOnlySpan span, T value0, T value1, T value2) where T : System.IEquatable? { throw null; } + public static int LastIndexOfAnyExcept(this System.ReadOnlySpan span, System.ReadOnlySpan values) where T : System.IEquatable? { throw null; } + public static int LastIndexOf(this System.ReadOnlySpan span, System.ReadOnlySpan value) where T : System.IEquatable? { throw null; } + public static int LastIndexOf(this System.ReadOnlySpan span, T value) where T : System.IEquatable? { throw null; } + public static int LastIndexOf(this System.Span span, System.ReadOnlySpan value) where T : System.IEquatable { throw null; } + public static int LastIndexOf(this System.Span span, T value) where T : System.IEquatable? { throw null; } public static bool Overlaps(this System.ReadOnlySpan span, System.ReadOnlySpan other) { throw null; } public static bool Overlaps(this System.ReadOnlySpan span, System.ReadOnlySpan other, out int elementOffset) { throw null; } public static bool Overlaps(this System.Span span, System.ReadOnlySpan other) { throw null; } public static bool Overlaps(this System.Span span, System.ReadOnlySpan other, out int elementOffset) { throw null; } public static void Reverse(this System.Span span) { } - public static int SequenceCompareTo(this System.ReadOnlySpan span, System.ReadOnlySpan other) where T : System.IComparable { throw null; } - public static int SequenceCompareTo(this System.Span span, System.ReadOnlySpan other) where T : System.IComparable { throw null; } - public static bool SequenceEqual(this System.ReadOnlySpan span, System.ReadOnlySpan other) where T : System.IEquatable { throw null; } - public static bool SequenceEqual(this System.Span span, System.ReadOnlySpan other) where T : System.IEquatable { throw null; } + public static int SequenceCompareTo(this System.ReadOnlySpan span, System.ReadOnlySpan other) where T : System.IComparable? { throw null; } + public static int SequenceCompareTo(this System.Span span, System.ReadOnlySpan other) where T : System.IComparable? { throw null; } + public static bool SequenceEqual(this System.ReadOnlySpan span, System.ReadOnlySpan other) where T : System.IEquatable? { throw null; } + public static bool SequenceEqual(this System.Span span, System.ReadOnlySpan other) where T : System.IEquatable? { throw null; } public static bool SequenceEqual(this System.ReadOnlySpan span, System.ReadOnlySpan other, System.Collections.Generic.IEqualityComparer? comparer = null) { throw null; } public static bool SequenceEqual(this System.Span span, System.ReadOnlySpan other, System.Collections.Generic.IEqualityComparer? comparer = null) { throw null; } public static void Sort(this System.Span span) { } @@ -299,8 +299,8 @@ public static void Sort(this System.Span keys, System.Span(this System.Span span, TComparer comparer) where TComparer : System.Collections.Generic.IComparer? { } public static void Sort(this System.Span keys, System.Span items, TComparer comparer) where TComparer : System.Collections.Generic.IComparer? { } public static bool StartsWith(this System.ReadOnlySpan span, System.ReadOnlySpan value, System.StringComparison comparisonType) { throw null; } - public static bool StartsWith(this System.ReadOnlySpan span, System.ReadOnlySpan value) where T : System.IEquatable { throw null; } - public static bool StartsWith(this System.Span span, System.ReadOnlySpan value) where T : System.IEquatable { throw null; } + public static bool StartsWith(this System.ReadOnlySpan span, System.ReadOnlySpan value) where T : System.IEquatable? { throw null; } + public static bool StartsWith(this System.Span span, System.ReadOnlySpan value) where T : System.IEquatable? { throw null; } public static int ToLower(this System.ReadOnlySpan source, System.Span destination, System.Globalization.CultureInfo? culture) { throw null; } public static int ToLowerInvariant(this System.ReadOnlySpan source, System.Span destination) { throw null; } public static int ToUpper(this System.ReadOnlySpan source, System.Span destination, System.Globalization.CultureInfo? culture) { throw null; } @@ -317,36 +317,36 @@ public static void Sort(this System.Span keys, Sy public static System.ReadOnlySpan TrimEnd(this System.ReadOnlySpan span, char trimChar) { throw null; } public static System.ReadOnlySpan TrimEnd(this System.ReadOnlySpan span, System.ReadOnlySpan trimChars) { throw null; } public static System.Span TrimEnd(this System.Span span) { throw null; } - public static System.Memory TrimEnd(this System.Memory memory, System.ReadOnlySpan trimElements) where T : System.IEquatable { throw null; } - public static System.Memory TrimEnd(this System.Memory memory, T trimElement) where T : System.IEquatable { throw null; } - public static System.ReadOnlyMemory TrimEnd(this System.ReadOnlyMemory memory, System.ReadOnlySpan trimElements) where T : System.IEquatable { throw null; } - public static System.ReadOnlyMemory TrimEnd(this System.ReadOnlyMemory memory, T trimElement) where T : System.IEquatable { throw null; } - public static System.ReadOnlySpan TrimEnd(this System.ReadOnlySpan span, System.ReadOnlySpan trimElements) where T : System.IEquatable { throw null; } - public static System.ReadOnlySpan TrimEnd(this System.ReadOnlySpan span, T trimElement) where T : System.IEquatable { throw null; } - public static System.Span TrimEnd(this System.Span span, System.ReadOnlySpan trimElements) where T : System.IEquatable { throw null; } - public static System.Span TrimEnd(this System.Span span, T trimElement) where T : System.IEquatable { throw null; } + public static System.Memory TrimEnd(this System.Memory memory, System.ReadOnlySpan trimElements) where T : System.IEquatable? { throw null; } + public static System.Memory TrimEnd(this System.Memory memory, T trimElement) where T : System.IEquatable? { throw null; } + public static System.ReadOnlyMemory TrimEnd(this System.ReadOnlyMemory memory, System.ReadOnlySpan trimElements) where T : System.IEquatable? { throw null; } + public static System.ReadOnlyMemory TrimEnd(this System.ReadOnlyMemory memory, T trimElement) where T : System.IEquatable? { throw null; } + public static System.ReadOnlySpan TrimEnd(this System.ReadOnlySpan span, System.ReadOnlySpan trimElements) where T : System.IEquatable? { throw null; } + public static System.ReadOnlySpan TrimEnd(this System.ReadOnlySpan span, T trimElement) where T : System.IEquatable? { throw null; } + public static System.Span TrimEnd(this System.Span span, System.ReadOnlySpan trimElements) where T : System.IEquatable? { throw null; } + public static System.Span TrimEnd(this System.Span span, T trimElement) where T : System.IEquatable? { throw null; } public static System.Memory TrimStart(this System.Memory memory) { throw null; } public static System.ReadOnlyMemory TrimStart(this System.ReadOnlyMemory memory) { throw null; } public static System.ReadOnlySpan TrimStart(this System.ReadOnlySpan span) { throw null; } public static System.ReadOnlySpan TrimStart(this System.ReadOnlySpan span, char trimChar) { throw null; } public static System.ReadOnlySpan TrimStart(this System.ReadOnlySpan span, System.ReadOnlySpan trimChars) { throw null; } public static System.Span TrimStart(this System.Span span) { throw null; } - public static System.Memory TrimStart(this System.Memory memory, System.ReadOnlySpan trimElements) where T : System.IEquatable { throw null; } - public static System.Memory TrimStart(this System.Memory memory, T trimElement) where T : System.IEquatable { throw null; } - public static System.ReadOnlyMemory TrimStart(this System.ReadOnlyMemory memory, System.ReadOnlySpan trimElements) where T : System.IEquatable { throw null; } - public static System.ReadOnlyMemory TrimStart(this System.ReadOnlyMemory memory, T trimElement) where T : System.IEquatable { throw null; } - public static System.ReadOnlySpan TrimStart(this System.ReadOnlySpan span, System.ReadOnlySpan trimElements) where T : System.IEquatable { throw null; } - public static System.ReadOnlySpan TrimStart(this System.ReadOnlySpan span, T trimElement) where T : System.IEquatable { throw null; } - public static System.Span TrimStart(this System.Span span, System.ReadOnlySpan trimElements) where T : System.IEquatable { throw null; } - public static System.Span TrimStart(this System.Span span, T trimElement) where T : System.IEquatable { throw null; } - public static System.Memory Trim(this System.Memory memory, System.ReadOnlySpan trimElements) where T : System.IEquatable { throw null; } - public static System.Memory Trim(this System.Memory memory, T trimElement) where T : System.IEquatable { throw null; } - public static System.ReadOnlyMemory Trim(this System.ReadOnlyMemory memory, System.ReadOnlySpan trimElements) where T : System.IEquatable { throw null; } - public static System.ReadOnlyMemory Trim(this System.ReadOnlyMemory memory, T trimElement) where T : System.IEquatable { throw null; } - public static System.ReadOnlySpan Trim(this System.ReadOnlySpan span, System.ReadOnlySpan trimElements) where T : System.IEquatable { throw null; } - public static System.ReadOnlySpan Trim(this System.ReadOnlySpan span, T trimElement) where T : System.IEquatable { throw null; } - public static System.Span Trim(this System.Span span, System.ReadOnlySpan trimElements) where T : System.IEquatable { throw null; } - public static System.Span Trim(this System.Span span, T trimElement) where T : System.IEquatable { throw null; } + public static System.Memory TrimStart(this System.Memory memory, System.ReadOnlySpan trimElements) where T : System.IEquatable? { throw null; } + public static System.Memory TrimStart(this System.Memory memory, T trimElement) where T : System.IEquatable? { throw null; } + public static System.ReadOnlyMemory TrimStart(this System.ReadOnlyMemory memory, System.ReadOnlySpan trimElements) where T : System.IEquatable? { throw null; } + public static System.ReadOnlyMemory TrimStart(this System.ReadOnlyMemory memory, T trimElement) where T : System.IEquatable? { throw null; } + public static System.ReadOnlySpan TrimStart(this System.ReadOnlySpan span, System.ReadOnlySpan trimElements) where T : System.IEquatable? { throw null; } + public static System.ReadOnlySpan TrimStart(this System.ReadOnlySpan span, T trimElement) where T : System.IEquatable? { throw null; } + public static System.Span TrimStart(this System.Span span, System.ReadOnlySpan trimElements) where T : System.IEquatable? { throw null; } + public static System.Span TrimStart(this System.Span span, T trimElement) where T : System.IEquatable? { throw null; } + public static System.Memory Trim(this System.Memory memory, System.ReadOnlySpan trimElements) where T : System.IEquatable? { throw null; } + public static System.Memory Trim(this System.Memory memory, T trimElement) where T : System.IEquatable? { throw null; } + public static System.ReadOnlyMemory Trim(this System.ReadOnlyMemory memory, System.ReadOnlySpan trimElements) where T : System.IEquatable? { throw null; } + public static System.ReadOnlyMemory Trim(this System.ReadOnlyMemory memory, T trimElement) where T : System.IEquatable? { throw null; } + public static System.ReadOnlySpan Trim(this System.ReadOnlySpan span, System.ReadOnlySpan trimElements) where T : System.IEquatable? { throw null; } + public static System.ReadOnlySpan Trim(this System.ReadOnlySpan span, T trimElement) where T : System.IEquatable? { throw null; } + public static System.Span Trim(this System.Span span, System.ReadOnlySpan trimElements) where T : System.IEquatable? { throw null; } + public static System.Span Trim(this System.Span span, T trimElement) where T : System.IEquatable? { throw null; } public static bool TryWrite(this System.Span destination, [System.Runtime.CompilerServices.InterpolatedStringHandlerArgumentAttribute("destination")] ref System.MemoryExtensions.TryWriteInterpolatedStringHandler handler, out int charsWritten) { throw null; } public static bool TryWrite(this System.Span destination, IFormatProvider? provider, [System.Runtime.CompilerServices.InterpolatedStringHandlerArgumentAttribute("destination", "provider")] ref System.MemoryExtensions.TryWriteInterpolatedStringHandler handler, out int charsWritten) { throw null; } [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] diff --git a/src/libraries/System.Memory/src/System/Buffers/BuffersExtensions.cs b/src/libraries/System.Memory/src/System/Buffers/BuffersExtensions.cs index 05c89507316afb..080c50a0650604 100644 --- a/src/libraries/System.Memory/src/System/Buffers/BuffersExtensions.cs +++ b/src/libraries/System.Memory/src/System/Buffers/BuffersExtensions.cs @@ -14,7 +14,7 @@ public static class BuffersExtensions /// Returns position of first occurrence of item in the /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static SequencePosition? PositionOf(in this ReadOnlySequence source, T value) where T : IEquatable + public static SequencePosition? PositionOf(in this ReadOnlySequence source, T value) where T : IEquatable? { if (source.IsSingleSegment) { @@ -32,7 +32,7 @@ public static class BuffersExtensions } } - private static SequencePosition? PositionOfMultiSegment(in ReadOnlySequence source, T value) where T : IEquatable + private static SequencePosition? PositionOfMultiSegment(in ReadOnlySequence source, T value) where T : IEquatable? { SequencePosition position = source.Start; SequencePosition result = position; diff --git a/src/libraries/System.Memory/tests/TestHelpers.cs b/src/libraries/System.Memory/tests/TestHelpers.cs index daca3c6eeb75a2..f209d9200d41b9 100644 --- a/src/libraries/System.Memory/tests/TestHelpers.cs +++ b/src/libraries/System.Memory/tests/TestHelpers.cs @@ -528,7 +528,11 @@ public static ReadOnlyMemory DangerousCreateReadOnlyMemory(object obj, int { new string[] { "1", "3", "2" }, new string[] { null, "1" }, 0}, { new string[] { "1", "3", "2" }, new string[] { "1", "2", null }, 2}, + { new string[] { "1", "3", "2" }, new string[] { "4", "5", null }, -1}, { new string[] { "1", "3", "2" }, new string[] { null, null }, -1}, + { new string[] { "1", "3", "2" }, new string[] { null, null, null }, -1}, + { new string[] { "1", "3", "2" }, new string[] { null, null, null, null }, -1}, + { new string[] { "1", "3", "2" }, new string[] { null, null, null, null, null }, -1}, { null, new string[] { null, "1" }, -1}, diff --git a/src/libraries/System.Private.CoreLib/src/System/Collections/Generic/Comparer.cs b/src/libraries/System.Private.CoreLib/src/System/Collections/Generic/Comparer.cs index 22cc2f3aac02cd..4151087faebae5 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Collections/Generic/Comparer.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Collections/Generic/Comparer.cs @@ -52,7 +52,7 @@ public ComparisonComparer(Comparison comparison) [Serializable] [TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")] // Needs to be public to support binary serialization compatibility - public sealed partial class GenericComparer : Comparer where T : IComparable + public sealed partial class GenericComparer : Comparer where T : IComparable? { [MethodImpl(MethodImplOptions.AggressiveInlining)] public override int Compare(T? x, T? y) diff --git a/src/libraries/System.Private.CoreLib/src/System/Collections/Generic/EqualityComparer.cs b/src/libraries/System.Private.CoreLib/src/System/Collections/Generic/EqualityComparer.cs index 60a65072a41f90..f6a4934fb684e5 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Collections/Generic/EqualityComparer.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Collections/Generic/EqualityComparer.cs @@ -67,7 +67,7 @@ internal virtual int LastIndexOf(T[] array, T value, int startIndex, int count) [Serializable] [TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")] // Needs to be public to support binary serialization compatibility - public sealed partial class GenericEqualityComparer : EqualityComparer where T : IEquatable + public sealed partial class GenericEqualityComparer : EqualityComparer where T : IEquatable? { [MethodImpl(MethodImplOptions.AggressiveInlining)] public override bool Equals(T? x, T? y) diff --git a/src/libraries/System.Private.CoreLib/src/System/MemoryExtensions.Trim.cs b/src/libraries/System.Private.CoreLib/src/System/MemoryExtensions.Trim.cs index df3cbf8a985cf6..6d4d9e455d38ea 100644 --- a/src/libraries/System.Private.CoreLib/src/System/MemoryExtensions.Trim.cs +++ b/src/libraries/System.Private.CoreLib/src/System/MemoryExtensions.Trim.cs @@ -12,7 +12,7 @@ public static partial class MemoryExtensions /// /// The source memory from which the element is removed. /// The specified element to look for and remove. - public static Memory Trim(this Memory memory, T trimElement) where T : IEquatable + public static Memory Trim(this Memory memory, T trimElement) where T : IEquatable? { ReadOnlySpan span = memory.Span; int start = ClampStart(span, trimElement); @@ -25,7 +25,7 @@ public static Memory Trim(this Memory memory, T trimElement) where T : /// /// The source memory from which the element is removed. /// The specified element to look for and remove. - public static Memory TrimStart(this Memory memory, T trimElement) where T : IEquatable + public static Memory TrimStart(this Memory memory, T trimElement) where T : IEquatable? => memory.Slice(ClampStart(memory.Span, trimElement)); /// @@ -33,7 +33,7 @@ public static Memory TrimStart(this Memory memory, T trimElement) where /// /// The source memory from which the element is removed. /// The specified element to look for and remove. - public static Memory TrimEnd(this Memory memory, T trimElement) where T : IEquatable + public static Memory TrimEnd(this Memory memory, T trimElement) where T : IEquatable? => memory.Slice(0, ClampEnd(memory.Span, 0, trimElement)); /// @@ -41,7 +41,7 @@ public static Memory TrimEnd(this Memory memory, T trimElement) where T /// /// The source memory from which the element is removed. /// The specified element to look for and remove. - public static ReadOnlyMemory Trim(this ReadOnlyMemory memory, T trimElement) where T : IEquatable + public static ReadOnlyMemory Trim(this ReadOnlyMemory memory, T trimElement) where T : IEquatable? { ReadOnlySpan span = memory.Span; int start = ClampStart(span, trimElement); @@ -54,7 +54,7 @@ public static ReadOnlyMemory Trim(this ReadOnlyMemory memory, T trimEle /// /// The source memory from which the element is removed. /// The specified element to look for and remove. - public static ReadOnlyMemory TrimStart(this ReadOnlyMemory memory, T trimElement) where T : IEquatable + public static ReadOnlyMemory TrimStart(this ReadOnlyMemory memory, T trimElement) where T : IEquatable? => memory.Slice(ClampStart(memory.Span, trimElement)); /// @@ -62,7 +62,7 @@ public static ReadOnlyMemory TrimStart(this ReadOnlyMemory memory, T tr /// /// The source memory from which the element is removed. /// The specified element to look for and remove. - public static ReadOnlyMemory TrimEnd(this ReadOnlyMemory memory, T trimElement) where T : IEquatable + public static ReadOnlyMemory TrimEnd(this ReadOnlyMemory memory, T trimElement) where T : IEquatable? => memory.Slice(0, ClampEnd(memory.Span, 0, trimElement)); /// @@ -70,7 +70,7 @@ public static ReadOnlyMemory TrimEnd(this ReadOnlyMemory memory, T trim /// /// The source span from which the element is removed. /// The specified element to look for and remove. - public static Span Trim(this Span span, T trimElement) where T : IEquatable + public static Span Trim(this Span span, T trimElement) where T : IEquatable? { int start = ClampStart(span, trimElement); int length = ClampEnd(span, start, trimElement); @@ -82,7 +82,7 @@ public static Span Trim(this Span span, T trimElement) where T : IEquat /// /// The source span from which the element is removed. /// The specified element to look for and remove. - public static Span TrimStart(this Span span, T trimElement) where T : IEquatable + public static Span TrimStart(this Span span, T trimElement) where T : IEquatable? => span.Slice(ClampStart(span, trimElement)); /// @@ -90,7 +90,7 @@ public static Span TrimStart(this Span span, T trimElement) where T : I /// /// The source span from which the element is removed. /// The specified element to look for and remove. - public static Span TrimEnd(this Span span, T trimElement) where T : IEquatable + public static Span TrimEnd(this Span span, T trimElement) where T : IEquatable? => span.Slice(0, ClampEnd(span, 0, trimElement)); /// @@ -98,7 +98,7 @@ public static Span TrimEnd(this Span span, T trimElement) where T : IEq /// /// The source span from which the element is removed. /// The specified element to look for and remove. - public static ReadOnlySpan Trim(this ReadOnlySpan span, T trimElement) where T : IEquatable + public static ReadOnlySpan Trim(this ReadOnlySpan span, T trimElement) where T : IEquatable? { int start = ClampStart(span, trimElement); int length = ClampEnd(span, start, trimElement); @@ -110,7 +110,7 @@ public static ReadOnlySpan Trim(this ReadOnlySpan span, T trimElement) /// /// The source span from which the element is removed. /// The specified element to look for and remove. - public static ReadOnlySpan TrimStart(this ReadOnlySpan span, T trimElement) where T : IEquatable + public static ReadOnlySpan TrimStart(this ReadOnlySpan span, T trimElement) where T : IEquatable? => span.Slice(ClampStart(span, trimElement)); /// @@ -118,7 +118,7 @@ public static ReadOnlySpan TrimStart(this ReadOnlySpan span, T trimElem /// /// The source span from which the element is removed. /// The specified element to look for and remove. - public static ReadOnlySpan TrimEnd(this ReadOnlySpan span, T trimElement) where T : IEquatable + public static ReadOnlySpan TrimEnd(this ReadOnlySpan span, T trimElement) where T : IEquatable? => span.Slice(0, ClampEnd(span, 0, trimElement)); /// @@ -126,7 +126,7 @@ public static ReadOnlySpan TrimEnd(this ReadOnlySpan span, T trimElemen /// /// The source span from which the element is removed. /// The specified element to look for and remove. - private static int ClampStart(ReadOnlySpan span, T trimElement) where T : IEquatable + private static int ClampStart(ReadOnlySpan span, T trimElement) where T : IEquatable? { int start = 0; @@ -160,7 +160,7 @@ private static int ClampStart(ReadOnlySpan span, T trimElement) where T : /// The source span from which the element is removed. /// The start index from which to being searching. /// The specified element to look for and remove. - private static int ClampEnd(ReadOnlySpan span, int start, T trimElement) where T : IEquatable + private static int ClampEnd(ReadOnlySpan span, int start, T trimElement) where T : IEquatable? { // Initially, start==len==0. If ClampStart trims all, start==len Debug.Assert((uint)start <= span.Length); @@ -198,7 +198,7 @@ private static int ClampEnd(ReadOnlySpan span, int start, T trimElement) w /// The source memory from which the elements are removed. /// The span which contains the set of elements to remove. /// If is empty, the memory is returned unaltered. - public static Memory Trim(this Memory memory, ReadOnlySpan trimElements) where T : IEquatable + public static Memory Trim(this Memory memory, ReadOnlySpan trimElements) where T : IEquatable? { if (trimElements.Length > 1) { @@ -223,7 +223,7 @@ public static Memory Trim(this Memory memory, ReadOnlySpan trimEleme /// The source memory from which the elements are removed. /// The span which contains the set of elements to remove. /// If is empty, the memory is returned unaltered. - public static Memory TrimStart(this Memory memory, ReadOnlySpan trimElements) where T : IEquatable + public static Memory TrimStart(this Memory memory, ReadOnlySpan trimElements) where T : IEquatable? { if (trimElements.Length > 1) { @@ -245,7 +245,7 @@ public static Memory TrimStart(this Memory memory, ReadOnlySpan trim /// The source memory from which the elements are removed. /// The span which contains the set of elements to remove. /// If is empty, the memory is returned unaltered. - public static Memory TrimEnd(this Memory memory, ReadOnlySpan trimElements) where T : IEquatable + public static Memory TrimEnd(this Memory memory, ReadOnlySpan trimElements) where T : IEquatable? { if (trimElements.Length > 1) { @@ -267,7 +267,7 @@ public static Memory TrimEnd(this Memory memory, ReadOnlySpan trimEl /// The source memory from which the elements are removed. /// The span which contains the set of elements to remove. /// If is empty, the memory is returned unaltered. - public static ReadOnlyMemory Trim(this ReadOnlyMemory memory, ReadOnlySpan trimElements) where T : IEquatable + public static ReadOnlyMemory Trim(this ReadOnlyMemory memory, ReadOnlySpan trimElements) where T : IEquatable? { if (trimElements.Length > 1) { @@ -292,7 +292,7 @@ public static ReadOnlyMemory Trim(this ReadOnlyMemory memory, ReadOnlyS /// The source memory from which the elements are removed. /// The span which contains the set of elements to remove. /// If is empty, the memory is returned unaltered. - public static ReadOnlyMemory TrimStart(this ReadOnlyMemory memory, ReadOnlySpan trimElements) where T : IEquatable + public static ReadOnlyMemory TrimStart(this ReadOnlyMemory memory, ReadOnlySpan trimElements) where T : IEquatable? { if (trimElements.Length > 1) { @@ -314,7 +314,7 @@ public static ReadOnlyMemory TrimStart(this ReadOnlyMemory memory, Read /// The source memory from which the elements are removed. /// The span which contains the set of elements to remove. /// If is empty, the memory is returned unaltered. - public static ReadOnlyMemory TrimEnd(this ReadOnlyMemory memory, ReadOnlySpan trimElements) where T : IEquatable + public static ReadOnlyMemory TrimEnd(this ReadOnlyMemory memory, ReadOnlySpan trimElements) where T : IEquatable? { if (trimElements.Length > 1) { @@ -336,7 +336,7 @@ public static ReadOnlyMemory TrimEnd(this ReadOnlyMemory memory, ReadOn /// The source span from which the elements are removed. /// The span which contains the set of elements to remove. /// If is empty, the span is returned unaltered. - public static Span Trim(this Span span, ReadOnlySpan trimElements) where T : IEquatable + public static Span Trim(this Span span, ReadOnlySpan trimElements) where T : IEquatable? { if (trimElements.Length > 1) { @@ -360,7 +360,7 @@ public static Span Trim(this Span span, ReadOnlySpan trimElements) w /// The source span from which the elements are removed. /// The span which contains the set of elements to remove. /// If is empty, the span is returned unaltered. - public static Span TrimStart(this Span span, ReadOnlySpan trimElements) where T : IEquatable + public static Span TrimStart(this Span span, ReadOnlySpan trimElements) where T : IEquatable? { if (trimElements.Length > 1) { @@ -382,7 +382,7 @@ public static Span TrimStart(this Span span, ReadOnlySpan trimElemen /// The source span from which the elements are removed. /// The span which contains the set of elements to remove. /// If is empty, the span is returned unaltered. - public static Span TrimEnd(this Span span, ReadOnlySpan trimElements) where T : IEquatable + public static Span TrimEnd(this Span span, ReadOnlySpan trimElements) where T : IEquatable? { if (trimElements.Length > 1) { @@ -404,7 +404,7 @@ public static Span TrimEnd(this Span span, ReadOnlySpan trimElements /// The source span from which the elements are removed. /// The span which contains the set of elements to remove. /// If is empty, the span is returned unaltered. - public static ReadOnlySpan Trim(this ReadOnlySpan span, ReadOnlySpan trimElements) where T : IEquatable + public static ReadOnlySpan Trim(this ReadOnlySpan span, ReadOnlySpan trimElements) where T : IEquatable? { if (trimElements.Length > 1) { @@ -428,7 +428,7 @@ public static ReadOnlySpan Trim(this ReadOnlySpan span, ReadOnlySpan /// The source span from which the elements are removed. /// The span which contains the set of elements to remove. /// If is empty, the span is returned unaltered. - public static ReadOnlySpan TrimStart(this ReadOnlySpan span, ReadOnlySpan trimElements) where T : IEquatable + public static ReadOnlySpan TrimStart(this ReadOnlySpan span, ReadOnlySpan trimElements) where T : IEquatable? { if (trimElements.Length > 1) { @@ -450,7 +450,7 @@ public static ReadOnlySpan TrimStart(this ReadOnlySpan span, ReadOnlySp /// The source span from which the elements are removed. /// The span which contains the set of elements to remove. /// If is empty, the span is returned unaltered. - public static ReadOnlySpan TrimEnd(this ReadOnlySpan span, ReadOnlySpan trimElements) where T : IEquatable + public static ReadOnlySpan TrimEnd(this ReadOnlySpan span, ReadOnlySpan trimElements) where T : IEquatable? { if (trimElements.Length > 1) { @@ -471,7 +471,7 @@ public static ReadOnlySpan TrimEnd(this ReadOnlySpan span, ReadOnlySpan /// /// The source span from which the elements are removed. /// The span which contains the set of elements to remove. - private static int ClampStart(ReadOnlySpan span, ReadOnlySpan trimElements) where T : IEquatable + private static int ClampStart(ReadOnlySpan span, ReadOnlySpan trimElements) where T : IEquatable? { int start = 0; for (; start < span.Length; start++) @@ -492,7 +492,7 @@ private static int ClampStart(ReadOnlySpan span, ReadOnlySpan trimEleme /// The source span from which the elements are removed. /// The start index from which to being searching. /// The span which contains the set of elements to remove. - private static int ClampEnd(ReadOnlySpan span, int start, ReadOnlySpan trimElements) where T : IEquatable + private static int ClampEnd(ReadOnlySpan span, int start, ReadOnlySpan trimElements) where T : IEquatable? { // Initially, start==len==0. If ClampStart trims all, start==len Debug.Assert((uint)start <= span.Length); diff --git a/src/libraries/System.Private.CoreLib/src/System/MemoryExtensions.cs b/src/libraries/System.Private.CoreLib/src/System/MemoryExtensions.cs index f7787949c61901..865d583654fc09 100644 --- a/src/libraries/System.Private.CoreLib/src/System/MemoryExtensions.cs +++ b/src/libraries/System.Private.CoreLib/src/System/MemoryExtensions.cs @@ -264,7 +264,7 @@ public static ReadOnlyMemory AsMemory(this string? text, Range range) /// The span to search. /// The value to search for. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static bool Contains(this Span span, T value) where T : IEquatable + public static bool Contains(this Span span, T value) where T : IEquatable? { if (RuntimeHelpers.IsBitwiseEquatable()) { @@ -303,7 +303,7 @@ ref Unsafe.As(ref MemoryMarshal.GetReference(span)), /// The span to search. /// The value to search for. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static bool Contains(this ReadOnlySpan span, T value) where T : IEquatable + public static bool Contains(this ReadOnlySpan span, T value) where T : IEquatable? { if (RuntimeHelpers.IsBitwiseEquatable()) { @@ -341,7 +341,7 @@ ref Unsafe.As(ref MemoryMarshal.GetReference(span)), /// The span to search. /// The value to search for. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int IndexOf(this Span span, T value) where T : IEquatable + public static int IndexOf(this Span span, T value) where T : IEquatable? { if (RuntimeHelpers.IsBitwiseEquatable()) { @@ -379,7 +379,7 @@ ref Unsafe.As(ref MemoryMarshal.GetReference(span)), /// The span to search. /// The sequence to search for. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int IndexOf(this Span span, ReadOnlySpan value) where T : IEquatable + public static int IndexOf(this Span span, ReadOnlySpan value) where T : IEquatable? { if (RuntimeHelpers.IsBitwiseEquatable()) { @@ -407,7 +407,7 @@ ref Unsafe.As(ref MemoryMarshal.GetReference(value)), /// The span to search. /// The value to search for. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int LastIndexOf(this Span span, T value) where T : IEquatable + public static int LastIndexOf(this Span span, T value) where T : IEquatable? { if (RuntimeHelpers.IsBitwiseEquatable()) { @@ -433,7 +433,7 @@ ref Unsafe.As(ref MemoryMarshal.GetReference(span)), /// The span to search. /// The sequence to search for. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int LastIndexOf(this Span span, ReadOnlySpan value) where T : IEquatable + public static int LastIndexOf(this Span span, ReadOnlySpan value) where T : IEquatable? { if (Unsafe.SizeOf() == sizeof(byte) && RuntimeHelpers.IsBitwiseEquatable()) return SpanHelpers.LastIndexOf( @@ -453,7 +453,7 @@ ref Unsafe.As(ref MemoryMarshal.GetReference(value)), /// The index in the span of the first occurrence of any value other than . /// If all of the values are , returns -1. /// - public static int IndexOfAnyExcept(this Span span, T value) where T : IEquatable => + public static int IndexOfAnyExcept(this Span span, T value) where T : IEquatable? => IndexOfAnyExcept((ReadOnlySpan)span, value); /// Searches for the first index of any value other than the specified or . @@ -465,7 +465,7 @@ public static int IndexOfAnyExcept(this Span span, T value) where T : IEqu /// The index in the span of the first occurrence of any value other than and . /// If all of the values are or , returns -1. /// - public static int IndexOfAnyExcept(this Span span, T value0, T value1) where T : IEquatable => + public static int IndexOfAnyExcept(this Span span, T value0, T value1) where T : IEquatable? => IndexOfAnyExcept((ReadOnlySpan)span, value0, value1); /// Searches for the first index of any value other than the specified , , or . @@ -478,7 +478,7 @@ public static int IndexOfAnyExcept(this Span span, T value0, T value1) whe /// The index in the span of the first occurrence of any value other than , , and . /// If all of the values are , , and , returns -1. /// - public static int IndexOfAnyExcept(this Span span, T value0, T value1, T value2) where T : IEquatable => + public static int IndexOfAnyExcept(this Span span, T value0, T value1, T value2) where T : IEquatable? => IndexOfAnyExcept((ReadOnlySpan)span, value0, value1, value2); /// Searches for the first index of any value other than the specified . @@ -489,7 +489,7 @@ public static int IndexOfAnyExcept(this Span span, T value0, T value1, T v /// The index in the span of the first occurrence of any value other than those in . /// If all of the values are in , returns -1. /// - public static int IndexOfAnyExcept(this Span span, ReadOnlySpan values) where T : IEquatable => + public static int IndexOfAnyExcept(this Span span, ReadOnlySpan values) where T : IEquatable? => IndexOfAnyExcept((ReadOnlySpan)span, values); /// Searches for the first index of any value other than the specified . @@ -500,7 +500,7 @@ public static int IndexOfAnyExcept(this Span span, ReadOnlySpan values) /// The index in the span of the first occurrence of any value other than . /// If all of the values are , returns -1. /// - public static int IndexOfAnyExcept(this ReadOnlySpan span, T value) where T : IEquatable + public static int IndexOfAnyExcept(this ReadOnlySpan span, T value) where T : IEquatable? { for (int i = 0; i < span.Length; i++) { @@ -522,7 +522,7 @@ public static int IndexOfAnyExcept(this ReadOnlySpan span, T value) where /// The index in the span of the first occurrence of any value other than and . /// If all of the values are or , returns -1. /// - public static int IndexOfAnyExcept(this ReadOnlySpan span, T value0, T value1) where T : IEquatable + public static int IndexOfAnyExcept(this ReadOnlySpan span, T value0, T value1) where T : IEquatable? { for (int i = 0; i < span.Length; i++) { @@ -546,7 +546,7 @@ public static int IndexOfAnyExcept(this ReadOnlySpan span, T value0, T val /// The index in the span of the first occurrence of any value other than , , and . /// If all of the values are , , and , returns -1. /// - public static int IndexOfAnyExcept(this ReadOnlySpan span, T value0, T value1, T value2) where T : IEquatable + public static int IndexOfAnyExcept(this ReadOnlySpan span, T value0, T value1, T value2) where T : IEquatable? { for (int i = 0; i < span.Length; i++) { @@ -569,7 +569,7 @@ public static int IndexOfAnyExcept(this ReadOnlySpan span, T value0, T val /// The index in the span of the first occurrence of any value other than those in . /// If all of the values are in , returns -1. /// - public static int IndexOfAnyExcept(this ReadOnlySpan span, ReadOnlySpan values) where T : IEquatable + public static int IndexOfAnyExcept(this ReadOnlySpan span, ReadOnlySpan values) where T : IEquatable? { switch (values.Length) { @@ -609,7 +609,7 @@ public static int IndexOfAnyExcept(this ReadOnlySpan span, ReadOnlySpan /// The index in the span of the last occurrence of any value other than . /// If all of the values are , returns -1. /// - public static int LastIndexOfAnyExcept(this Span span, T value) where T : IEquatable => + public static int LastIndexOfAnyExcept(this Span span, T value) where T : IEquatable? => LastIndexOfAnyExcept((ReadOnlySpan)span, value); /// Searches for the last index of any value other than the specified or . @@ -621,7 +621,7 @@ public static int LastIndexOfAnyExcept(this Span span, T value) where T : /// The index in the span of the last occurrence of any value other than and . /// If all of the values are or , returns -1. /// - public static int LastIndexOfAnyExcept(this Span span, T value0, T value1) where T : IEquatable => + public static int LastIndexOfAnyExcept(this Span span, T value0, T value1) where T : IEquatable? => LastIndexOfAnyExcept((ReadOnlySpan)span, value0, value1); /// Searches for the last index of any value other than the specified , , or . @@ -634,7 +634,7 @@ public static int LastIndexOfAnyExcept(this Span span, T value0, T value1) /// The index in the span of the last occurrence of any value other than , , and . /// If all of the values are , , and , returns -1. /// - public static int LastIndexOfAnyExcept(this Span span, T value0, T value1, T value2) where T : IEquatable => + public static int LastIndexOfAnyExcept(this Span span, T value0, T value1, T value2) where T : IEquatable? => LastIndexOfAnyExcept((ReadOnlySpan)span, value0, value1, value2); /// Searches for the last index of any value other than the specified . @@ -645,7 +645,7 @@ public static int LastIndexOfAnyExcept(this Span span, T value0, T value1, /// The index in the span of the last occurrence of any value other than those in . /// If all of the values are in , returns -1. /// - public static int LastIndexOfAnyExcept(this Span span, ReadOnlySpan values) where T : IEquatable => + public static int LastIndexOfAnyExcept(this Span span, ReadOnlySpan values) where T : IEquatable? => LastIndexOfAnyExcept((ReadOnlySpan)span, values); /// Searches for the last index of any value other than the specified . @@ -656,7 +656,7 @@ public static int LastIndexOfAnyExcept(this Span span, ReadOnlySpan val /// The index in the span of the last occurrence of any value other than . /// If all of the values are , returns -1. /// - public static int LastIndexOfAnyExcept(this ReadOnlySpan span, T value) where T : IEquatable + public static int LastIndexOfAnyExcept(this ReadOnlySpan span, T value) where T : IEquatable? { for (int i = span.Length - 1; i >= 0; i--) { @@ -678,7 +678,7 @@ public static int LastIndexOfAnyExcept(this ReadOnlySpan span, T value) wh /// The index in the span of the last occurrence of any value other than and . /// If all of the values are or , returns -1. /// - public static int LastIndexOfAnyExcept(this ReadOnlySpan span, T value0, T value1) where T : IEquatable + public static int LastIndexOfAnyExcept(this ReadOnlySpan span, T value0, T value1) where T : IEquatable? { for (int i = span.Length - 1; i >= 0; i--) { @@ -702,7 +702,7 @@ public static int LastIndexOfAnyExcept(this ReadOnlySpan span, T value0, T /// The index in the span of the last occurrence of any value other than , , and . /// If all of the values are , , and , returns -1. /// - public static int LastIndexOfAnyExcept(this ReadOnlySpan span, T value0, T value1, T value2) where T : IEquatable + public static int LastIndexOfAnyExcept(this ReadOnlySpan span, T value0, T value1, T value2) where T : IEquatable? { for (int i = span.Length - 1; i >= 0; i--) { @@ -725,7 +725,7 @@ public static int LastIndexOfAnyExcept(this ReadOnlySpan span, T value0, T /// The index in the span of the first occurrence of any value other than those in . /// If all of the values are in , returns -1. /// - public static int LastIndexOfAnyExcept(this ReadOnlySpan span, ReadOnlySpan values) where T : IEquatable + public static int LastIndexOfAnyExcept(this ReadOnlySpan span, ReadOnlySpan values) where T : IEquatable? { switch (values.Length) { @@ -763,7 +763,7 @@ public static int LastIndexOfAnyExcept(this ReadOnlySpan span, ReadOnlySpa /// [Intrinsic] // Unrolled and vectorized for half-constant input [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static bool SequenceEqual(this Span span, ReadOnlySpan other) where T : IEquatable + public static bool SequenceEqual(this Span span, ReadOnlySpan other) where T : IEquatable? { int length = span.Length; @@ -784,7 +784,7 @@ ref Unsafe.As(ref MemoryMarshal.GetReference(other)), /// Determines the relative order of the sequences being compared by comparing the elements using IComparable{T}.CompareTo(T). /// public static int SequenceCompareTo(this Span span, ReadOnlySpan other) - where T : IComparable + where T : IComparable? { // Can't use IsBitwiseEquatable() below because that only tells us about // equality checks, not about CompareTo checks. @@ -812,7 +812,7 @@ ref Unsafe.As(ref MemoryMarshal.GetReference(other)), /// The span to search. /// The value to search for. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int IndexOf(this ReadOnlySpan span, T value) where T : IEquatable + public static int IndexOf(this ReadOnlySpan span, T value) where T : IEquatable? { if (RuntimeHelpers.IsBitwiseEquatable()) { @@ -838,7 +838,7 @@ ref Unsafe.As(ref MemoryMarshal.GetReference(span)), /// The span to search. /// The sequence to search for. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int IndexOf(this ReadOnlySpan span, ReadOnlySpan value) where T : IEquatable + public static int IndexOf(this ReadOnlySpan span, ReadOnlySpan value) where T : IEquatable? { if (RuntimeHelpers.IsBitwiseEquatable()) { @@ -866,7 +866,7 @@ ref Unsafe.As(ref MemoryMarshal.GetReference(value)), /// The span to search. /// The value to search for. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int LastIndexOf(this ReadOnlySpan span, T value) where T : IEquatable + public static int LastIndexOf(this ReadOnlySpan span, T value) where T : IEquatable? { if (RuntimeHelpers.IsBitwiseEquatable()) { @@ -892,7 +892,7 @@ ref Unsafe.As(ref MemoryMarshal.GetReference(span)), /// The span to search. /// The sequence to search for. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int LastIndexOf(this ReadOnlySpan span, ReadOnlySpan value) where T : IEquatable + public static int LastIndexOf(this ReadOnlySpan span, ReadOnlySpan value) where T : IEquatable? { if (RuntimeHelpers.IsBitwiseEquatable()) { @@ -924,7 +924,7 @@ ref Unsafe.As(ref MemoryMarshal.GetReference(value)), /// One of the values to search for. /// One of the values to search for. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int IndexOfAny(this Span span, T value0, T value1) where T : IEquatable + public static int IndexOfAny(this Span span, T value0, T value1) where T : IEquatable? { if (RuntimeHelpers.IsBitwiseEquatable()) { @@ -954,7 +954,7 @@ ref Unsafe.As(ref MemoryMarshal.GetReference(span)), /// One of the values to search for. /// One of the values to search for. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int IndexOfAny(this Span span, T value0, T value1, T value2) where T : IEquatable + public static int IndexOfAny(this Span span, T value0, T value1, T value2) where T : IEquatable? { if (RuntimeHelpers.IsBitwiseEquatable()) { @@ -984,7 +984,7 @@ ref Unsafe.As(ref MemoryMarshal.GetReference(span)), /// The span to search. /// The set of values to search for. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int IndexOfAny(this Span span, ReadOnlySpan values) where T : IEquatable => + public static int IndexOfAny(this Span span, ReadOnlySpan values) where T : IEquatable? => IndexOfAny((ReadOnlySpan)span, values); /// @@ -994,7 +994,7 @@ public static int IndexOfAny(this Span span, ReadOnlySpan values) where /// One of the values to search for. /// One of the values to search for. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int IndexOfAny(this ReadOnlySpan span, T value0, T value1) where T : IEquatable + public static int IndexOfAny(this ReadOnlySpan span, T value0, T value1) where T : IEquatable? { if (RuntimeHelpers.IsBitwiseEquatable()) { @@ -1024,7 +1024,7 @@ ref Unsafe.As(ref MemoryMarshal.GetReference(span)), /// One of the values to search for. /// One of the values to search for. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int IndexOfAny(this ReadOnlySpan span, T value0, T value1, T value2) where T : IEquatable + public static int IndexOfAny(this ReadOnlySpan span, T value0, T value1, T value2) where T : IEquatable? { if (RuntimeHelpers.IsBitwiseEquatable()) { @@ -1054,7 +1054,7 @@ ref Unsafe.As(ref MemoryMarshal.GetReference(span)), /// The span to search. /// The set of values to search for. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int IndexOfAny(this ReadOnlySpan span, ReadOnlySpan values) where T : IEquatable + public static int IndexOfAny(this ReadOnlySpan span, ReadOnlySpan values) where T : IEquatable? { if (RuntimeHelpers.IsBitwiseEquatable()) { @@ -1175,7 +1175,7 @@ private static unsafe int IndexOfAnyProbabilistic(ref char searchSpace, int sear /// One of the values to search for. /// One of the values to search for. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int LastIndexOfAny(this Span span, T value0, T value1) where T : IEquatable + public static int LastIndexOfAny(this Span span, T value0, T value1) where T : IEquatable? { if (Unsafe.SizeOf() == sizeof(byte) && RuntimeHelpers.IsBitwiseEquatable()) return SpanHelpers.LastIndexOfAny( @@ -1195,7 +1195,7 @@ ref Unsafe.As(ref MemoryMarshal.GetReference(span)), /// One of the values to search for. /// One of the values to search for. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int LastIndexOfAny(this Span span, T value0, T value1, T value2) where T : IEquatable + public static int LastIndexOfAny(this Span span, T value0, T value1, T value2) where T : IEquatable? { if (Unsafe.SizeOf() == sizeof(byte) && RuntimeHelpers.IsBitwiseEquatable()) return SpanHelpers.LastIndexOfAny( @@ -1214,7 +1214,7 @@ ref Unsafe.As(ref MemoryMarshal.GetReference(span)), /// The span to search. /// The set of values to search for. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int LastIndexOfAny(this Span span, ReadOnlySpan values) where T : IEquatable + public static int LastIndexOfAny(this Span span, ReadOnlySpan values) where T : IEquatable? { if (Unsafe.SizeOf() == sizeof(byte) && RuntimeHelpers.IsBitwiseEquatable()) return SpanHelpers.LastIndexOfAny( @@ -1233,7 +1233,7 @@ ref Unsafe.As(ref MemoryMarshal.GetReference(values)), /// One of the values to search for. /// One of the values to search for. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int LastIndexOfAny(this ReadOnlySpan span, T value0, T value1) where T : IEquatable + public static int LastIndexOfAny(this ReadOnlySpan span, T value0, T value1) where T : IEquatable? { if (Unsafe.SizeOf() == sizeof(byte) && RuntimeHelpers.IsBitwiseEquatable()) return SpanHelpers.LastIndexOfAny( @@ -1253,7 +1253,7 @@ ref Unsafe.As(ref MemoryMarshal.GetReference(span)), /// One of the values to search for. /// One of the values to search for. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int LastIndexOfAny(this ReadOnlySpan span, T value0, T value1, T value2) where T : IEquatable + public static int LastIndexOfAny(this ReadOnlySpan span, T value0, T value1, T value2) where T : IEquatable? { if (Unsafe.SizeOf() == sizeof(byte) && RuntimeHelpers.IsBitwiseEquatable()) return SpanHelpers.LastIndexOfAny( @@ -1272,7 +1272,7 @@ ref Unsafe.As(ref MemoryMarshal.GetReference(span)), /// The span to search. /// The set of values to search for. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int LastIndexOfAny(this ReadOnlySpan span, ReadOnlySpan values) where T : IEquatable + public static int LastIndexOfAny(this ReadOnlySpan span, ReadOnlySpan values) where T : IEquatable? { if (RuntimeHelpers.IsBitwiseEquatable()) { @@ -1340,7 +1340,7 @@ private static unsafe int LastIndexOfAnyProbabilistic(ref char searchSpace, int /// [Intrinsic] // Unrolled and vectorized for half-constant input [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static bool SequenceEqual(this ReadOnlySpan span, ReadOnlySpan other) where T : IEquatable + public static bool SequenceEqual(this ReadOnlySpan span, ReadOnlySpan other) where T : IEquatable? { int length = span.Length; if (RuntimeHelpers.IsBitwiseEquatable()) @@ -1426,7 +1426,7 @@ ref Unsafe.As(ref MemoryMarshal.GetReference(other)), /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int SequenceCompareTo(this ReadOnlySpan span, ReadOnlySpan other) - where T : IComparable + where T : IComparable? { // Can't use IsBitwiseEquatable() below because that only tells us about // equality checks, not about CompareTo checks. @@ -1453,7 +1453,7 @@ ref Unsafe.As(ref MemoryMarshal.GetReference(other)), /// [Intrinsic] // Unrolled and vectorized for half-constant input [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static bool StartsWith(this Span span, ReadOnlySpan value) where T : IEquatable + public static bool StartsWith(this Span span, ReadOnlySpan value) where T : IEquatable? { int valueLength = value.Length; if (RuntimeHelpers.IsBitwiseEquatable()) @@ -1474,7 +1474,7 @@ ref Unsafe.As(ref MemoryMarshal.GetReference(value)), /// [Intrinsic] // Unrolled and vectorized for half-constant input [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static bool StartsWith(this ReadOnlySpan span, ReadOnlySpan value) where T : IEquatable + public static bool StartsWith(this ReadOnlySpan span, ReadOnlySpan value) where T : IEquatable? { int valueLength = value.Length; if (RuntimeHelpers.IsBitwiseEquatable()) @@ -1494,7 +1494,7 @@ ref Unsafe.As(ref MemoryMarshal.GetReference(value)), /// Determines whether the specified sequence appears at the end of the span. /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static bool EndsWith(this Span span, ReadOnlySpan value) where T : IEquatable + public static bool EndsWith(this Span span, ReadOnlySpan value) where T : IEquatable? { int spanLength = span.Length; int valueLength = value.Length; @@ -1519,7 +1519,7 @@ ref MemoryMarshal.GetReference(value), /// Determines whether the specified sequence appears at the end of the span. /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static bool EndsWith(this ReadOnlySpan span, ReadOnlySpan value) where T : IEquatable + public static bool EndsWith(this ReadOnlySpan span, ReadOnlySpan value) where T : IEquatable? { int spanLength = span.Length; int valueLength = value.Length; diff --git a/src/libraries/System.Private.CoreLib/src/System/SpanHelpers.T.cs b/src/libraries/System.Private.CoreLib/src/System/SpanHelpers.T.cs index 8b372fe952b320..e1c03a69a9c348 100644 --- a/src/libraries/System.Private.CoreLib/src/System/SpanHelpers.T.cs +++ b/src/libraries/System.Private.CoreLib/src/System/SpanHelpers.T.cs @@ -184,7 +184,7 @@ public static void Fill(ref T refData, nuint numElements, T value) } } - public static int IndexOf(ref T searchSpace, int searchSpaceLength, ref T value, int valueLength) where T : IEquatable + public static int IndexOf(ref T searchSpace, int searchSpaceLength, ref T value, int valueLength) where T : IEquatable? { Debug.Assert(searchSpaceLength >= 0); Debug.Assert(valueLength >= 0); @@ -220,14 +220,16 @@ public static int IndexOf(ref T searchSpace, int searchSpaceLength, ref T val } // Adapted from IndexOf(...) - public static unsafe bool Contains(ref T searchSpace, T value, int length) where T : IEquatable + public static unsafe bool Contains(ref T searchSpace, T value, int length) where T : IEquatable? { Debug.Assert(length >= 0); nint index = 0; // Use nint for arithmetic to avoid unnecessary 64->32->64 truncations - if (default(T) != null || (object)value != null) + if (default(T) != null || (object?)value != null) { + Debug.Assert(value is not null); + while (length >= 8) { length -= 8; @@ -277,7 +279,7 @@ public static unsafe bool Contains(ref T searchSpace, T value, int length) wh nint len = length; for (index = 0; index < len; index++) { - if ((object)Unsafe.Add(ref searchSpace, index) is null) + if ((object?)Unsafe.Add(ref searchSpace, index) is null) { goto Found; } @@ -399,13 +401,15 @@ internal static unsafe int IndexOfValueType(ref T searchSpace, T value, int l return (int)(index + 7); } - public static unsafe int IndexOf(ref T searchSpace, T value, int length) where T : IEquatable + public static unsafe int IndexOf(ref T searchSpace, T value, int length) where T : IEquatable? { Debug.Assert(length >= 0); nint index = 0; // Use nint for arithmetic to avoid unnecessary 64->32->64 truncations - if (default(T) != null || (object)value != null) + if (default(T) != null || (object?)value != null) { + Debug.Assert(value is not null); + while (length >= 8) { length -= 8; @@ -460,7 +464,7 @@ public static unsafe int IndexOf(ref T searchSpace, T value, int length) wher nint len = (nint)length; for (index = 0; index < len; index++) { - if ((object)Unsafe.Add(ref searchSpace, index) is null) + if ((object?)Unsafe.Add(ref searchSpace, index) is null) { goto Found; } @@ -486,14 +490,16 @@ public static unsafe int IndexOf(ref T searchSpace, T value, int length) wher return (int)(index + 7); } - public static int IndexOfAny(ref T searchSpace, T value0, T value1, int length) where T : IEquatable + public static int IndexOfAny(ref T searchSpace, T value0, T value1, int length) where T : IEquatable? { Debug.Assert(length >= 0); T lookUp; int index = 0; - if (default(T) != null || ((object)value0 != null && (object)value1 != null)) + if (default(T) != null || ((object?)value0 != null && (object?)value1 != null)) { + Debug.Assert(value0 is not null && value1 is not null); + while ((length - index) >= 8) { lookUp = Unsafe.Add(ref searchSpace, index); @@ -590,14 +596,16 @@ public static int IndexOfAny(ref T searchSpace, T value0, T value1, int lengt return index + 7; } - public static int IndexOfAny(ref T searchSpace, T value0, T value1, T value2, int length) where T : IEquatable + public static int IndexOfAny(ref T searchSpace, T value0, T value1, T value2, int length) where T : IEquatable? { Debug.Assert(length >= 0); T lookUp; int index = 0; - if (default(T) != null || ((object)value0 != null && (object)value1 != null && (object)value2 != null)) + if (default(T) != null || ((object?)value0 != null && (object?)value1 != null && (object?)value2 != null)) { + Debug.Assert(value0 is not null && value1 is not null && value2 is not null); + while ((length - index) >= 8) { lookUp = Unsafe.Add(ref searchSpace, index); @@ -693,7 +701,7 @@ public static int IndexOfAny(ref T searchSpace, T value0, T value1, T value2, return index + 7; } - public static int IndexOfAny(ref T searchSpace, int searchSpaceLength, ref T value, int valueLength) where T : IEquatable + public static int IndexOfAny(ref T searchSpace, int searchSpaceLength, ref T value, int valueLength) where T : IEquatable? { Debug.Assert(searchSpaceLength >= 0); Debug.Assert(valueLength >= 0); @@ -723,7 +731,7 @@ public static int IndexOfAny(ref T searchSpace, int searchSpaceLength, ref T T candidate = Unsafe.Add(ref searchSpace, i); for (int j = 0; j < valueLength; j++) { - if (Unsafe.Add(ref value, j).Equals(candidate)) + if (Unsafe.Add(ref value, j)!.Equals(candidate)) { return i; } @@ -764,7 +772,7 @@ public static int IndexOfAny(ref T searchSpace, int searchSpaceLength, ref T return -1; // not found } - public static int LastIndexOf(ref T searchSpace, int searchSpaceLength, ref T value, int valueLength) where T : IEquatable + public static int LastIndexOf(ref T searchSpace, int searchSpaceLength, ref T value, int valueLength) where T : IEquatable? { Debug.Assert(searchSpaceLength >= 0); Debug.Assert(valueLength >= 0); @@ -804,12 +812,14 @@ public static int LastIndexOf(ref T searchSpace, int searchSpaceLength, ref T return -1; } - public static int LastIndexOf(ref T searchSpace, T value, int length) where T : IEquatable + public static int LastIndexOf(ref T searchSpace, T value, int length) where T : IEquatable? { Debug.Assert(length >= 0); - if (default(T) != null || (object)value != null) + if (default(T) != null || (object?)value != null) { + Debug.Assert(value is not null); + while (length >= 8) { length -= 8; @@ -858,7 +868,7 @@ public static int LastIndexOf(ref T searchSpace, T value, int length) where T { for (length--; length >= 0; length--) { - if ((object)Unsafe.Add(ref searchSpace, length) is null) + if ((object?)Unsafe.Add(ref searchSpace, length) is null) { goto Found; } @@ -885,13 +895,15 @@ public static int LastIndexOf(ref T searchSpace, T value, int length) where T return length + 7; } - public static int LastIndexOfAny(ref T searchSpace, T value0, T value1, int length) where T : IEquatable + public static int LastIndexOfAny(ref T searchSpace, T value0, T value1, int length) where T : IEquatable? { Debug.Assert(length >= 0); T lookUp; - if (default(T) != null || ((object)value0 != null && (object)value1 != null)) + if (default(T) != null || ((object?)value0 != null && (object?)value1 != null)) { + Debug.Assert(value0 is not null && value1 is not null); + while (length >= 8) { length -= 8; @@ -988,13 +1000,15 @@ public static int LastIndexOfAny(ref T searchSpace, T value0, T value1, int l return length + 7; } - public static int LastIndexOfAny(ref T searchSpace, T value0, T value1, T value2, int length) where T : IEquatable + public static int LastIndexOfAny(ref T searchSpace, T value0, T value1, T value2, int length) where T : IEquatable? { Debug.Assert(length >= 0); T lookUp; - if (default(T) != null || ((object)value0 != null && (object)value1 != null)) + if (default(T) != null || ((object?)value0 != null && (object?)value1 != null && (object?)value2 != null)) { + Debug.Assert(value0 is not null && value1 is not null && value2 is not null); + while (length >= 8) { length -= 8; @@ -1091,7 +1105,7 @@ public static int LastIndexOfAny(ref T searchSpace, T value0, T value1, T val return length + 7; } - public static int LastIndexOfAny(ref T searchSpace, int searchSpaceLength, ref T value, int valueLength) where T : IEquatable + public static int LastIndexOfAny(ref T searchSpace, int searchSpaceLength, ref T value, int valueLength) where T : IEquatable? { Debug.Assert(searchSpaceLength >= 0); Debug.Assert(valueLength >= 0); @@ -1109,7 +1123,7 @@ public static int LastIndexOfAny(ref T searchSpace, int searchSpaceLength, re T candidate = Unsafe.Add(ref searchSpace, i); for (int j = 0; j < valueLength; j++) { - if (Unsafe.Add(ref value, j).Equals(candidate)) + if (Unsafe.Add(ref value, j)!.Equals(candidate)) { return i; } @@ -1147,7 +1161,7 @@ public static int LastIndexOfAny(ref T searchSpace, int searchSpaceLength, re return -1; // not found } - public static bool SequenceEqual(ref T first, ref T second, int length) where T : IEquatable + public static bool SequenceEqual(ref T first, ref T second, int length) where T : IEquatable? { Debug.Assert(length >= 0); @@ -1239,7 +1253,7 @@ public static bool SequenceEqual(ref T first, ref T second, int length) where } public static int SequenceCompareTo(ref T first, int firstLength, ref T second, int secondLength) - where T : IComparable + where T : IComparable? { Debug.Assert(firstLength >= 0); Debug.Assert(secondLength >= 0);