From 3274fc4e6f706f8658f2cdaf6dd85160c02b43d1 Mon Sep 17 00:00:00 2001 From: Ahson Khan Date: Thu, 12 Apr 2018 22:40:43 -0700 Subject: [PATCH] Collapse leftover AsSpan().Slice(...) into AsSpan(...) (dotnet/corefx#29078) Commit migrated from https://github.com/dotnet/corefx/commit/5c01da951f57ad69d64a5d7c7357d4f033cb5fea --- src/libraries/System.IO.FileSystem/src/System/IO/File.cs | 2 +- .../System.Memory/tests/ReadOnlySpan/Overlaps.cs | 4 ++-- src/libraries/System.Memory/tests/Span/Overlaps.cs | 8 ++++---- .../Net/Http/SocketsHttpHandler/HttpEnvironmentProxy.cs | 2 +- src/libraries/System.Runtime/tests/System/StringTests.cs | 6 +++--- .../tests/Asn1/Reader/ReadBMPString.cs | 2 +- .../tests/Asn1/Reader/ReadBitString.cs | 4 ++-- .../tests/Asn1/Reader/ReadIA5String.cs | 2 +- .../tests/Asn1/Reader/ReadOctetString.cs | 4 ++-- .../tests/Asn1/Reader/ReadUTF8String.cs | 2 +- .../tests/Asn1/Writer/ComprehensiveWriteTest.cs | 2 +- .../tests/Asn1/Writer/WriteCharacterString.cs | 4 ++-- 12 files changed, 21 insertions(+), 21 deletions(-) diff --git a/src/libraries/System.IO.FileSystem/src/System/IO/File.cs b/src/libraries/System.IO.FileSystem/src/System/IO/File.cs index d2486b8f0de..2225e2df4d0 100644 --- a/src/libraries/System.IO.FileSystem/src/System/IO/File.cs +++ b/src/libraries/System.IO.FileSystem/src/System/IO/File.cs @@ -836,7 +836,7 @@ private static async Task 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; } diff --git a/src/libraries/System.Memory/tests/ReadOnlySpan/Overlaps.cs b/src/libraries/System.Memory/tests/ReadOnlySpan/Overlaps.cs index 937fb11b975..150cf90f003 100644 --- a/src/libraries/System.Memory/tests/ReadOnlySpan/Overlaps.cs +++ b/src/libraries/System.Memory/tests/ReadOnlySpan/Overlaps.cs @@ -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 source = a.AsSpan().Slice(7, 5); + ReadOnlySpan source = a.AsSpan(7, 5); Span expected = new int[a.Length].AsSpan(i, 5); Span 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 source = a.AsSpan().Slice(7, 5); + ReadOnlySpan source = a.AsSpan(7, 5); Span expected = new int[a.Length].AsSpan(i, 5); Span actual = a.AsSpan(i, 5); diff --git a/src/libraries/System.Memory/tests/Span/Overlaps.cs b/src/libraries/System.Memory/tests/Span/Overlaps.cs index 02a4720ee66..ce85c95c827 100644 --- a/src/libraries/System.Memory/tests/Span/Overlaps.cs +++ b/src/libraries/System.Memory/tests/Span/Overlaps.cs @@ -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 source = a.AsSpan().Slice(7, 5); + Span source = a.AsSpan(7, 5); Span expected = new int[a.Length].AsSpan(i, 5); Span 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 source = a.AsSpan().Slice(7, 5); + Span source = a.AsSpan(7, 5); Span expected = new int[a.Length].AsSpan(i, 5); Span 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); } diff --git a/src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/HttpEnvironmentProxy.cs b/src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/HttpEnvironmentProxy.cs index 85d933dfd9a..5f46cfe8ab5 100644 --- a/src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/HttpEnvironmentProxy.cs +++ b/src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/HttpEnvironmentProxy.cs @@ -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; } diff --git a/src/libraries/System.Runtime/tests/System/StringTests.cs b/src/libraries/System.Runtime/tests/System/StringTests.cs index 5cea77c216a..cc83dfa4250 100644 --- a/src/libraries/System.Runtime/tests/System/StringTests.cs +++ b/src/libraries/System.Runtime/tests/System/StringTests.cs @@ -448,7 +448,7 @@ public static void CopyTo(string s, int sourceIndex, int destinationIndex, int c Assert.Equal(expected, dst); Span 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] diff --git a/src/libraries/System.Security.Cryptography.Encoding/tests/Asn1/Reader/ReadBMPString.cs b/src/libraries/System.Security.Cryptography.Encoding/tests/Asn1/Reader/ReadBMPString.cs index 3eb40a428b2..642f54943f2 100644 --- a/src/libraries/System.Security.Cryptography.Encoding/tests/Asn1/Reader/ReadBMPString.cs +++ b/src/libraries/System.Security.Cryptography.Encoding/tests/Asn1/Reader/ReadBMPString.cs @@ -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()); } diff --git a/src/libraries/System.Security.Cryptography.Encoding/tests/Asn1/Reader/ReadBitString.cs b/src/libraries/System.Security.Cryptography.Encoding/tests/Asn1/Reader/ReadBitString.cs index 4230b1d1bd4..077e3c639f1 100644 --- a/src/libraries/System.Security.Cryptography.Encoding/tests/Asn1/Reader/ReadBitString.cs +++ b/src/libraries/System.Security.Cryptography.Encoding/tests/Asn1/Reader/ReadBitString.cs @@ -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()); } diff --git a/src/libraries/System.Security.Cryptography.Encoding/tests/Asn1/Reader/ReadIA5String.cs b/src/libraries/System.Security.Cryptography.Encoding/tests/Asn1/Reader/ReadIA5String.cs index 5d3d285a428..4dcb6f0aaa1 100644 --- a/src/libraries/System.Security.Cryptography.Encoding/tests/Asn1/Reader/ReadIA5String.cs +++ b/src/libraries/System.Security.Cryptography.Encoding/tests/Asn1/Reader/ReadIA5String.cs @@ -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()); } diff --git a/src/libraries/System.Security.Cryptography.Encoding/tests/Asn1/Reader/ReadOctetString.cs b/src/libraries/System.Security.Cryptography.Encoding/tests/Asn1/Reader/ReadOctetString.cs index f9ff4d4f7da..909f62a6680 100644 --- a/src/libraries/System.Security.Cryptography.Encoding/tests/Asn1/Reader/ReadOctetString.cs +++ b/src/libraries/System.Security.Cryptography.Encoding/tests/Asn1/Reader/ReadOctetString.cs @@ -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()); } diff --git a/src/libraries/System.Security.Cryptography.Encoding/tests/Asn1/Reader/ReadUTF8String.cs b/src/libraries/System.Security.Cryptography.Encoding/tests/Asn1/Reader/ReadUTF8String.cs index f441405c5b4..d3bb9dfe275 100644 --- a/src/libraries/System.Security.Cryptography.Encoding/tests/Asn1/Reader/ReadUTF8String.cs +++ b/src/libraries/System.Security.Cryptography.Encoding/tests/Asn1/Reader/ReadUTF8String.cs @@ -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()); } diff --git a/src/libraries/System.Security.Cryptography.Encoding/tests/Asn1/Writer/ComprehensiveWriteTest.cs b/src/libraries/System.Security.Cryptography.Encoding/tests/Asn1/Writer/ComprehensiveWriteTest.cs index cb524dfd1d2..183c5b75ac7 100644 --- a/src/libraries/System.Security.Cryptography.Encoding/tests/Asn1/Writer/ComprehensiveWriteTest.cs +++ b/src/libraries/System.Security.Cryptography.Encoding/tests/Asn1/Writer/ComprehensiveWriteTest.cs @@ -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(); diff --git a/src/libraries/System.Security.Cryptography.Encoding/tests/Asn1/Writer/WriteCharacterString.cs b/src/libraries/System.Security.Cryptography.Encoding/tests/Asn1/Writer/WriteCharacterString.cs index 6d1f4d9cf44..b9ac66f75b3 100644 --- a/src/libraries/System.Security.Cryptography.Encoding/tests/Asn1/Writer/WriteCharacterString.cs +++ b/src/libraries/System.Security.Cryptography.Encoding/tests/Asn1/Writer/WriteCharacterString.cs @@ -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); } -- GitLab