diff --git a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/ReachabilityInstrumentationFilter.cs b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/ReachabilityInstrumentationFilter.cs index 9afe7e724fcc81..2fb613d9521dff 100644 --- a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/ReachabilityInstrumentationFilter.cs +++ b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/ReachabilityInstrumentationFilter.cs @@ -44,7 +44,7 @@ public ReachabilityInstrumentationFilter(string profileDataFileName, ILProvider int numTokens = reader.ReadInt32(); bool[] tokenStates = new bool[numTokens]; - if (reader.Read(MemoryMarshal.Cast(tokenStates)) != numTokens) + if (reader.Read(MemoryMarshal.Cast(tokenStates.AsSpan())) != numTokens) throw new IOException("Unexpected end of file"); _reachabilityInfo.Add(new Guid(guidBytes), tokenStates); diff --git a/src/libraries/Common/tests/StreamConformanceTests/System/IO/StreamConformanceTests.cs b/src/libraries/Common/tests/StreamConformanceTests/System/IO/StreamConformanceTests.cs index 61fb0f51936e27..e9ff147bbe5f03 100644 --- a/src/libraries/Common/tests/StreamConformanceTests/System/IO/StreamConformanceTests.cs +++ b/src/libraries/Common/tests/StreamConformanceTests/System/IO/StreamConformanceTests.cs @@ -1915,7 +1915,7 @@ public virtual async Task ReadWrite_MessagesSmallerThanReadBuffer_Success(ReadWr } Assert.Equal(writerBytes.Length, n); - AssertExtensions.SequenceEqual(writerBytes, readerBytes.AsSpan(0, writerBytes.Length)); + AssertExtensions.SequenceEqual(writerBytes.AsSpan(), readerBytes.AsSpan(0, writerBytes.Length)); await writes; } @@ -3069,7 +3069,7 @@ public virtual async Task ZeroByteRead_PerformsZeroByteReadOnUnderlyingStreamWhe if (FlushGuaranteesAllDataWritten) { - AssertExtensions.SequenceEqual(data, buffer.AsSpan(0, bytesRead)); + AssertExtensions.SequenceEqual(data.AsSpan(), buffer.AsSpan(0, bytesRead)); } } } diff --git a/src/libraries/System.Formats.Nrbf/src/System/Formats/Nrbf/ArraySinglePrimitiveRecord.cs b/src/libraries/System.Formats.Nrbf/src/System/Formats/Nrbf/ArraySinglePrimitiveRecord.cs index a28359d9bb13dc..fa18cc5bb9da4d 100644 --- a/src/libraries/System.Formats.Nrbf/src/System/Formats/Nrbf/ArraySinglePrimitiveRecord.cs +++ b/src/libraries/System.Formats.Nrbf/src/System/Formats/Nrbf/ArraySinglePrimitiveRecord.cs @@ -161,7 +161,7 @@ internal static IReadOnlyList DecodePrimitiveTypes(BinaryReader reader, int c { if (typeof(T) == typeof(short) || typeof(T) == typeof(ushort)) { - Span span = MemoryMarshal.Cast(result); + Span span = MemoryMarshal.Cast(result.AsSpan()); #if NET BinaryPrimitives.ReverseEndianness(span, span); #else @@ -173,7 +173,7 @@ internal static IReadOnlyList DecodePrimitiveTypes(BinaryReader reader, int c } else if (typeof(T) == typeof(int) || typeof(T) == typeof(uint) || typeof(T) == typeof(float)) { - Span span = MemoryMarshal.Cast(result); + Span span = MemoryMarshal.Cast(result.AsSpan()); #if NET BinaryPrimitives.ReverseEndianness(span, span); #else @@ -185,7 +185,7 @@ internal static IReadOnlyList DecodePrimitiveTypes(BinaryReader reader, int c } else if (typeof(T) == typeof(long) || typeof(T) == typeof(ulong) || typeof(T) == typeof(double)) { - Span span = MemoryMarshal.Cast(result); + Span span = MemoryMarshal.Cast(result.AsSpan()); #if NET BinaryPrimitives.ReverseEndianness(span, span); #else diff --git a/src/libraries/System.Linq/tests/RangeTests.cs b/src/libraries/System.Linq/tests/RangeTests.cs index 2e331cfee7ecd7..26ec544f327af7 100644 --- a/src/libraries/System.Linq/tests/RangeTests.cs +++ b/src/libraries/System.Linq/tests/RangeTests.cs @@ -270,7 +270,7 @@ static void Validate(IEnumerable e, int[] expected) list.CopyTo(actual, 1); Assert.Equal(0, actual[0]); Assert.Equal(0, actual[^1]); - AssertExtensions.SequenceEqual(expected, actual.AsSpan(1, expected.Length)); + AssertExtensions.SequenceEqual(expected.AsSpan(), actual.AsSpan(1, expected.Length)); } } } diff --git a/src/libraries/System.Linq/tests/RepeatTests.cs b/src/libraries/System.Linq/tests/RepeatTests.cs index df8eebda35691e..9ee0d7f68fb146 100644 --- a/src/libraries/System.Linq/tests/RepeatTests.cs +++ b/src/libraries/System.Linq/tests/RepeatTests.cs @@ -282,7 +282,7 @@ static void Validate(IEnumerable e, int[] expected) list.CopyTo(actual, 1); Assert.Equal(0, actual[0]); Assert.Equal(0, actual[^1]); - AssertExtensions.SequenceEqual(expected, actual.AsSpan(1, expected.Length)); + AssertExtensions.SequenceEqual(expected.AsSpan(), actual.AsSpan(1, expected.Length)); } } } diff --git a/src/libraries/System.Memory/tests/Base64Url/Base64UrlUnicodeAPIsUnitTests.cs b/src/libraries/System.Memory/tests/Base64Url/Base64UrlUnicodeAPIsUnitTests.cs index 09326bef170ea8..a455075bb9c7ed 100644 --- a/src/libraries/System.Memory/tests/Base64Url/Base64UrlUnicodeAPIsUnitTests.cs +++ b/src/libraries/System.Memory/tests/Base64Url/Base64UrlUnicodeAPIsUnitTests.cs @@ -438,7 +438,7 @@ public static void Base64_AllMethodsRoundtripConsistently() Span decodedBytes = new byte[original.Length]; int decoded = Base64Url.DecodeFromChars(encodedArray, decodedBytes); Assert.Equal(original.Length, decoded); - AssertExtensions.SequenceEqual(original, decodedBytes); + AssertExtensions.SequenceEqual(original.AsSpan(), decodedBytes); byte[] actualBytes = new byte[original.Length]; Assert.True(Base64Url.TryDecodeFromChars(encodedSpan, actualBytes, out int bytesWritten)); diff --git a/src/libraries/System.Memory/tests/Span/SearchValues.cs b/src/libraries/System.Memory/tests/Span/SearchValues.cs index 00e9c71e3dfb75..51c8688bfae2b9 100644 --- a/src/libraries/System.Memory/tests/Span/SearchValues.cs +++ b/src/libraries/System.Memory/tests/Span/SearchValues.cs @@ -465,7 +465,7 @@ static SearchValuesTestHelper() s_randomLatin1Chars[i] = (char)rng.Next(0, 256); } - rng.NextBytes(MemoryMarshal.Cast(s_randomChars)); + rng.NextBytes(MemoryMarshal.Cast(s_randomChars.AsSpan())); s_randomAsciiBytes = Encoding.ASCII.GetBytes(s_randomAsciiChars); diff --git a/src/libraries/System.Memory/tests/Span/StringSearchValues.cs b/src/libraries/System.Memory/tests/Span/StringSearchValues.cs index c0b80b5ab06776..f702b0bdcad99d 100644 --- a/src/libraries/System.Memory/tests/Span/StringSearchValues.cs +++ b/src/libraries/System.Memory/tests/Span/StringSearchValues.cs @@ -620,7 +620,7 @@ public StringSearchValuesTestHelper(IndexOfAnySearchDelegate expected, SearchVal })); } - rng.NextBytes(MemoryMarshal.Cast(_randomChars)); + rng.NextBytes(MemoryMarshal.Cast(_randomChars.AsSpan())); } public void StressRandomInputs(TimeSpan duration) diff --git a/src/libraries/System.Net.Sockets/tests/FunctionalTests/SocketAsyncEventArgsTest.cs b/src/libraries/System.Net.Sockets/tests/FunctionalTests/SocketAsyncEventArgsTest.cs index 9909192150ed0b..73c4ee74d18e21 100644 --- a/src/libraries/System.Net.Sockets/tests/FunctionalTests/SocketAsyncEventArgsTest.cs +++ b/src/libraries/System.Net.Sockets/tests/FunctionalTests/SocketAsyncEventArgsTest.cs @@ -728,7 +728,7 @@ public void AcceptAsync_WithReceiveBuffer_Success() Assert.Equal(acceptBufferDataSize, acceptArgs.BytesTransferred); - AssertExtensions.SequenceEqual(sendBuffer, acceptArgs.Buffer.AsSpan(0, acceptArgs.BytesTransferred)); + AssertExtensions.SequenceEqual(sendBuffer.AsSpan(), acceptArgs.Buffer.AsSpan(0, acceptArgs.BytesTransferred)); } } diff --git a/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/CollectionsMarshalTests.cs b/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/CollectionsMarshalTests.cs index 325c9a43de6303..867ee99b852e89 100644 --- a/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/CollectionsMarshalTests.cs +++ b/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/CollectionsMarshalTests.cs @@ -527,19 +527,19 @@ public void ListSetCount() CollectionsMarshal.SetCount(list, 3); Assert.Equal(3, list.Count); Assert.Throws(() => list[3]); - AssertExtensions.SequenceEqual(CollectionsMarshal.AsSpan(list), new int[] { 1, 2, 3 }); + AssertExtensions.SequenceEqual(CollectionsMarshal.AsSpan(list), new int[] { 1, 2, 3 }.AsSpan()); Assert.True(Unsafe.AreSame(ref intRef, ref MemoryMarshal.GetReference(CollectionsMarshal.AsSpan(list)))); // make sure that size increase preserves content and doesn't clear CollectionsMarshal.SetCount(list, 5); - AssertExtensions.SequenceEqual(CollectionsMarshal.AsSpan(list), new int[] { 1, 2, 3, 4, 5 }); + AssertExtensions.SequenceEqual(CollectionsMarshal.AsSpan(list), new int[] { 1, 2, 3, 4, 5 }.AsSpan()); Assert.True(Unsafe.AreSame(ref intRef, ref MemoryMarshal.GetReference(CollectionsMarshal.AsSpan(list)))); // make sure that reallocations preserve content int newCount = list.Capacity * 2; CollectionsMarshal.SetCount(list, newCount); Assert.Equal(newCount, list.Count); - AssertExtensions.SequenceEqual(CollectionsMarshal.AsSpan(list)[..3], new int[] { 1, 2, 3 }); + AssertExtensions.SequenceEqual(CollectionsMarshal.AsSpan(list)[..3], new int[] { 1, 2, 3 }.AsSpan()); Assert.True(!Unsafe.AreSame(ref intRef, ref MemoryMarshal.GetReference(CollectionsMarshal.AsSpan(list)))); List listReference = new() { "a", "b", "c", "d", "e" }; @@ -547,12 +547,12 @@ public void ListSetCount() CollectionsMarshal.SetCount(listReference, 3); // verify that reference types aren't cleared - AssertExtensions.SequenceEqual(CollectionsMarshal.AsSpan(listReference), new string[] { "a", "b", "c" }); + AssertExtensions.SequenceEqual(CollectionsMarshal.AsSpan(listReference), new string[] { "a", "b", "c" }.AsSpan()); Assert.True(Unsafe.AreSame(ref stringRef, ref MemoryMarshal.GetReference(CollectionsMarshal.AsSpan(listReference)))); CollectionsMarshal.SetCount(listReference, 5); // verify that removed reference types are cleared - AssertExtensions.SequenceEqual(CollectionsMarshal.AsSpan(listReference), new string[] { "a", "b", "c", null, null }); + AssertExtensions.SequenceEqual(CollectionsMarshal.AsSpan(listReference), new string[] { "a", "b", "c", null, null }.AsSpan()); Assert.True(Unsafe.AreSame(ref stringRef, ref MemoryMarshal.GetReference(CollectionsMarshal.AsSpan(listReference)))); } } diff --git a/src/libraries/System.Runtime.Numerics/src/System/Numerics/BigInteger.cs b/src/libraries/System.Runtime.Numerics/src/System/Numerics/BigInteger.cs index b3355ff68678ca..ee00e32b4f956e 100644 --- a/src/libraries/System.Runtime.Numerics/src/System/Numerics/BigInteger.cs +++ b/src/libraries/System.Runtime.Numerics/src/System/Numerics/BigInteger.cs @@ -384,7 +384,7 @@ public BigInteger(ReadOnlySpan value, bool isUnsigned = false, bool isBigE // The bytes parameter is in little-endian byte order. // We can just copy the bytes directly into the uint array. - value.Slice(0, wholeUInt32Count * 4).CopyTo(MemoryMarshal.AsBytes(val)); + value.Slice(0, wholeUInt32Count * 4).CopyTo(MemoryMarshal.AsBytes(val.AsSpan())); } // In both of the above cases on big-endian architecture, we need to perform diff --git a/src/libraries/System.Runtime/tests/System.IO.FileSystem.Tests/FileStream/ReadAsync.cs b/src/libraries/System.Runtime/tests/System.IO.FileSystem.Tests/FileStream/ReadAsync.cs index d31149d297c5e0..40220b45ef875a 100644 --- a/src/libraries/System.Runtime/tests/System.IO.FileSystem.Tests/FileStream/ReadAsync.cs +++ b/src/libraries/System.Runtime/tests/System.IO.FileSystem.Tests/FileStream/ReadAsync.cs @@ -123,7 +123,7 @@ public async Task IncompleteReadCantSetPositionBeyondEndOfFile(FileShare fileSha await Task.WhenAll(reads); // but when they are finished, the first buffer should contain valid data: Assert.Equal(fileSize, reads.First().Result); - AssertExtensions.SequenceEqual(content, buffers.First().AsSpan(0, fileSize)); + AssertExtensions.SequenceEqual(content.AsSpan(), buffers.First().AsSpan(0, fileSize)); // and other reads should return 0: Assert.All(reads.Skip(1), read => Assert.Equal(0, read.Result)); // and the Position must be correct: diff --git a/src/libraries/System.Runtime/tests/System.Runtime.Extensions.Tests/System/Convert.FromHexString.cs b/src/libraries/System.Runtime/tests/System.Runtime.Extensions.Tests/System/Convert.FromHexString.cs index fd8bcd6c8e05d0..643971e0163962 100644 --- a/src/libraries/System.Runtime/tests/System.Runtime.Extensions.Tests/System/Convert.FromHexString.cs +++ b/src/libraries/System.Runtime/tests/System.Runtime.Extensions.Tests/System/Convert.FromHexString.cs @@ -42,7 +42,7 @@ private static void TestSequence(byte[] expected, string actual) Assert.Equal(OperationStatus.Done, Convert.FromHexString(actual, tryResult, out int consumed, out int written)); Assert.Equal(fromResult.Length, written); Assert.Equal(actual.Length, consumed); - AssertExtensions.SequenceEqual(expected, tryResult); + AssertExtensions.SequenceEqual(expected.AsSpan(), tryResult); } [Fact] diff --git a/src/libraries/System.Runtime/tests/System.Runtime.Extensions.Tests/System/Random.cs b/src/libraries/System.Runtime/tests/System.Runtime.Extensions.Tests/System/Random.cs index f6cb50a52fc90d..057d6f0c96c12e 100644 --- a/src/libraries/System.Runtime/tests/System.Runtime.Extensions.Tests/System/Random.cs +++ b/src/libraries/System.Runtime/tests/System.Runtime.Extensions.Tests/System/Random.cs @@ -713,9 +713,9 @@ public static void Shuffle_Array_Seeded(bool emptyShuffle) Random random = new Random(0x70636A61); int[] items = new int[] { 1, 2, 3, 4 }; random.Shuffle(items); - AssertExtensions.SequenceEqual(stackalloc int[] { 4, 2, 1, 3 }, items); + AssertExtensions.SequenceEqual(stackalloc int[] { 4, 2, 1, 3 }, items.AsSpan()); random.Shuffle(items); - AssertExtensions.SequenceEqual(stackalloc int[] { 2, 3, 4, 1 }, items); + AssertExtensions.SequenceEqual(stackalloc int[] { 2, 3, 4, 1 }, items.AsSpan()); if (emptyShuffle) { @@ -724,7 +724,7 @@ public static void Shuffle_Array_Seeded(bool emptyShuffle) } random.Shuffle(items); - AssertExtensions.SequenceEqual(stackalloc int[] { 1, 4, 3, 2 }, items); + AssertExtensions.SequenceEqual(stackalloc int[] { 1, 4, 3, 2 }, items.AsSpan()); } [Fact] @@ -831,13 +831,13 @@ public static void GetItems_Buffer_Seeded_NonPower2() Span buffer = stackalloc byte[7]; random.GetItems(items, buffer); - AssertExtensions.SequenceEqual(new byte[] { 3, 1, 3, 2, 3, 3, 3 }, buffer); + AssertExtensions.SequenceEqual(new byte[] { 3, 1, 3, 2, 3, 3, 3 }.AsSpan(), buffer); random.GetItems(items, buffer); - AssertExtensions.SequenceEqual(new byte[] { 2, 1, 2, 1, 2, 3, 1 }, buffer); + AssertExtensions.SequenceEqual(new byte[] { 2, 1, 2, 1, 2, 3, 1 }.AsSpan(), buffer); random.GetItems(items, buffer); - AssertExtensions.SequenceEqual(new byte[] { 1, 1, 3, 1, 3, 2, 2 }, buffer); + AssertExtensions.SequenceEqual(new byte[] { 1, 1, 3, 1, 3, 2, 2 }.AsSpan(), buffer); } [Fact] @@ -880,13 +880,13 @@ public static void GetItems_Buffer_Seeded_Power2() Span buffer = stackalloc byte[7]; random.GetItems(items, buffer); - AssertExtensions.SequenceEqual(new byte[] { 4, 1, 4, 2, 4, 4, 4 }, buffer); + AssertExtensions.SequenceEqual(new byte[] { 4, 1, 4, 2, 4, 4, 4 }.AsSpan(), buffer); random.GetItems(items, buffer); - AssertExtensions.SequenceEqual(new byte[] { 2, 2, 3, 1, 3, 3, 1 }, buffer); + AssertExtensions.SequenceEqual(new byte[] { 2, 2, 3, 1, 3, 3, 1 }.AsSpan(), buffer); random.GetItems(items, buffer); - AssertExtensions.SequenceEqual(new byte[] { 2, 1, 4, 2, 4, 2, 2 }, buffer); + AssertExtensions.SequenceEqual(new byte[] { 2, 1, 4, 2, 4, 2, 2 }.AsSpan(), buffer); } [Theory] diff --git a/src/libraries/System.Runtime/tests/System.Text.Encoding.Tests/Ascii/CaseConversionTests.cs b/src/libraries/System.Runtime/tests/System.Text.Encoding.Tests/Ascii/CaseConversionTests.cs index ceb836ff268a41..ef06e40d1c2dfd 100644 --- a/src/libraries/System.Runtime/tests/System.Text.Encoding.Tests/Ascii/CaseConversionTests.cs +++ b/src/libraries/System.Runtime/tests/System.Text.Encoding.Tests/Ascii/CaseConversionTests.cs @@ -25,20 +25,20 @@ public static void OverlappingBuffers_Throws() Assert.Throws(() => Ascii.ToUpper(byteBuffer, byteBuffer, out _)); Assert.Throws(() => Ascii.ToUpper(byteBuffer.AsSpan(1, 3), byteBuffer.AsSpan(3, 5), out _)); // byte -> char - Assert.Throws(() => Ascii.ToLower(byteBuffer, MemoryMarshal.Cast(byteBuffer), out _)); - Assert.Throws(() => Ascii.ToLower(byteBuffer, MemoryMarshal.Cast(byteBuffer).Slice(1, 3), out _)); - Assert.Throws(() => Ascii.ToUpper(byteBuffer, MemoryMarshal.Cast(byteBuffer), out _)); - Assert.Throws(() => Ascii.ToUpper(byteBuffer, MemoryMarshal.Cast(byteBuffer).Slice(1, 3), out _)); + Assert.Throws(() => Ascii.ToLower(byteBuffer, MemoryMarshal.Cast(byteBuffer.AsSpan()), out _)); + Assert.Throws(() => Ascii.ToLower(byteBuffer, MemoryMarshal.Cast(byteBuffer.AsSpan()).Slice(1, 3), out _)); + Assert.Throws(() => Ascii.ToUpper(byteBuffer, MemoryMarshal.Cast(byteBuffer.AsSpan()), out _)); + Assert.Throws(() => Ascii.ToUpper(byteBuffer, MemoryMarshal.Cast(byteBuffer.AsSpan()).Slice(1, 3), out _)); // char -> char Assert.Throws(() => Ascii.ToLower(charBuffer, charBuffer, out _)); Assert.Throws(() => Ascii.ToLower(charBuffer.AsSpan(1, 3), charBuffer.AsSpan(3, 5), out _)); Assert.Throws(() => Ascii.ToUpper(charBuffer, charBuffer, out _)); Assert.Throws(() => Ascii.ToUpper(charBuffer.AsSpan(1, 3), charBuffer.AsSpan(3, 5), out _)); // char -> byte - Assert.Throws(() => Ascii.ToLower(charBuffer, MemoryMarshal.Cast(charBuffer), out _)); - Assert.Throws(() => Ascii.ToLower(charBuffer, MemoryMarshal.Cast(charBuffer).Slice(1, 3), out _)); - Assert.Throws(() => Ascii.ToUpper(charBuffer, MemoryMarshal.Cast(charBuffer), out _)); - Assert.Throws(() => Ascii.ToUpper(charBuffer, MemoryMarshal.Cast(charBuffer).Slice(1, 3), out _)); + Assert.Throws(() => Ascii.ToLower(charBuffer, MemoryMarshal.Cast(charBuffer.AsSpan()), out _)); + Assert.Throws(() => Ascii.ToLower(charBuffer, MemoryMarshal.Cast(charBuffer.AsSpan()).Slice(1, 3), out _)); + Assert.Throws(() => Ascii.ToUpper(charBuffer, MemoryMarshal.Cast(charBuffer.AsSpan()), out _)); + Assert.Throws(() => Ascii.ToUpper(charBuffer, MemoryMarshal.Cast(charBuffer.AsSpan()).Slice(1, 3), out _)); } private static void VerifySingleChar(OperationStatus status, int value, T expected, T actual, int written) diff --git a/src/libraries/System.Security.Cryptography.Cose/tests/CoseHeaderValueTests.cs b/src/libraries/System.Security.Cryptography.Cose/tests/CoseHeaderValueTests.cs index b01cbc953177c4..2d7c891fecf4e6 100644 --- a/src/libraries/System.Security.Cryptography.Cose/tests/CoseHeaderValueTests.cs +++ b/src/libraries/System.Security.Cryptography.Cose/tests/CoseHeaderValueTests.cs @@ -97,7 +97,7 @@ public void GetValueAsBytesSucceeds(ContentTestCase @case) Span buffer = new byte[content.Length]; int length = headerValue.GetValueAsBytes(buffer); Assert.Equal(content.Length, length); - AssertExtensions.SequenceEqual(content, buffer); + AssertExtensions.SequenceEqual(content.AsSpan(), buffer); } [Theory] @@ -138,7 +138,7 @@ void Verify(int repetitions) for (int i = 0; i < expectedLength; i+= content.Length) { - AssertExtensions.SequenceEqual(content, buffer.Slice(i, content.Length)); + AssertExtensions.SequenceEqual(content.AsSpan(), buffer.Slice(i, content.Length)); } } } @@ -244,7 +244,7 @@ public void FromBytesSucceeds(ContentTestCase @case) Span buffer = new byte[content.Length]; int length = headerValue.GetValueAsBytes(buffer); - AssertExtensions.SequenceEqual(content, buffer); + AssertExtensions.SequenceEqual(content.AsSpan(), buffer); Assert.Equal(content.Length, length); } diff --git a/src/libraries/System.Security.Cryptography.ProtectedData/tests/SpanProtectedDataTests.cs b/src/libraries/System.Security.Cryptography.ProtectedData/tests/SpanProtectedDataTests.cs index e626a4ce9301be..e1cfc029ea66b9 100644 --- a/src/libraries/System.Security.Cryptography.ProtectedData/tests/SpanProtectedDataTests.cs +++ b/src/libraries/System.Security.Cryptography.ProtectedData/tests/SpanProtectedDataTests.cs @@ -42,7 +42,7 @@ public void ZeroBufferThrows() public void NearCorrectSizeBufferTests(int delta, bool success) { byte[] buffer = new byte[DefaultProtectedBufferSize]; - int original = ProtectedData.Protect([1, 2, 3], DataProtectionScope.CurrentUser, buffer); + int original = ProtectedData.Protect([1, 2, 3], DataProtectionScope.CurrentUser, buffer.AsSpan()); if (success) { diff --git a/src/libraries/System.Security.Cryptography/tests/HashAlgorithmTestDriver.cs b/src/libraries/System.Security.Cryptography/tests/HashAlgorithmTestDriver.cs index bbcf23ec0e596e..53e6839c5eee42 100644 --- a/src/libraries/System.Security.Cryptography/tests/HashAlgorithmTestDriver.cs +++ b/src/libraries/System.Security.Cryptography/tests/HashAlgorithmTestDriver.cs @@ -66,7 +66,7 @@ private void VerifyOneShotStream(Stream input, string output) Span buffer = stackalloc byte[512 / 8]; int written = HashData(input, buffer); - AssertExtensions.SequenceEqual(expected, buffer.Slice(0, written)); + AssertExtensions.SequenceEqual(expected.AsSpan(), buffer.Slice(0, written)); } private async Task VerifyOneShotStreamAsync(Stream input, string output) @@ -75,7 +75,7 @@ private async Task VerifyOneShotStreamAsync(Stream input, string output) Memory buffer = new byte[512 / 8]; int written = await HashDataAsync(input, buffer, cancellationToken: default); - AssertExtensions.SequenceEqual(expected, buffer.Slice(0, written).Span); + AssertExtensions.SequenceEqual(expected.AsSpan(), buffer.Slice(0, written).Span); } private void VerifyOneShotAllocatingStream(Stream input, string output) @@ -100,7 +100,7 @@ private void VerifyOneShotStream_CryptographicOperations(Stream input, string ou Span buffer = stackalloc byte[512 / 8]; int written = CryptographicOperations.HashData(HashAlgorithm, input, buffer); - AssertExtensions.SequenceEqual(expected, buffer.Slice(0, written)); + AssertExtensions.SequenceEqual(expected.AsSpan(), buffer.Slice(0, written)); } private async Task VerifyOneShotStreamAsync_CryptographicOperations(Stream input, string output) @@ -114,7 +114,7 @@ private async Task VerifyOneShotStreamAsync_CryptographicOperations(Stream input buffer, cancellationToken: default); - AssertExtensions.SequenceEqual(expected, buffer.Slice(0, written).Span); + AssertExtensions.SequenceEqual(expected.AsSpan(), buffer.Slice(0, written).Span); } private void VerifyOneShotAllocatingStream_CryptographicOperations(Stream input, string output) diff --git a/src/libraries/System.Security.Cryptography/tests/HmacTests.cs b/src/libraries/System.Security.Cryptography/tests/HmacTests.cs index 75a36fba2e879e..a2d649fb3d960a 100644 --- a/src/libraries/System.Security.Cryptography/tests/HmacTests.cs +++ b/src/libraries/System.Security.Cryptography/tests/HmacTests.cs @@ -136,7 +136,7 @@ protected void VerifyHashDataStream(ReadOnlySpan key, Stream stream, strin int written = HashDataOneShot(key, stream, destination); Assert.Equal(MacSize, written); - AssertExtensions.SequenceEqual(expected, destination); + AssertExtensions.SequenceEqual(expected.AsSpan(), destination); } protected void VerifyHashDataStream_CryptographicOperations(ReadOnlySpan key, Stream stream, string output) @@ -146,7 +146,7 @@ protected void VerifyHashDataStream_CryptographicOperations(ReadOnlySpan k int written = CryptographicOperations.HmacData(HashAlgorithm, key, stream, destination); Assert.Equal(MacSize, written); - AssertExtensions.SequenceEqual(expected, destination); + AssertExtensions.SequenceEqual(expected.AsSpan(), destination); } protected async Task VerifyHashDataStreamAsync(ReadOnlyMemory key, Stream stream, string output) @@ -156,7 +156,7 @@ protected async Task VerifyHashDataStreamAsync(ReadOnlyMemory key, Stream int written = await HashDataOneShotAsync(key, stream, destination, cancellationToken: default); Assert.Equal(MacSize, written); - AssertExtensions.SequenceEqual(expected, destination.Span); + AssertExtensions.SequenceEqual(expected.AsSpan(), destination.Span); } protected async Task VerifyHashDataStreamAsync_CryptographicOperations(ReadOnlyMemory key, Stream stream, string output) @@ -171,7 +171,7 @@ protected async Task VerifyHashDataStreamAsync_CryptographicOperations(ReadOnlyM cancellationToken: default); Assert.Equal(MacSize, written); - AssertExtensions.SequenceEqual(expected, destination.Span); + AssertExtensions.SequenceEqual(expected.AsSpan(), destination.Span); } protected void VerifyHashDataStreamAllocating(byte[] key, Stream stream, string output, bool spanKey) diff --git a/src/libraries/System.Security.Cryptography/tests/KmacTestDriver.cs b/src/libraries/System.Security.Cryptography/tests/KmacTestDriver.cs index b508acacc1d6d5..4d7c10b317add9 100644 --- a/src/libraries/System.Security.Cryptography/tests/KmacTestDriver.cs +++ b/src/libraries/System.Security.Cryptography/tests/KmacTestDriver.cs @@ -500,7 +500,7 @@ public void GetHashAndReset_ResetWithEmpty() mac = stackalloc byte[OutputLength]; TKmacTrait.AppendData(kmac, "habaneros"u8); TKmacTrait.GetHashAndReset(kmac, mac); - AssertExtensions.SequenceEqual(expected, mac); + AssertExtensions.SequenceEqual(expected.AsSpan(), mac); } } diff --git a/src/libraries/System.Security.Cryptography/tests/X509Certificates/ExtensionsTests/AuthorityKeyIdentifierTests.cs b/src/libraries/System.Security.Cryptography/tests/X509Certificates/ExtensionsTests/AuthorityKeyIdentifierTests.cs index 520d52cbc85123..326491ac53b7f8 100644 --- a/src/libraries/System.Security.Cryptography/tests/X509Certificates/ExtensionsTests/AuthorityKeyIdentifierTests.cs +++ b/src/libraries/System.Security.Cryptography/tests/X509Certificates/ExtensionsTests/AuthorityKeyIdentifierTests.cs @@ -477,7 +477,7 @@ public static void CreateFromLargeKeyIdentifier() byte[] rawData = akid.RawData; - AssertExtensions.SequenceEqual(keyId, rawData.AsSpan(6)); + AssertExtensions.SequenceEqual(keyId.AsSpan(), rawData.AsSpan(6)); Assert.Equal("308183808180", rawData.AsSpan(0, 6).ByteArrayToHex()); } diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Document/JsonDocument.MetadataDb.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Document/JsonDocument.MetadataDb.cs index dca61c889c89d8..20cdf3775c0a43 100644 --- a/src/libraries/System.Text.Json/src/System/Text/Json/Document/JsonDocument.MetadataDb.cs +++ b/src/libraries/System.Text.Json/src/System/Text/Json/Document/JsonDocument.MetadataDb.cs @@ -381,7 +381,7 @@ internal MetadataDb CopySegment(int startIndex, int endIndex) byte[] newDatabase = new byte[length]; _data.AsSpan(startIndex, length).CopyTo(newDatabase); - Span newDbInts = MemoryMarshal.Cast(newDatabase); + Span newDbInts = MemoryMarshal.Cast(newDatabase.AsSpan()); int locationOffset = newDbInts[0]; // Need to nudge one forward to account for the hidden quote on the string. diff --git a/src/libraries/System.Text.Json/tests/Common/CollectionTests/CollectionTests.Memory.cs b/src/libraries/System.Text.Json/tests/Common/CollectionTests/CollectionTests.Memory.cs index 58525300624be0..b99428c39c7d6c 100644 --- a/src/libraries/System.Text.Json/tests/Common/CollectionTests/CollectionTests.Memory.cs +++ b/src/libraries/System.Text.Json/tests/Common/CollectionTests/CollectionTests.Memory.cs @@ -34,7 +34,7 @@ public async Task SerializeReadOnlyMemoryOfTAsync() public async Task DeserializeMemoryOfTAsync() { Memory memoryInt = await Serializer.DeserializeWrapper>("[1,2,3]"); - AssertExtensions.SequenceEqual(new int[] { 1, 2, 3 }, memoryInt.Span); + AssertExtensions.SequenceEqual(new int[] { 1, 2, 3 }.AsSpan(), memoryInt.Span); Memory memoryPoco = new EmptyClass[] { new(), new(), new() }.AsMemory(); Assert.Equal(3, memoryPoco.Length); @@ -75,7 +75,7 @@ public async Task DeserializeMemoryOfTClassAsync() { string json = @"{""Memory"":[1,2,3]}"; MemoryOfTClass memoryOfIntClass = await Serializer.DeserializeWrapper>(json); - AssertExtensions.SequenceEqual(new int[] { 1, 2, 3 }, memoryOfIntClass.Memory.Span); + AssertExtensions.SequenceEqual(new int[] { 1, 2, 3 }.AsSpan(), memoryOfIntClass.Memory.Span); } [Fact] @@ -97,7 +97,7 @@ public async Task SerializeMemoryByteAsync() public async Task DeserializeMemoryByteAsync() { Memory memory = await Serializer.DeserializeWrapper>("\"VGhpcyBpcyBzb21lIHRlc3QgZGF0YSEhIQ==\""); - AssertExtensions.SequenceEqual(s_testData, memory.Span); + AssertExtensions.SequenceEqual(s_testData.AsSpan(), memory.Span); ReadOnlyMemory readOnlyMemory = await Serializer.DeserializeWrapper>("\"VGhpcyBpcyBzb21lIHRlc3QgZGF0YSEhIQ==\""); AssertExtensions.SequenceEqual(s_testData, readOnlyMemory.Span); @@ -135,7 +135,7 @@ public async Task DeserializeMemoryByteClassAsync() string json = @"{""Memory"":""VGhpcyBpcyBzb21lIHRlc3QgZGF0YSEhIQ==""}"; MemoryOfTClass memoryOfByteClass = await Serializer.DeserializeWrapper>(json); - AssertExtensions.SequenceEqual(s_testData, memoryOfByteClass.Memory.Span); + AssertExtensions.SequenceEqual(s_testData.AsSpan(), memoryOfByteClass.Memory.Span); } } }