Skip to content

Commit 3a7a63b

Browse files
committed
Use explicit AsSpan
1 parent 1012c0d commit 3a7a63b

File tree

23 files changed

+57
-57
lines changed

23 files changed

+57
-57
lines changed

src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/ReachabilityInstrumentationFilter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public ReachabilityInstrumentationFilter(string profileDataFileName, ILProvider
4444
int numTokens = reader.ReadInt32();
4545

4646
bool[] tokenStates = new bool[numTokens];
47-
if (reader.Read(MemoryMarshal.Cast<bool, byte>(tokenStates)) != numTokens)
47+
if (reader.Read(MemoryMarshal.Cast<bool, byte>(tokenStates.AsSpan())) != numTokens)
4848
throw new IOException("Unexpected end of file");
4949

5050
_reachabilityInfo.Add(new Guid(guidBytes), tokenStates);

src/libraries/Common/tests/StreamConformanceTests/System/IO/StreamConformanceTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1915,7 +1915,7 @@ public virtual async Task ReadWrite_MessagesSmallerThanReadBuffer_Success(ReadWr
19151915
}
19161916

19171917
Assert.Equal(writerBytes.Length, n);
1918-
AssertExtensions.SequenceEqual(writerBytes, readerBytes.AsSpan(0, writerBytes.Length));
1918+
AssertExtensions.SequenceEqual(writerBytes.AsSpan(), readerBytes.AsSpan(0, writerBytes.Length));
19191919

19201920
await writes;
19211921
}
@@ -3069,7 +3069,7 @@ public virtual async Task ZeroByteRead_PerformsZeroByteReadOnUnderlyingStreamWhe
30693069

30703070
if (FlushGuaranteesAllDataWritten)
30713071
{
3072-
AssertExtensions.SequenceEqual(data, buffer.AsSpan(0, bytesRead));
3072+
AssertExtensions.SequenceEqual(data.AsSpan(), buffer.AsSpan(0, bytesRead));
30733073
}
30743074
}
30753075
}

src/libraries/System.Formats.Nrbf/src/System/Formats/Nrbf/ArraySinglePrimitiveRecord.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ internal static IReadOnlyList<T> DecodePrimitiveTypes(BinaryReader reader, int c
161161
{
162162
if (typeof(T) == typeof(short) || typeof(T) == typeof(ushort))
163163
{
164-
Span<short> span = MemoryMarshal.Cast<T, short>(result);
164+
Span<short> span = MemoryMarshal.Cast<T, short>(result.AsSpan());
165165
#if NET
166166
BinaryPrimitives.ReverseEndianness(span, span);
167167
#else
@@ -173,7 +173,7 @@ internal static IReadOnlyList<T> DecodePrimitiveTypes(BinaryReader reader, int c
173173
}
174174
else if (typeof(T) == typeof(int) || typeof(T) == typeof(uint) || typeof(T) == typeof(float))
175175
{
176-
Span<int> span = MemoryMarshal.Cast<T, int>(result);
176+
Span<int> span = MemoryMarshal.Cast<T, int>(result.AsSpan());
177177
#if NET
178178
BinaryPrimitives.ReverseEndianness(span, span);
179179
#else
@@ -185,7 +185,7 @@ internal static IReadOnlyList<T> DecodePrimitiveTypes(BinaryReader reader, int c
185185
}
186186
else if (typeof(T) == typeof(long) || typeof(T) == typeof(ulong) || typeof(T) == typeof(double))
187187
{
188-
Span<long> span = MemoryMarshal.Cast<T, long>(result);
188+
Span<long> span = MemoryMarshal.Cast<T, long>(result.AsSpan());
189189
#if NET
190190
BinaryPrimitives.ReverseEndianness(span, span);
191191
#else
@@ -201,7 +201,7 @@ internal static IReadOnlyList<T> DecodePrimitiveTypes(BinaryReader reader, int c
201201
{
202202
// See DontCastBytesToBooleans test to see what could go wrong.
203203
bool[] booleans = (bool[])(object)result;
204-
Span<byte> resultAsBytes = MemoryMarshal.AsBytes<T>(result);
204+
Span<byte> resultAsBytes = MemoryMarshal.AsBytes<T>(result.AsSpan());
205205
for (int i = 0; i < booleans.Length; i++)
206206
{
207207
// We don't use the bool array to get the value, as an optimizing compiler or JIT could elide this.

src/libraries/System.Linq/tests/RangeTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ static void Validate(IEnumerable<int> e, int[] expected)
270270
list.CopyTo(actual, 1);
271271
Assert.Equal(0, actual[0]);
272272
Assert.Equal(0, actual[^1]);
273-
AssertExtensions.SequenceEqual(expected, actual.AsSpan(1, expected.Length));
273+
AssertExtensions.SequenceEqual(expected.AsSpan(), actual.AsSpan(1, expected.Length));
274274
}
275275
}
276276
}

src/libraries/System.Linq/tests/RepeatTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ static void Validate(IEnumerable<int> e, int[] expected)
282282
list.CopyTo(actual, 1);
283283
Assert.Equal(0, actual[0]);
284284
Assert.Equal(0, actual[^1]);
285-
AssertExtensions.SequenceEqual(expected, actual.AsSpan(1, expected.Length));
285+
AssertExtensions.SequenceEqual(expected.AsSpan(), actual.AsSpan(1, expected.Length));
286286
}
287287
}
288288
}

src/libraries/System.Memory/tests/Base64Url/Base64UrlUnicodeAPIsUnitTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,7 @@ public static void Base64_AllMethodsRoundtripConsistently()
438438
Span<byte> decodedBytes = new byte[original.Length];
439439
int decoded = Base64Url.DecodeFromChars(encodedArray, decodedBytes);
440440
Assert.Equal(original.Length, decoded);
441-
AssertExtensions.SequenceEqual(original, decodedBytes);
441+
AssertExtensions.SequenceEqual(original.AsSpan(), decodedBytes);
442442

443443
byte[] actualBytes = new byte[original.Length];
444444
Assert.True(Base64Url.TryDecodeFromChars(encodedSpan, actualBytes, out int bytesWritten));

src/libraries/System.Memory/tests/Span/SearchValues.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,7 @@ static SearchValuesTestHelper()
465465
s_randomLatin1Chars[i] = (char)rng.Next(0, 256);
466466
}
467467

468-
rng.NextBytes(MemoryMarshal.Cast<char, byte>(s_randomChars));
468+
rng.NextBytes(MemoryMarshal.Cast<char, byte>(s_randomChars.AsSpan()));
469469

470470
s_randomAsciiBytes = Encoding.ASCII.GetBytes(s_randomAsciiChars);
471471

src/libraries/System.Memory/tests/Span/StringSearchValues.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -620,7 +620,7 @@ public StringSearchValuesTestHelper(IndexOfAnySearchDelegate expected, SearchVal
620620
}));
621621
}
622622

