提交 3274fc4e 编写于 作者: A Ahson Khan 提交者: GitHub

Collapse leftover AsSpan().Slice(...) into AsSpan(...) (dotnet/corefx#29078)



Commit migrated from https://github.com/dotnet/corefx/commit/5c01da951f57ad69d64a5d7c7357d4f033cb5fea
上级 18dea2e6
......@@ -836,7 +836,7 @@ private static async Task<byte[]> InternalReadAllBytesUnknownLengthAsync(FileStr
int n = await fs.ReadAsync(rentedArray.AsMemory(bytesRead), cancellationToken).ConfigureAwait(false);
if (n == 0)
{
return rentedArray.AsSpan().Slice(0, bytesRead).ToArray();
return rentedArray.AsSpan(0, bytesRead).ToArray();
}
bytesRead += n;
}
......
......@@ -31,7 +31,7 @@ public static void TestAlignedForwards()
{
int[] a = new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19 };
ReadOnlySpan<int> source = a.AsSpan().Slice(7, 5);
ReadOnlySpan<int> source = a.AsSpan(7, 5);
Span<int> expected = new int[a.Length].AsSpan(i, 5);
Span<int> actual = a.AsSpan(i, 5);
......@@ -93,7 +93,7 @@ public static void TestAlignedBackwards()
{
int[] a = new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19 };
ReadOnlySpan<int> source = a.AsSpan().Slice(7, 5);
ReadOnlySpan<int> source = a.AsSpan(7, 5);
Span<int> expected = new int[a.Length].AsSpan(i, 5);
Span<int> actual = a.AsSpan(i, 5);
......
......@@ -31,7 +31,7 @@ public static void TestAlignedForwards()
{
int[] a = new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19 };
Span<int> source = a.AsSpan().Slice(7, 5);
Span<int> source = a.AsSpan(7, 5);
Span<int> expected = new int[a.Length].AsSpan(i, 5);
Span<int> actual = a.AsSpan(i, 5);
......@@ -93,7 +93,7 @@ public static void TestAlignedBackwards()
{
int[] a = new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19 };
Span<int> source = a.AsSpan().Slice(7, 5);
Span<int> source = a.AsSpan(7, 5);
Span<int> expected = new int[a.Length].AsSpan(i, 5);
Span<int> actual = a.AsSpan(i, 5);
......@@ -138,7 +138,7 @@ public static void SizeOf1Overlaps()
{
byte[] a = new byte[16];
Assert.True(a.AsSpan().Slice(0, 12).Overlaps(a.AsSpan().Slice(8, 8), out int elementOffset));
Assert.True(a.AsSpan(0, 12).Overlaps(a.AsSpan(8, 8), out int elementOffset));
Assert.Equal(8, elementOffset);
}
......@@ -147,7 +147,7 @@ public static void SizeOf16Overlaps()
{
Guid[] a = new Guid[16];
Assert.True(a.AsSpan().Slice(0, 12).Overlaps(a.AsSpan().Slice(8, 8), out int elementOffset));
Assert.True(a.AsSpan(0, 12).Overlaps(a.AsSpan(8, 8), out int elementOffset));
Assert.Equal(8, elementOffset);
}
......
......@@ -227,7 +227,7 @@ private static Uri GetUriFromString(string value)
else
{
host = value.Substring(0, separatorIndex);
if (!UInt16.TryParse(value.AsSpan().Slice(separatorIndex + 1), out port))
if (!UInt16.TryParse(value.AsSpan(separatorIndex + 1), out port))
{
return null;
}
......
......@@ -448,7 +448,7 @@ public static void CopyTo(string s, int sourceIndex, int destinationIndex, int c
Assert.Equal(expected, dst);
Span<char> dstSpan = new char[expected.Length];
s.AsSpan().Slice(sourceIndex, count).CopyTo(dstSpan.Slice(destinationIndex, count));
s.AsSpan(sourceIndex, count).CopyTo(dstSpan.Slice(destinationIndex, count));
Assert.Equal(expected, dstSpan.ToArray());
}
......@@ -2608,11 +2608,11 @@ public static void Substring(string s, int startIndex, int length, string expect
if (startIndex + length == s.Length)
{
Assert.Equal(expected, s.Substring(startIndex));
Assert.Equal(expected, s.AsSpan().Slice(startIndex).ToString());
Assert.Equal(expected, s.AsSpan(startIndex).ToString());
}
Assert.Equal(expected, s.Substring(startIndex, length));
Assert.Equal(expected, s.AsSpan().Slice(startIndex, length).ToString());
Assert.Equal(expected, s.AsSpan(startIndex, length).ToString());
}
[Fact]
......
......@@ -542,7 +542,7 @@ public static void TryCopyBMPStringBytes_Success_CER_MaxPrimitiveLength()
Assert.Equal(1000, bytesWritten);
Assert.Equal(
input.AsSpan().Slice(4).ByteArrayToHex(),
input.AsSpan(4).ByteArrayToHex(),
output.ByteArrayToHex());
}
......
......@@ -247,7 +247,7 @@ public static void TryCopyBitStringBytes_Fails(PublicEncodingRules ruleSet, stri
Assert.True(didRead, "reader.TryCopyBitStringBytes");
Assert.Equal(expectedUnusedBitCount, unusedBitCount);
Assert.Equal(expectedHex, output.AsSpan().Slice(0, bytesWritten).ByteArrayToHex());
Assert.Equal(expectedHex, output.AsSpan(0, bytesWritten).ByteArrayToHex());
}
private static void TryCopyBitStringBytes_Throws(
......@@ -453,7 +453,7 @@ public static void TryCopyBitStringBytes_Success_CER_MaxPrimitiveLength()
Assert.Equal(999, bytesWritten);
Assert.Equal(
input.AsSpan().Slice(5).ByteArrayToHex(),
input.AsSpan(5).ByteArrayToHex(),
output.ByteArrayToHex());
}
......
......@@ -506,7 +506,7 @@ public static void TryCopyIA5StringBytes_Success_CER_MaxPrimitiveLength()
Assert.Equal(1000, bytesWritten);
Assert.Equal(
input.AsSpan().Slice(4).ByteArrayToHex(),
input.AsSpan(4).ByteArrayToHex(),
output.ByteArrayToHex());
}
......
......@@ -204,7 +204,7 @@ public static void TryCopyOctetStringBytes_Fails(PublicEncodingRules ruleSet, st
out int bytesWritten);
Assert.True(didRead, "reader.TryCopyOctetStringBytes");
Assert.Equal(expectedHex, output.AsSpan().Slice(0, bytesWritten).ByteArrayToHex());
Assert.Equal(expectedHex, output.AsSpan(0, bytesWritten).ByteArrayToHex());
}
private static void TryCopyOctetStringBytes_Throws(
......@@ -359,7 +359,7 @@ public static void TryCopyOctetStringBytes_Success_CER_MaxPrimitiveLength()
Assert.Equal(1000, bytesWritten);
Assert.Equal(
input.AsSpan().Slice(4).ByteArrayToHex(),
input.AsSpan(4).ByteArrayToHex(),
output.ByteArrayToHex());
}
......
......@@ -522,7 +522,7 @@ public static void TryCopyUTF8StringBytes_Success_CER_MaxPrimitiveLength()
Assert.Equal(1000, bytesWritten);
Assert.Equal(
input.AsSpan().Slice(4).ByteArrayToHex(),
input.AsSpan(4).ByteArrayToHex(),
output.ByteArrayToHex());
}
......
......@@ -266,7 +266,7 @@ public static void WriteMicrosoftDotComCert()
"C058767D1FF060A609D7E3D4317079AF0CD0A8A49251AB129157F9894A036487" +
"090807060504030201").HexToByteArray();
writer.WriteBitString(containsSignature.AsSpan().Slice(9, 256));
writer.WriteBitString(containsSignature.AsSpan(9, 256));
// certificate
writer.PopSequence();
......
......@@ -372,8 +372,8 @@ private void VerifyWrite_CERSegmented(AsnWriter writer, string tagHex, int conte
byte[] encoded = writer.Encode();
Assert.Equal(tagHex, encoded.AsSpan().Slice(0, tagHex.Length / 2).ByteArrayToHex());
Assert.Equal("0000", encoded.AsSpan().Slice(encoded.Length - 2).ByteArrayToHex());
Assert.Equal(tagHex, encoded.AsSpan(0, tagHex.Length / 2).ByteArrayToHex());
Assert.Equal("0000", encoded.AsSpan(encoded.Length - 2).ByteArrayToHex());
Assert.Equal(encodedSize, encoded.Length);
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册