623-
rng.NextBytes(MemoryMarshal.Cast<char, byte>(_randomChars));
623+
rng.NextBytes(MemoryMarshal.Cast<char, byte>(_randomChars.AsSpan()));
624624
}
625625

626626
public void StressRandomInputs(TimeSpan duration)

src/libraries/System.Net.Sockets/tests/FunctionalTests/SocketAsyncEventArgsTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -728,7 +728,7 @@ public void AcceptAsync_WithReceiveBuffer_Success()
728728

729729
Assert.Equal(acceptBufferDataSize, acceptArgs.BytesTransferred);
730730

731-
AssertExtensions.SequenceEqual(sendBuffer, acceptArgs.Buffer.AsSpan(0, acceptArgs.BytesTransferred));
731+
AssertExtensions.SequenceEqual(sendBuffer.AsSpan(), acceptArgs.Buffer.AsSpan(0, acceptArgs.BytesTransferred));
732732
}
733733
}
734734

src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/CollectionsMarshalTests.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -527,32 +527,32 @@ public void ListSetCount()
527527
CollectionsMarshal.SetCount(list, 3);
528528
Assert.Equal(3, list.Count);
529529
Assert.Throws<ArgumentOutOfRangeException>(() => list[3]);
530-
AssertExtensions.SequenceEqual(CollectionsMarshal.AsSpan(list), new int[] { 1, 2, 3 });
530+
AssertExtensions.SequenceEqual(CollectionsMarshal.AsSpan(list), new int[] { 1, 2, 3 }.AsSpan());
531531
Assert.True(Unsafe.AreSame(ref intRef, ref MemoryMarshal.GetReference(CollectionsMarshal.AsSpan(list))));
532532

533533
// make sure that size increase preserves content and doesn't clear
534534
CollectionsMarshal.SetCount(list, 5);
535-
AssertExtensions.SequenceEqual(CollectionsMarshal.AsSpan(list), new int[] { 1, 2, 3, 4, 5 });
535+
AssertExtensions.SequenceEqual(CollectionsMarshal.AsSpan(list), new int[] { 1, 2, 3, 4, 5 }.AsSpan());
536536
Assert.True(Unsafe.AreSame(ref intRef, ref MemoryMarshal.GetReference(CollectionsMarshal.AsSpan(list))));
537537

538538
// make sure that reallocations preserve content
539539
int newCount = list.Capacity * 2;
540540
CollectionsMarshal.SetCount(list, newCount);
541541
Assert.Equal(newCount, list.Count);
542-
AssertExtensions.SequenceEqual(CollectionsMarshal.AsSpan(list)[..3], new int[] { 1, 2, 3 });
542+
AssertExtensions.SequenceEqual(CollectionsMarshal.AsSpan(list)[..3], new int[] { 1, 2, 3 }.AsSpan());
543543
Assert.True(!Unsafe.AreSame(ref intRef, ref MemoryMarshal.GetReference(CollectionsMarshal.AsSpan(list))));
544544

545545
List<string> listReference = new() { "a", "b", "c", "d", "e" };
546546
ref string stringRef = ref MemoryMarshal.GetReference(CollectionsMarshal.AsSpan(listReference));
547547
CollectionsMarshal.SetCount(listReference, 3);
548548

549549
// verify that reference types aren't cleared
550-
AssertExtensions.SequenceEqual(CollectionsMarshal.AsSpan(listReference), new string[] { "a", "b", "c" });
550+
AssertExtensions.SequenceEqual(CollectionsMarshal.AsSpan(listReference), new string[] { "a", "b", "c" }.AsSpan());
551551
Assert.True(Unsafe.AreSame(ref stringRef, ref MemoryMarshal.GetReference(CollectionsMarshal.AsSpan(listReference))));
552552
CollectionsMarshal.SetCount(listReference, 5);
553553

554554
// verify that removed reference types are cleared
555-
AssertExtensions.SequenceEqual(CollectionsMarshal.AsSpan(listReference), new string[] { "a", "b", "c", null, null });
555+
AssertExtensions.SequenceEqual(CollectionsMarshal.AsSpan(listReference), new string[] { "a", "b", "c", null, null }.AsSpan());
556556
Assert.True(Unsafe.AreSame(ref stringRef, ref MemoryMarshal.GetReference(CollectionsMarshal.AsSpan(listReference))));
557557
}
558558
}

0 commit comments

Comments
 (0)