From c0e96d1fec20ced8cc3232b23e96c026c49a8d10 Mon Sep 17 00:00:00 2001 From: ahsonkhan Date: Tue, 5 Dec 2017 19:13:03 -0800 Subject: [PATCH 1/9] Implement Span LastIndexOf and add tests --- src/System.Memory/ref/System.Memory.cs | 6 + .../src/System/MemoryExtensions.cs | 70 ++++++++ src/System.Memory/src/System/SpanHelpers.T.cs | 104 ++++++++++++ .../src/System/SpanHelpers.byte.cs | 102 ++++++++++++ .../tests/ReadOnlySpan/LastIndexOf.T.cs | 120 ++++++++++++++ .../tests/ReadOnlySpan/LastIndexOf.byte.cs | 150 ++++++++++++++++++ .../tests/ReadOnlySpan/LastIndexOf.char.cs | 74 +++++++++ src/System.Memory/tests/Span/LastIndexOf.T.cs | 120 ++++++++++++++ .../tests/Span/LastIndexOf.byte.cs | 150 ++++++++++++++++++ .../tests/Span/LastIndexOf.char.cs | 74 +++++++++ .../tests/System.Memory.Tests.csproj | 6 + 11 files changed, 976 insertions(+) create mode 100644 src/System.Memory/tests/ReadOnlySpan/LastIndexOf.T.cs create mode 100644 src/System.Memory/tests/ReadOnlySpan/LastIndexOf.byte.cs create mode 100644 src/System.Memory/tests/ReadOnlySpan/LastIndexOf.char.cs create mode 100644 src/System.Memory/tests/Span/LastIndexOf.T.cs create mode 100644 src/System.Memory/tests/Span/LastIndexOf.byte.cs create mode 100644 src/System.Memory/tests/Span/LastIndexOf.char.cs diff --git a/src/System.Memory/ref/System.Memory.cs b/src/System.Memory/ref/System.Memory.cs index e388776bce3e..2d6193bb9582 100644 --- a/src/System.Memory/ref/System.Memory.cs +++ b/src/System.Memory/ref/System.Memory.cs @@ -97,6 +97,9 @@ public static class MemoryExtensions public static int IndexOfAny(this Span span, byte value0, byte value1, byte value2) { throw null; } public static int IndexOfAny(this Span span, ReadOnlySpan values) { throw null; } + public static int LastIndexOf(this Span span, T value) where T : IEquatable { throw null; } + public static int LastIndexOf(this Span span, ReadOnlySpan value) where T : IEquatable { throw null; } + public static bool SequenceEqual(this Span first, ReadOnlySpan second) where T : IEquatable { throw null; } public static bool StartsWith(this Span span, ReadOnlySpan value) where T : IEquatable { throw null; } @@ -128,6 +131,9 @@ public static class MemoryExtensions public static int IndexOfAny(this ReadOnlySpan span, byte value0, byte value1, byte value2) { throw null; } public static int IndexOfAny(this ReadOnlySpan span, ReadOnlySpan values) { throw null; } + public static int LastIndexOf(this ReadOnlySpan span, T value) where T : IEquatable { throw null; } + public static int LastIndexOf(this ReadOnlySpan span, ReadOnlySpan value) where T : IEquatable { throw null; } + public static bool SequenceEqual(this ReadOnlySpan first, ReadOnlySpan second) where T : IEquatable { throw null; } public static bool StartsWith(this ReadOnlySpan span, ReadOnlySpan value) where T : IEquatable { throw null; } diff --git a/src/System.Memory/src/System/MemoryExtensions.cs b/src/System.Memory/src/System/MemoryExtensions.cs index e6aeb81ddb4b..dde616244430 100644 --- a/src/System.Memory/src/System/MemoryExtensions.cs +++ b/src/System.Memory/src/System/MemoryExtensions.cs @@ -47,6 +47,41 @@ ref Unsafe.As(ref value.DangerousGetPinnableReference()), return SpanHelpers.IndexOf(ref span.DangerousGetPinnableReference(), span.Length, ref value.DangerousGetPinnableReference(), value.Length); } + /// + /// Searches for the specified value and returns the index of its last occurrence. If not found, returns -1. Values are compared using IEquatable{T}.Equals(T). + /// + /// The span to search. + /// The value to search for. + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int LastIndexOf(this Span span, T value) + where T : IEquatable + { + if (typeof(T) == typeof(byte)) + return SpanHelpers.LastIndexOf( + ref Unsafe.As(ref span.DangerousGetPinnableReference()), + Unsafe.As(ref value), + span.Length); + return SpanHelpers.LastIndexOf(ref span.DangerousGetPinnableReference(), value, span.Length); + } + + /// + /// Searches for the specified sequence and returns the index of its last occurrence. If not found, returns -1. Values are compared using IEquatable{T}.Equals(T). + /// + /// The span to search. + /// The sequence to search for. + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int LastIndexOf(this Span span, ReadOnlySpan value) + where T : IEquatable + { + if (typeof(T) == typeof(byte)) + return SpanHelpers.LastIndexOf( + ref Unsafe.As(ref span.DangerousGetPinnableReference()), + span.Length, + ref Unsafe.As(ref value.DangerousGetPinnableReference()), + value.Length); + return SpanHelpers.LastIndexOf(ref span.DangerousGetPinnableReference(), span.Length, ref value.DangerousGetPinnableReference(), value.Length); + } + /// /// Determines whether two sequences are equal by comparing the elements using IEquatable{T}.Equals(T). /// @@ -99,6 +134,41 @@ ref Unsafe.As(ref value.DangerousGetPinnableReference()), return SpanHelpers.IndexOf(ref span.DangerousGetPinnableReference(), span.Length, ref value.DangerousGetPinnableReference(), value.Length); } + /// + /// Searches for the specified value and returns the index of its last occurrence. If not found, returns -1. Values are compared using IEquatable{T}.Equals(T). + /// + /// The span to search. + /// The value to search for. + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int LastIndexOf(this ReadOnlySpan span, T value) + where T : IEquatable + { + if (typeof(T) == typeof(byte)) + return SpanHelpers.LastIndexOf( + ref Unsafe.As(ref span.DangerousGetPinnableReference()), + Unsafe.As(ref value), + span.Length); + return SpanHelpers.LastIndexOf(ref span.DangerousGetPinnableReference(), value, span.Length); + } + + /// + /// Searches for the specified sequence and returns the index of its last occurrence. If not found, returns -1. Values are compared using IEquatable{T}.Equals(T). + /// + /// The span to search. + /// The sequence to search for. + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int LastIndexOf(this ReadOnlySpan span, ReadOnlySpan value) + where T : IEquatable + { + if (typeof(T) == typeof(byte)) + return SpanHelpers.LastIndexOf( + ref Unsafe.As(ref span.DangerousGetPinnableReference()), + span.Length, + ref Unsafe.As(ref value.DangerousGetPinnableReference()), + value.Length); + return SpanHelpers.LastIndexOf(ref span.DangerousGetPinnableReference(), span.Length, ref value.DangerousGetPinnableReference(), value.Length); + } + /// /// Searches for the first index of any of the specified values similar to calling IndexOf several times with the logical OR operator. If not found, returns -1. /// diff --git a/src/System.Memory/src/System/SpanHelpers.T.cs b/src/System.Memory/src/System/SpanHelpers.T.cs index 88bb4447f8b2..eac82690dbc4 100644 --- a/src/System.Memory/src/System/SpanHelpers.T.cs +++ b/src/System.Memory/src/System/SpanHelpers.T.cs @@ -119,6 +119,110 @@ public static unsafe int IndexOf(ref T searchSpace, T value, int length) return (int)(byte*)(index + 7); } + 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); + + if (valueLength == 0) + return 0; // A zero-length sequence is always treated as "found" at the start of the search space. + + T valueHead = value; + ref T valueTail = ref Unsafe.Add(ref value, 1); + int valueTailLength = valueLength - 1; + + int index = 0; + for (;;) + { + Debug.Assert(0 <= index && index <= searchSpaceLength); // Ensures no deceptive underflows in the computation of "remainingSearchSpaceLength". + int remainingSearchSpaceLength = searchSpaceLength - index - valueTailLength; + if (remainingSearchSpaceLength <= 0) + break; // The unsearched portion is now shorter than the sequence we're looking for. So it can't be there. + + // Do a quick search for the first element of "value". + int relativeIndex = LastIndexOf(ref Unsafe.Add(ref searchSpace, index), valueHead, remainingSearchSpaceLength); + if (relativeIndex == -1) + break; + index += relativeIndex; + + // Found the first element of "value". See if the tail matches. + if (SequenceEqual(ref Unsafe.Add(ref searchSpace, index + 1), ref valueTail, valueTailLength)) + return index; // The tail matched. Return a successful find. + + index++; + } + return -1; + } + + public static unsafe int LastIndexOf(ref T searchSpace, T value, int length) + where T : IEquatable + { + Debug.Assert(length >= 0); + + while (length >= 8) + { + length -= 8; + + if (value.Equals(Unsafe.Add(ref searchSpace, length + 7))) + goto Found7; + if (value.Equals(Unsafe.Add(ref searchSpace, length + 6))) + goto Found6; + if (value.Equals(Unsafe.Add(ref searchSpace, length + 5))) + goto Found5; + if (value.Equals(Unsafe.Add(ref searchSpace, length + 4))) + goto Found4; + if (value.Equals(Unsafe.Add(ref searchSpace, length + 3))) + goto Found3; + if (value.Equals(Unsafe.Add(ref searchSpace, length + 2))) + goto Found2; + if (value.Equals(Unsafe.Add(ref searchSpace, length + 1))) + goto Found1; + if (value.Equals(Unsafe.Add(ref searchSpace, length))) + goto Found; + } + + if (length >= 4) + { + length -= 4; + + if (value.Equals(Unsafe.Add(ref searchSpace, length + 3))) + goto Found3; + if (value.Equals(Unsafe.Add(ref searchSpace, length + 2))) + goto Found2; + if (value.Equals(Unsafe.Add(ref searchSpace, length + 1))) + goto Found1; + if (value.Equals(Unsafe.Add(ref searchSpace, length))) + goto Found; + } + + while (length > 0) + { + length--; + + if (value.Equals(Unsafe.Add(ref searchSpace, length))) + goto Found; + } + return -1; + +Found: // Workaround for https://github.com/dotnet/coreclr/issues/13549 + return length; +Found1: + return length + 1; +Found2: + return length + 2; +Found3: + return length + 3; +Found4: + return length + 4; +Found5: + return length + 5; +Found6: + return length + 6; +Found7: + return length + 7; + } + public static bool SequenceEqual(ref T first, ref T second, int length) where T : IEquatable { diff --git a/src/System.Memory/src/System/SpanHelpers.byte.cs b/src/System.Memory/src/System/SpanHelpers.byte.cs index ba0e8b990d1d..22998a6b7186 100644 --- a/src/System.Memory/src/System/SpanHelpers.byte.cs +++ b/src/System.Memory/src/System/SpanHelpers.byte.cs @@ -182,6 +182,108 @@ public static unsafe int IndexOf(ref byte searchSpace, byte value, int length) return (int)(byte*)(index + 7); } + public static int LastIndexOf(ref byte searchSpace, int searchSpaceLength, ref byte value, int valueLength) + { + Debug.Assert(searchSpaceLength >= 0); + Debug.Assert(valueLength >= 0); + + if (valueLength == 0) + return 0; // A zero-length sequence is always treated as "found" at the start of the search space. + + byte valueHead = value; + ref byte valueTail = ref Unsafe.Add(ref value, 1); + int valueTailLength = valueLength - 1; + + int index = 0; + for (;;) + { + Debug.Assert(0 <= index && index <= searchSpaceLength); // Ensures no deceptive underflows in the computation of "remainingSearchSpaceLength". + int remainingSearchSpaceLength = searchSpaceLength - index - valueTailLength; + if (remainingSearchSpaceLength <= 0) + break; // The unsearched portion is now shorter than the sequence we're looking for. So it can't be there. + + // Do a quick search for the first element of "value". + int relativeIndex = LastIndexOf(ref Unsafe.Add(ref searchSpace, index), valueHead, remainingSearchSpaceLength); + if (relativeIndex == -1) + break; + index += relativeIndex; + + // Found the first element of "value". See if the tail matches. + if (SequenceEqual(ref Unsafe.Add(ref searchSpace, index + 1), ref valueTail, valueTailLength)) + return index; // The tail matched. Return a successful find. + + index++; + } + return -1; + } + + public static unsafe int LastIndexOf(ref byte searchSpace, byte value, int length) + { + Debug.Assert(length >= 0); + + while (length >= 8) + { + length -= 8; + + if (value.Equals(Unsafe.Add(ref searchSpace, length + 7))) + goto Found7; + if (value.Equals(Unsafe.Add(ref searchSpace, length + 6))) + goto Found6; + if (value.Equals(Unsafe.Add(ref searchSpace, length + 5))) + goto Found5; + if (value.Equals(Unsafe.Add(ref searchSpace, length + 4))) + goto Found4; + if (value.Equals(Unsafe.Add(ref searchSpace, length + 3))) + goto Found3; + if (value.Equals(Unsafe.Add(ref searchSpace, length + 2))) + goto Found2; + if (value.Equals(Unsafe.Add(ref searchSpace, length + 1))) + goto Found1; + if (value.Equals(Unsafe.Add(ref searchSpace, length))) + goto Found; + } + + if (length >= 4) + { + length -= 4; + + if (value.Equals(Unsafe.Add(ref searchSpace, length + 3))) + goto Found3; + if (value.Equals(Unsafe.Add(ref searchSpace, length + 2))) + goto Found2; + if (value.Equals(Unsafe.Add(ref searchSpace, length + 1))) + goto Found1; + if (value.Equals(Unsafe.Add(ref searchSpace, length))) + goto Found; + } + + while (length > 0) + { + length--; + + if (value.Equals(Unsafe.Add(ref searchSpace, length))) + goto Found; + } + return -1; + +Found: // Workaround for https://github.com/dotnet/coreclr/issues/13549 + return length; +Found1: + return length + 1; +Found2: + return length + 2; +Found3: + return length + 3; +Found4: + return length + 4; +Found5: + return length + 5; +Found6: + return length + 6; +Found7: + return length + 7; + } + public static unsafe int IndexOfAny(ref byte searchSpace, byte value0, byte value1, int length) { Debug.Assert(length >= 0); diff --git a/src/System.Memory/tests/ReadOnlySpan/LastIndexOf.T.cs b/src/System.Memory/tests/ReadOnlySpan/LastIndexOf.T.cs new file mode 100644 index 000000000000..036635b6c076 --- /dev/null +++ b/src/System.Memory/tests/ReadOnlySpan/LastIndexOf.T.cs @@ -0,0 +1,120 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using Xunit; + +namespace System.SpanTests +{ + public static partial class ReadOnlySpanTests + { + [Fact] + public static void ZeroLengthLastIndexOf() + { + ReadOnlySpan sp = new ReadOnlySpan(Array.Empty()); + int idx = sp.LastIndexOf(0); + Assert.Equal(-1, idx); + } + + [Fact] + public static void TestMatchLastIndexOf() + { + for (int length = 0; length < 32; length++) + { + int[] a = new int[length]; + for (int i = 0; i < length; i++) + { + a[i] = 10 * (i + 1); + } + ReadOnlySpan span = new ReadOnlySpan(a); + + for (int targetIndex = 0; targetIndex < length; targetIndex++) + { + int target = a[targetIndex]; + int idx = span.LastIndexOf(target); + Assert.Equal(targetIndex, idx); + } + } + } + + [Fact] + public static void TestMultipleMatchLastIndexOf() + { + for (int length = 2; length < 32; length++) + { + int[] a = new int[length]; + for (int i = 0; i < length; i++) + { + a[i] = 10 * (i + 1); + } + + a[length - 1] = 5555; + a[length - 2] = 5555; + + ReadOnlySpan span = new ReadOnlySpan(a); + int idx = span.LastIndexOf(5555); + Assert.Equal(length - 1, idx); + } + } + + [Fact] + public static void OnNoMatchMakeSureEveryElementIsComparedLastIndexOf() + { + for (int length = 0; length < 100; length++) + { + TIntLog log = new TIntLog(); + + TInt[] a = new TInt[length]; + for (int i = 0; i < length; i++) + { + a[i] = new TInt(10 * (i + 1), log); + } + ReadOnlySpan span = new ReadOnlySpan(a); + int idx = span.LastIndexOf(new TInt(9999, log)); + Assert.Equal(-1, idx); + + // Since we asked for a non-existent value, make sure each element of the array was compared once. + // (Strictly speaking, it would not be illegal for IndexOf to compare an element more than once but + // that would be a non-optimal implementation and a red flag. So we'll stick with the stricter test.) + Assert.Equal(a.Length, log.Count); + foreach (TInt elem in a) + { + int numCompares = log.CountCompares(elem.Value, 9999); + Assert.True(numCompares == 1, $"Expected {numCompares} == 1 for element {elem.Value}."); + } + } + } + + [Fact] + public static void MakeSureNoChecksGoOutOfRangeLastIndexOf() + { + const int GuardValue = 77777; + const int GuardLength = 50; + + Action checkForOutOfRangeAccess = + delegate (int x, int y) + { + if (x == GuardValue || y == GuardValue) + throw new Exception("Detected out of range access in IndexOf()"); + }; + + for (int length = 0; length < 100; length++) + { + TInt[] a = new TInt[GuardLength + length + GuardLength]; + for (int i = 0; i < a.Length; i++) + { + a[i] = new TInt(GuardValue, checkForOutOfRangeAccess); + } + + for (int i = 0; i < length; i++) + { + a[GuardLength + i] = new TInt(10 * (i + 1), checkForOutOfRangeAccess); + } + + ReadOnlySpan span = new ReadOnlySpan(a, GuardLength, length); + int idx = span.LastIndexOf(new TInt(9999, checkForOutOfRangeAccess)); + Assert.Equal(-1, idx); + } + } + } +} diff --git a/src/System.Memory/tests/ReadOnlySpan/LastIndexOf.byte.cs b/src/System.Memory/tests/ReadOnlySpan/LastIndexOf.byte.cs new file mode 100644 index 000000000000..5ede3d4423f6 --- /dev/null +++ b/src/System.Memory/tests/ReadOnlySpan/LastIndexOf.byte.cs @@ -0,0 +1,150 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.Numerics; +using System.Text; +using Xunit; + +namespace System.SpanTests +{ + public static partial class ReadOnlySpanTests + { + [Fact] + public static void ZeroLengthLastIndexOf_Byte() + { + ReadOnlySpan sp = new ReadOnlySpan(Array.Empty()); + int idx = sp.LastIndexOf(0); + Assert.Equal(-1, idx); + } + + [Fact] + public static void DefaultFilledLastIndexOf_Byte() + { + for (int length = 0; length <= byte.MaxValue; length++) + { + byte[] a = new byte[length]; + ReadOnlySpan span = new ReadOnlySpan(a); + + for (int i = 0; i < length; i++) + { + byte target0 = default(byte); + int idx = span.LastIndexOf(target0); + Assert.Equal(length - 1, idx); + } + } + } + + [Fact] + public static void TestMatchLastIndexOf_Byte() + { + for (int length = 0; length <= byte.MaxValue; length++) + { + byte[] a = new byte[length]; + for (int i = 0; i < length; i++) + { + a[i] = (byte)(i + 1); + } + ReadOnlySpan span = new ReadOnlySpan(a); + + for (int targetIndex = 0; targetIndex < length; targetIndex++) + { + byte target = a[targetIndex]; + int idx = span.LastIndexOf(target); + Assert.Equal(targetIndex, idx); + } + } + } + + [Fact] + public static void TestNoMatchLastIndexOf_Byte() + { + var rnd = new Random(42); + for (int length = 0; length <= byte.MaxValue; length++) + { + byte[] a = new byte[length]; + byte target = (byte)rnd.Next(0, 256); + for (int i = 0; i < length; i++) + { + byte val = (byte)(i + 1); + a[i] = val == target ? (byte)(target + 1) : val; + } + ReadOnlySpan span = new ReadOnlySpan(a); + + int idx = span.LastIndexOf(target); + Assert.Equal(-1, idx); + } + } + + [Fact] + public static void TestAllignmentNoMatchLastIndexOf_Byte() + { + byte[] array = new byte[4 * Vector.Count]; + for (var i = 0; i < Vector.Count; i++) + { + var span = new ReadOnlySpan(array, i, 3 * Vector.Count); + int idx = span.LastIndexOf(5); + Assert.Equal(-1, idx); + + span = new ReadOnlySpan(array, i, 3 * Vector.Count - 3); + idx = span.LastIndexOf(5); + Assert.Equal(-1, idx); + } + } + + [Fact] + public static void TestAllignmentMatchLastIndexOf_Byte() + { + byte[] array = new byte[4 * Vector.Count]; + for (int i = 0; i < array.Length; i++) + { + array[i] = 5; + } + for (var i = 0; i < Vector.Count; i++) + { + var span = new ReadOnlySpan(array, i, 3 * Vector.Count); + int idx = span.LastIndexOf(5); + Assert.Equal(span.Length - 1, idx); + + span = new ReadOnlySpan(array, i, 3 * Vector.Count - 3); + idx = span.LastIndexOf(5); + Assert.Equal(span.Length - 1, idx); + } + } + + [Fact] + public static void TestMultipleMatchLastIndexOf_Byte() + { + for (int length = 2; length <= byte.MaxValue; length++) + { + byte[] a = new byte[length]; + for (int i = 0; i < length; i++) + { + byte val = (byte)(i + 1); + a[i] = val == 200 ? (byte)201 : val; + } + + a[length - 1] = 200; + a[length - 2] = 200; + + ReadOnlySpan span = new ReadOnlySpan(a); + int idx = span.LastIndexOf(200); + Assert.Equal(length - 1, idx); + } + } + + [Fact] + public static void MakeSureNoChecksGoOutOfRangeLastIndexOf_Byte() + { + for (int length = 0; length <= byte.MaxValue; length++) + { + byte[] a = new byte[length + 2]; + a[0] = 99; + a[length + 1] = 99; + ReadOnlySpan span = new ReadOnlySpan(a, 1, length); + int index = span.LastIndexOf(99); + Assert.Equal(-1, index); + } + } + } +} diff --git a/src/System.Memory/tests/ReadOnlySpan/LastIndexOf.char.cs b/src/System.Memory/tests/ReadOnlySpan/LastIndexOf.char.cs new file mode 100644 index 000000000000..b1caa690dc14 --- /dev/null +++ b/src/System.Memory/tests/ReadOnlySpan/LastIndexOf.char.cs @@ -0,0 +1,74 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using Xunit; + +namespace System.SpanTests +{ + public static partial class ReadOnlySpanTests + { + [Fact] + public static void ZeroLengthLastIndexOf_Char() + { + ReadOnlySpan sp = new ReadOnlySpan(Array.Empty()); + int idx = sp.LastIndexOf((char)0); + Assert.Equal(-1, idx); + } + + [Fact] + public static void TestMatchLastIndexOf_Char() + { + for (int length = 0; length < 32; length++) + { + char[] a = new char[length]; + for (int i = 0; i < length; i++) + { + a[i] = (char)(i + 1); + } + ReadOnlySpan span = new ReadOnlySpan(a); + + for (int targetIndex = 0; targetIndex < length; targetIndex++) + { + char target = a[targetIndex]; + int idx = span.LastIndexOf(target); + Assert.Equal(targetIndex, idx); + } + } + } + + [Fact] + public static void TestMultipleMatchLastIndexOf_Char() + { + for (int length = 2; length < 32; length++) + { + char[] a = new char[length]; + for (int i = 0; i < length; i++) + { + a[i] = (char)(i + 1); + } + + a[length - 1] = (char)200; + a[length - 2] = (char)200; + + ReadOnlySpan span = new ReadOnlySpan(a); + int idx = span.LastIndexOf((char)200); + Assert.Equal(length - 1, idx); + } + } + + [Fact] + public static void MakeSureNoChecksGoOutOfRangeLastIndexOf_Char() + { + for (int length = 0; length < 100; length++) + { + char[] a = new char[length + 2]; + a[0] = '9'; + a[length + 1] = '9'; + ReadOnlySpan span = new ReadOnlySpan(a, 1, length); + int index = span.LastIndexOf('9'); + Assert.Equal(-1, index); + } + } + } +} diff --git a/src/System.Memory/tests/Span/LastIndexOf.T.cs b/src/System.Memory/tests/Span/LastIndexOf.T.cs new file mode 100644 index 000000000000..427ff80a4e7b --- /dev/null +++ b/src/System.Memory/tests/Span/LastIndexOf.T.cs @@ -0,0 +1,120 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using Xunit; + +namespace System.SpanTests +{ + public static partial class SpanTests + { + [Fact] + public static void ZeroLengthLastIndexOf() + { + Span sp = new Span(Array.Empty()); + int idx = sp.LastIndexOf(0); + Assert.Equal(-1, idx); + } + + [Fact] + public static void TestMatchLastIndexOf() + { + for (int length = 0; length < 32; length++) + { + int[] a = new int[length]; + for (int i = 0; i < length; i++) + { + a[i] = 10 * (i + 1); + } + Span span = new Span(a); + + for (int targetIndex = 0; targetIndex < length; targetIndex++) + { + int target = a[targetIndex]; + int idx = span.LastIndexOf(target); + Assert.Equal(targetIndex, idx); + } + } + } + + [Fact] + public static void TestMultipleMatchLastIndexOf() + { + for (int length = 2; length < 32; length++) + { + int[] a = new int[length]; + for (int i = 0; i < length; i++) + { + a[i] = 10 * (i + 1); + } + + a[length - 1] = 5555; + a[length - 2] = 5555; + + Span span = new Span(a); + int idx = span.LastIndexOf(5555); + Assert.Equal(length - 1, idx); + } + } + + [Fact] + public static void OnNoMatchMakeSureEveryElementIsComparedLastIndexOf() + { + for (int length = 0; length < 100; length++) + { + TIntLog log = new TIntLog(); + + TInt[] a = new TInt[length]; + for (int i = 0; i < length; i++) + { + a[i] = new TInt(10 * (i + 1), log); + } + Span span = new Span(a); + int idx = span.LastIndexOf(new TInt(9999, log)); + Assert.Equal(-1, idx); + + // Since we asked for a non-existent value, make sure each element of the array was compared once. + // (Strictly speaking, it would not be illegal for IndexOf to compare an element more than once but + // that would be a non-optimal implementation and a red flag. So we'll stick with the stricter test.) + Assert.Equal(a.Length, log.Count); + foreach (TInt elem in a) + { + int numCompares = log.CountCompares(elem.Value, 9999); + Assert.True(numCompares == 1, $"Expected {numCompares} == 1 for element {elem.Value}."); + } + } + } + + [Fact] + public static void MakeSureNoChecksGoOutOfRangeLastIndexOf() + { + const int GuardValue = 77777; + const int GuardLength = 50; + + Action checkForOutOfRangeAccess = + delegate (int x, int y) + { + if (x == GuardValue || y == GuardValue) + throw new Exception("Detected out of range access in IndexOf()"); + }; + + for (int length = 0; length < 100; length++) + { + TInt[] a = new TInt[GuardLength + length + GuardLength]; + for (int i = 0; i < a.Length; i++) + { + a[i] = new TInt(GuardValue, checkForOutOfRangeAccess); + } + + for (int i = 0; i < length; i++) + { + a[GuardLength + i] = new TInt(10 * (i + 1), checkForOutOfRangeAccess); + } + + Span span = new Span(a, GuardLength, length); + int idx = span.LastIndexOf(new TInt(9999, checkForOutOfRangeAccess)); + Assert.Equal(-1, idx); + } + } + } +} diff --git a/src/System.Memory/tests/Span/LastIndexOf.byte.cs b/src/System.Memory/tests/Span/LastIndexOf.byte.cs new file mode 100644 index 000000000000..1886a5f25d7a --- /dev/null +++ b/src/System.Memory/tests/Span/LastIndexOf.byte.cs @@ -0,0 +1,150 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.Numerics; +using System.Text; +using Xunit; + +namespace System.SpanTests +{ + public static partial class SpanTests + { + [Fact] + public static void ZeroLengthLastIndexOf_Byte() + { + Span sp = new Span(Array.Empty()); + int idx = sp.LastIndexOf(0); + Assert.Equal(-1, idx); + } + + [Fact] + public static void DefaultFilledLastIndexOf_Byte() + { + for (int length = 0; length <= byte.MaxValue; length++) + { + byte[] a = new byte[length]; + Span span = new Span(a); + + for (int i = 0; i < length; i++) + { + byte target0 = default(byte); + int idx = span.LastIndexOf(target0); + Assert.Equal(length - 1, idx); + } + } + } + + [Fact] + public static void TestMatchLastIndexOf_Byte() + { + for (int length = 0; length <= byte.MaxValue; length++) + { + byte[] a = new byte[length]; + for (int i = 0; i < length; i++) + { + a[i] = (byte)(i + 1); + } + Span span = new Span(a); + + for (int targetIndex = 0; targetIndex < length; targetIndex++) + { + byte target = a[targetIndex]; + int idx = span.LastIndexOf(target); + Assert.Equal(targetIndex, idx); + } + } + } + + [Fact] + public static void TestNoMatchLastIndexOf_Byte() + { + var rnd = new Random(42); + for (int length = 0; length <= byte.MaxValue; length++) + { + byte[] a = new byte[length]; + byte target = (byte)rnd.Next(0, 256); + for (int i = 0; i < length; i++) + { + byte val = (byte)(i + 1); + a[i] = val == target ? (byte)(target + 1) : val; + } + Span span = new Span(a); + + int idx = span.LastIndexOf(target); + Assert.Equal(-1, idx); + } + } + + [Fact] + public static void TestAllignmentNoMatchLastIndexOf_Byte() + { + byte[] array = new byte[4 * Vector.Count]; + for (var i = 0; i < Vector.Count; i++) + { + var span = new Span(array, i, 3 * Vector.Count); + int idx = span.LastIndexOf(5); + Assert.Equal(-1, idx); + + span = new Span(array, i, 3 * Vector.Count - 3); + idx = span.LastIndexOf(5); + Assert.Equal(-1, idx); + } + } + + [Fact] + public static void TestAllignmentMatchLastIndexOf_Byte() + { + byte[] array = new byte[4 * Vector.Count]; + for (int i = 0; i < array.Length; i++) + { + array[i] = 5; + } + for (var i = 0; i < Vector.Count; i++) + { + var span = new Span(array, i, 3 * Vector.Count); + int idx = span.LastIndexOf(5); + Assert.Equal(span.Length - 1, idx); + + span = new Span(array, i, 3 * Vector.Count - 3); + idx = span.LastIndexOf(5); + Assert.Equal(span.Length - 1, idx); + } + } + + [Fact] + public static void TestMultipleMatchLastIndexOf_Byte() + { + for (int length = 2; length <= byte.MaxValue; length++) + { + byte[] a = new byte[length]; + for (int i = 0; i < length; i++) + { + byte val = (byte)(i + 1); + a[i] = val == 200 ? (byte)201 : val; + } + + a[length - 1] = 200; + a[length - 2] = 200; + + Span span = new Span(a); + int idx = span.LastIndexOf(200); + Assert.Equal(length - 1, idx); + } + } + + [Fact] + public static void MakeSureNoChecksGoOutOfRangeLastIndexOf_Byte() + { + for (int length = 0; length <= byte.MaxValue; length++) + { + byte[] a = new byte[length + 2]; + a[0] = 99; + a[length + 1] = 99; + Span span = new Span(a, 1, length); + int index = span.LastIndexOf(99); + Assert.Equal(-1, index); + } + } + } +} diff --git a/src/System.Memory/tests/Span/LastIndexOf.char.cs b/src/System.Memory/tests/Span/LastIndexOf.char.cs new file mode 100644 index 000000000000..1ca6bcaa3b5a --- /dev/null +++ b/src/System.Memory/tests/Span/LastIndexOf.char.cs @@ -0,0 +1,74 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using Xunit; + +namespace System.SpanTests +{ + public static partial class SpanTests + { + [Fact] + public static void ZeroLengthLastIndexOf_Char() + { + Span sp = new Span(Array.Empty()); + int idx = sp.LastIndexOf((char)0); + Assert.Equal(-1, idx); + } + + [Fact] + public static void TestMatchLastIndexOf_Char() + { + for (int length = 0; length < 32; length++) + { + char[] a = new char[length]; + for (int i = 0; i < length; i++) + { + a[i] = (char)(i + 1); + } + Span span = new Span(a); + + for (int targetIndex = 0; targetIndex < length; targetIndex++) + { + char target = a[targetIndex]; + int idx = span.LastIndexOf(target); + Assert.Equal(targetIndex, idx); + } + } + } + + [Fact] + public static void TestMultipleMatchLastIndexOf_Char() + { + for (int length = 2; length < 32; length++) + { + char[] a = new char[length]; + for (int i = 0; i < length; i++) + { + a[i] = (char)(i + 1); + } + + a[length - 1] = (char)200; + a[length - 2] = (char)200; + + Span span = new Span(a); + int idx = span.LastIndexOf((char)200); + Assert.Equal(length - 1, idx); + } + } + + [Fact] + public static void MakeSureNoChecksGoOutOfRangeLastIndexOf_Char() + { + for (int length = 0; length < 100; length++) + { + char[] a = new char[length + 2]; + a[0] = '9'; + a[length + 1] = '9'; + Span span = new Span(a, 1, length); + int index = span.LastIndexOf('9'); + Assert.Equal(-1, index); + } + } + } +} diff --git a/src/System.Memory/tests/System.Memory.Tests.csproj b/src/System.Memory/tests/System.Memory.Tests.csproj index f85ef2582814..3b97a7784b1f 100644 --- a/src/System.Memory/tests/System.Memory.Tests.csproj +++ b/src/System.Memory/tests/System.Memory.Tests.csproj @@ -38,6 +38,9 @@ + + + @@ -70,6 +73,9 @@ + + + From c7ec22fcdfaccf388c21cc03c6d665ba4fb3b64a Mon Sep 17 00:00:00 2001 From: ahsonkhan Date: Tue, 5 Dec 2017 20:41:09 -0800 Subject: [PATCH 2/9] Add LastIndexOfSequence tests and fix implementation --- src/System.Memory/src/System/SpanHelpers.T.cs | 9 +- .../src/System/SpanHelpers.byte.cs | 9 +- .../ReadOnlySpan/LastIndexOfSequence.T.cs | 133 ++++++++++++++++++ .../ReadOnlySpan/LastIndexOfSequence.byte.cs | 133 ++++++++++++++++++ .../ReadOnlySpan/LastIndexOfSequence.char.cs | 133 ++++++++++++++++++ .../tests/Span/LastIndexOfSequence.T.cs | 133 ++++++++++++++++++ .../tests/Span/LastIndexOfSequence.byte.cs | 133 ++++++++++++++++++ .../tests/Span/LastIndexOfSequence.char.cs | 133 ++++++++++++++++++ .../tests/System.Memory.Tests.csproj | 6 + 9 files changed, 812 insertions(+), 10 deletions(-) create mode 100644 src/System.Memory/tests/ReadOnlySpan/LastIndexOfSequence.T.cs create mode 100644 src/System.Memory/tests/ReadOnlySpan/LastIndexOfSequence.byte.cs create mode 100644 src/System.Memory/tests/ReadOnlySpan/LastIndexOfSequence.char.cs create mode 100644 src/System.Memory/tests/Span/LastIndexOfSequence.T.cs create mode 100644 src/System.Memory/tests/Span/LastIndexOfSequence.byte.cs create mode 100644 src/System.Memory/tests/Span/LastIndexOfSequence.char.cs diff --git a/src/System.Memory/src/System/SpanHelpers.T.cs b/src/System.Memory/src/System/SpanHelpers.T.cs index eac82690dbc4..a228d1007f87 100644 --- a/src/System.Memory/src/System/SpanHelpers.T.cs +++ b/src/System.Memory/src/System/SpanHelpers.T.cs @@ -141,16 +141,15 @@ public static int LastIndexOf(ref T searchSpace, int searchSpaceLength, ref T break; // The unsearched portion is now shorter than the sequence we're looking for. So it can't be there. // Do a quick search for the first element of "value". - int relativeIndex = LastIndexOf(ref Unsafe.Add(ref searchSpace, index), valueHead, remainingSearchSpaceLength); + int relativeIndex = LastIndexOf(ref searchSpace, valueHead, remainingSearchSpaceLength); if (relativeIndex == -1) break; - index += relativeIndex; // Found the first element of "value". See if the tail matches. - if (SequenceEqual(ref Unsafe.Add(ref searchSpace, index + 1), ref valueTail, valueTailLength)) - return index; // The tail matched. Return a successful find. + if (SequenceEqual(ref Unsafe.Add(ref searchSpace, relativeIndex + 1), ref valueTail, valueTailLength)) + return relativeIndex; // The tail matched. Return a successful find. - index++; + index += remainingSearchSpaceLength - relativeIndex; } return -1; } diff --git a/src/System.Memory/src/System/SpanHelpers.byte.cs b/src/System.Memory/src/System/SpanHelpers.byte.cs index 22998a6b7186..cd8eec6d5c29 100644 --- a/src/System.Memory/src/System/SpanHelpers.byte.cs +++ b/src/System.Memory/src/System/SpanHelpers.byte.cs @@ -203,16 +203,15 @@ public static int LastIndexOf(ref byte searchSpace, int searchSpaceLength, ref b break; // The unsearched portion is now shorter than the sequence we're looking for. So it can't be there. // Do a quick search for the first element of "value". - int relativeIndex = LastIndexOf(ref Unsafe.Add(ref searchSpace, index), valueHead, remainingSearchSpaceLength); + int relativeIndex = LastIndexOf(ref searchSpace, valueHead, remainingSearchSpaceLength); if (relativeIndex == -1) break; - index += relativeIndex; // Found the first element of "value". See if the tail matches. - if (SequenceEqual(ref Unsafe.Add(ref searchSpace, index + 1), ref valueTail, valueTailLength)) - return index; // The tail matched. Return a successful find. + if (SequenceEqual(ref Unsafe.Add(ref searchSpace, relativeIndex + 1), ref valueTail, valueTailLength)) + return relativeIndex; // The tail matched. Return a successful find. - index++; + index += remainingSearchSpaceLength - relativeIndex; } return -1; } diff --git a/src/System.Memory/tests/ReadOnlySpan/LastIndexOfSequence.T.cs b/src/System.Memory/tests/ReadOnlySpan/LastIndexOfSequence.T.cs new file mode 100644 index 000000000000..f5876a20d2ad --- /dev/null +++ b/src/System.Memory/tests/ReadOnlySpan/LastIndexOfSequence.T.cs @@ -0,0 +1,133 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using Xunit; + +namespace System.SpanTests +{ + public static partial class ReadOnlySpanTests + { + [Fact] + public static void LastIndexOfSequenceMatchAtStart() + { + ReadOnlySpan span = new ReadOnlySpan(new int[] { 5, 1, 77, 2, 3, 77, 77, 4, 5, 77, 77, 77, 88, 6, 6, 77, 77, 88, 9 }); + ReadOnlySpan value = new ReadOnlySpan(new int[] { 5, 1, 77 }); + int index = span.LastIndexOf(value); + Assert.Equal(0, index); + } + + [Fact] + public static void LastIndexOfSequenceMultipleMatch() + { + ReadOnlySpan span = new ReadOnlySpan(new int[] { 1, 2, 3, 1, 2, 3, 1, 2, 3, 1 }); + ReadOnlySpan value = new ReadOnlySpan(new int[] { 2, 3 }); + int index = span.LastIndexOf(value); + Assert.Equal(7, index); + } + + [Fact] + public static void LastIndexOfSequenceRestart() + { + ReadOnlySpan span = new ReadOnlySpan(new int[] { 0, 1, 77, 2, 3, 77, 77, 4, 5, 77, 77, 77, 88, 6, 6, 77, 77, 8, 9, 77, 0, 1 }); + ReadOnlySpan value = new ReadOnlySpan(new int[] { 77, 77, 88 }); + int index = span.LastIndexOf(value); + Assert.Equal(10, index); + } + + [Fact] + public static void LastIndexOfSequenceNoMatch() + { + ReadOnlySpan span = new ReadOnlySpan(new int[] { 0, 1, 77, 2, 3, 77, 77, 4, 5, 77, 77, 77, 88, 6, 6, 77, 77, 88, 9 }); + ReadOnlySpan value = new ReadOnlySpan(new int[] { 77, 77, 88, 99 }); + int index = span.LastIndexOf(value); + Assert.Equal(-1, index); + } + + [Fact] + public static void LastIndexOfSequenceNotEvenAHeadMatch() + { + ReadOnlySpan span = new ReadOnlySpan(new int[] { 0, 1, 77, 2, 3, 77, 77, 4, 5, 77, 77, 77, 88, 6, 6, 77, 77, 88, 9 }); + ReadOnlySpan value = new ReadOnlySpan(new int[] { 100, 77, 88, 99 }); + int index = span.LastIndexOf(value); + Assert.Equal(-1, index); + } + + [Fact] + public static void LastIndexOfSequenceMatchAtVeryEnd() + { + ReadOnlySpan span = new ReadOnlySpan(new int[] { 0, 1, 2, 3, 4, 5 }); + ReadOnlySpan value = new ReadOnlySpan(new int[] { 3, 4, 5 }); + int index = span.LastIndexOf(value); + Assert.Equal(3, index); + } + + [Fact] + public static void LastIndexOfSequenceJustPastVeryEnd() + { + ReadOnlySpan span = new ReadOnlySpan(new int[] { 0, 1, 2, 3, 4, 5 }, 0, 5); + ReadOnlySpan value = new ReadOnlySpan(new int[] { 3, 4, 5 }); + int index = span.LastIndexOf(value); + Assert.Equal(-1, index); + } + + [Fact] + public static void LastIndexOfSequenceZeroLengthValue() + { + // A zero-length value is always "found" at the start of the span. + ReadOnlySpan span = new ReadOnlySpan(new int[] { 0, 1, 77, 2, 3, 77, 77, 4, 5, 77, 77, 77, 88, 6, 6, 77, 77, 88, 9 }); + ReadOnlySpan value = new ReadOnlySpan(Array.Empty()); + int index = span.LastIndexOf(value); + Assert.Equal(0, index); + } + + [Fact] + public static void LastIndexOfSequenceZeroLengthSpan() + { + ReadOnlySpan span = new ReadOnlySpan(Array.Empty()); + ReadOnlySpan value = new ReadOnlySpan(new int[] { 1, 2, 3 }); + int index = span.LastIndexOf(value); + Assert.Equal(-1, index); + } + + [Fact] + public static void LastIndexOfSequenceLengthOneValue() + { + // A zero-length value is always "found" at the start of the span. + ReadOnlySpan span = new ReadOnlySpan(new int[] { 0, 1, 2, 3, 4, 5 }); + ReadOnlySpan value = new ReadOnlySpan(new int[] { 2 }); + int index = span.LastIndexOf(value); + Assert.Equal(2, index); + } + + [Fact] + public static void LastIndexOfSequenceLengthOneValueAtVeryEnd() + { + // A zero-length value is always "found" at the start of the span. + ReadOnlySpan span = new ReadOnlySpan(new int[] { 0, 1, 2, 3, 4, 5 }); + ReadOnlySpan value = new ReadOnlySpan(new int[] { 5 }); + int index = span.LastIndexOf(value); + Assert.Equal(5, index); + } + + [Fact] + public static void LastIndexOfSequenceLengthOneValueMultipleTimes() + { + // A zero-length value is always "found" at the start of the span. + ReadOnlySpan span = new ReadOnlySpan(new int[] { 0, 1, 5, 3, 4, 5 }); + ReadOnlySpan value = new ReadOnlySpan(new int[] { 5 }); + int index = span.LastIndexOf(value); + Assert.Equal(5, index); + } + + [Fact] + public static void LastIndexOfSequenceLengthOneValueJustPasttVeryEnd() + { + // A zero-length value is always "found" at the start of the span. + ReadOnlySpan span = new ReadOnlySpan(new int[] { 0, 1, 2, 3, 4, 5 }, 0, 5); + ReadOnlySpan value = new ReadOnlySpan(new int[] { 5 }); + int index = span.LastIndexOf(value); + Assert.Equal(-1, index); + } + } +} diff --git a/src/System.Memory/tests/ReadOnlySpan/LastIndexOfSequence.byte.cs b/src/System.Memory/tests/ReadOnlySpan/LastIndexOfSequence.byte.cs new file mode 100644 index 000000000000..8b7adec168be --- /dev/null +++ b/src/System.Memory/tests/ReadOnlySpan/LastIndexOfSequence.byte.cs @@ -0,0 +1,133 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using Xunit; + +namespace System.SpanTests +{ + public static partial class ReadOnlySpanTests + { + [Fact] + public static void LastIndexOfSequenceMatchAtStart_Byte() + { + ReadOnlySpan span = new ReadOnlySpan(new byte[] { 5, 1, 77, 2, 3, 77, 77, 4, 5, 77, 77, 77, 88, 6, 6, 77, 77, 88, 9 }); + ReadOnlySpan value = new ReadOnlySpan(new byte[] { 5, 1, 77 }); + int index = span.LastIndexOf(value); + Assert.Equal(0, index); + } + + [Fact] + public static void LastIndexOfSequenceMultipleMatch_Byte() + { + ReadOnlySpan span = new ReadOnlySpan(new byte[] { 1, 2, 3, 1, 2, 3, 1, 2, 3, 1 }); + ReadOnlySpan value = new ReadOnlySpan(new byte[] { 2, 3 }); + int index = span.LastIndexOf(value); + Assert.Equal(7, index); + } + + [Fact] + public static void LastIndexOfSequenceRestart_Byte() + { + ReadOnlySpan span = new ReadOnlySpan(new byte[] { 0, 1, 77, 2, 3, 77, 77, 4, 5, 77, 77, 77, 88, 6, 6, 77, 77, 8, 9, 77, 0, 1 }); + ReadOnlySpan value = new ReadOnlySpan(new byte[] { 77, 77, 88 }); + int index = span.LastIndexOf(value); + Assert.Equal(10, index); + } + + [Fact] + public static void LastIndexOfSequenceNoMatch_Byte() + { + ReadOnlySpan span = new ReadOnlySpan(new byte[] { 0, 1, 77, 2, 3, 77, 77, 4, 5, 77, 77, 77, 88, 6, 6, 77, 77, 88, 9 }); + ReadOnlySpan value = new ReadOnlySpan(new byte[] { 77, 77, 88, 99 }); + int index = span.LastIndexOf(value); + Assert.Equal(-1, index); + } + + [Fact] + public static void LastIndexOfSequenceNotEvenAHeadMatch_Byte() + { + ReadOnlySpan span = new ReadOnlySpan(new byte[] { 0, 1, 77, 2, 3, 77, 77, 4, 5, 77, 77, 77, 88, 6, 6, 77, 77, 88, 9 }); + ReadOnlySpan value = new ReadOnlySpan(new byte[] { 100, 77, 88, 99 }); + int index = span.LastIndexOf(value); + Assert.Equal(-1, index); + } + + [Fact] + public static void LastIndexOfSequenceMatchAtVeryEnd_Byte() + { + ReadOnlySpan span = new ReadOnlySpan(new byte[] { 0, 1, 2, 3, 4, 5 }); + ReadOnlySpan value = new ReadOnlySpan(new byte[] { 3, 4, 5 }); + int index = span.LastIndexOf(value); + Assert.Equal(3, index); + } + + [Fact] + public static void LastIndexOfSequenceJustPastVeryEnd_Byte() + { + ReadOnlySpan span = new ReadOnlySpan(new byte[] { 0, 1, 2, 3, 4, 5 }, 0, 5); + ReadOnlySpan value = new ReadOnlySpan(new byte[] { 3, 4, 5 }); + int index = span.LastIndexOf(value); + Assert.Equal(-1, index); + } + + [Fact] + public static void LastIndexOfSequenceZeroLengthValue_Byte() + { + // A zero-length value is always "found" at the start of the span. + ReadOnlySpan span = new ReadOnlySpan(new byte[] { 0, 1, 77, 2, 3, 77, 77, 4, 5, 77, 77, 77, 88, 6, 6, 77, 77, 88, 9 }); + ReadOnlySpan value = new ReadOnlySpan(Array.Empty()); + int index = span.LastIndexOf(value); + Assert.Equal(0, index); + } + + [Fact] + public static void LastIndexOfSequenceZeroLengthSpan_Byte() + { + ReadOnlySpan span = new ReadOnlySpan(Array.Empty()); + ReadOnlySpan value = new ReadOnlySpan(new byte[] { 1, 2, 3 }); + int index = span.LastIndexOf(value); + Assert.Equal(-1, index); + } + + [Fact] + public static void LastIndexOfSequenceLengthOneValue_Byte() + { + // A zero-length value is always "found" at the start of the span. + ReadOnlySpan span = new ReadOnlySpan(new byte[] { 0, 1, 2, 3, 4, 5 }); + ReadOnlySpan value = new ReadOnlySpan(new byte[] { 2 }); + int index = span.LastIndexOf(value); + Assert.Equal(2, index); + } + + [Fact] + public static void LastIndexOfSequenceLengthOneValueAtVeryEnd_Byte() + { + // A zero-length value is always "found" at the start of the span. + ReadOnlySpan span = new ReadOnlySpan(new byte[] { 0, 1, 2, 3, 4, 5 }); + ReadOnlySpan value = new ReadOnlySpan(new byte[] { 5 }); + int index = span.LastIndexOf(value); + Assert.Equal(5, index); + } + + [Fact] + public static void LastIndexOfSequenceLengthOneValueMultipleTimes_Byte() + { + // A zero-length value is always "found" at the start of the span. + ReadOnlySpan span = new ReadOnlySpan(new byte[] { 0, 1, 5, 3, 4, 5 }); + ReadOnlySpan value = new ReadOnlySpan(new byte[] { 5 }); + int index = span.LastIndexOf(value); + Assert.Equal(5, index); + } + + [Fact] + public static void LastIndexOfSequenceLengthOneValueJustPasttVeryEnd_Byte() + { + // A zero-length value is always "found" at the start of the span. + ReadOnlySpan span = new ReadOnlySpan(new byte[] { 0, 1, 2, 3, 4, 5 }, 0, 5); + ReadOnlySpan value = new ReadOnlySpan(new byte[] { 5 }); + int index = span.LastIndexOf(value); + Assert.Equal(-1, index); + } + } +} diff --git a/src/System.Memory/tests/ReadOnlySpan/LastIndexOfSequence.char.cs b/src/System.Memory/tests/ReadOnlySpan/LastIndexOfSequence.char.cs new file mode 100644 index 000000000000..63f6635f7678 --- /dev/null +++ b/src/System.Memory/tests/ReadOnlySpan/LastIndexOfSequence.char.cs @@ -0,0 +1,133 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using Xunit; + +namespace System.SpanTests +{ + public static partial class ReadOnlySpanTests + { + [Fact] + public static void LastIndexOfSequenceMatchAtStart_Char() + { + ReadOnlySpan span = new ReadOnlySpan(new char[] { '5', '1', '7', '2', '3', '7', '7', '4', '5', '7', '7', '7', '8', '6', '6', '7', '7', '8', '9' }); + ReadOnlySpan value = new ReadOnlySpan(new char[] { '5', '1', '7' }); + int index = span.LastIndexOf(value); + Assert.Equal(0, index); + } + + [Fact] + public static void LastIndexOfSequenceMultipleMatch_Char() + { + ReadOnlySpan span = new ReadOnlySpan(new char[] { '1', '2', '3', '1', '2', '3', '1', '2', '3', '1' }); + ReadOnlySpan value = new ReadOnlySpan(new char[] { '2', '3' }); + int index = span.LastIndexOf(value); + Assert.Equal(7, index); + } + + [Fact] + public static void LastIndexOfSequenceRestart_Char() + { + ReadOnlySpan span = new ReadOnlySpan(new char[] { '5', '1', '7', '2', '3', '7', '7', '4', '5', '7', '7', '7', '8', '6', '6', '7', '7', '6', '9', '7', '0', '1' }); + ReadOnlySpan value = new ReadOnlySpan(new char[] { '7', '7', '8' }); + int index = span.LastIndexOf(value); + Assert.Equal(10, index); + } + + [Fact] + public static void LastIndexOfSequenceNoMatch_Char() + { + ReadOnlySpan span = new ReadOnlySpan(new char[] { '0', '1', '7', '2', '3', '7', '7', '4', '5', '7', '7', '7', '8', '6', '6', '7', '7', '8', '9' }); + ReadOnlySpan value = new ReadOnlySpan(new char[] { '7', '7', '8', 'X' }); + int index = span.LastIndexOf(value); + Assert.Equal(-1, index); + } + + [Fact] + public static void LastIndexOfSequenceNotEvenAHeadMatch_Char() + { + ReadOnlySpan span = new ReadOnlySpan(new char[] { '0', '1', '7', '2', '3', '7', '7', '4', '5', '7', '7', '7', '8', '6', '6', '7', '7', '8', '9' }); + ReadOnlySpan value = new ReadOnlySpan(new char[] { 'X', '7', '8', '9' }); + int index = span.LastIndexOf(value); + Assert.Equal(-1, index); + } + + [Fact] + public static void LastIndexOfSequenceMatchAtVeryEnd_Char() + { + ReadOnlySpan span = new ReadOnlySpan(new char[] { '0', '1', '2', '3', '4', '5' }); + ReadOnlySpan value = new ReadOnlySpan(new char[] { '3', '4', '5' }); + int index = span.LastIndexOf(value); + Assert.Equal(3, index); + } + + [Fact] + public static void LastIndexOfSequenceJustPastVeryEnd_Char() + { + ReadOnlySpan span = new ReadOnlySpan(new char[] { '0', '1', '2', '3', '4', '5' }, 0, 5); + ReadOnlySpan value = new ReadOnlySpan(new char[] { '3', '4', '5' }); + int index = span.LastIndexOf(value); + Assert.Equal(-1, index); + } + + [Fact] + public static void LastIndexOfSequenceZeroLengthValue_Char() + { + // A zero-length value is always "found" at the start of the span. + ReadOnlySpan span = new ReadOnlySpan(new char[] { '0', '1', '7', '2', '3', '7', '7', '4', '5', '7', '7', '7', '8', '6', '6', '7', '7', '8', '9' }); + ReadOnlySpan value = new ReadOnlySpan(Array.Empty()); + int index = span.LastIndexOf(value); + Assert.Equal(0, index); + } + + [Fact] + public static void LastIndexOfSequenceZeroLengthSpan_Char() + { + ReadOnlySpan span = new ReadOnlySpan(Array.Empty()); + ReadOnlySpan value = new ReadOnlySpan(new char[] { '1', '2', '3' }); + int index = span.LastIndexOf(value); + Assert.Equal(-1, index); + } + + [Fact] + public static void LastIndexOfSequenceLengthOneValue_Char() + { + // A zero-length value is always "found" at the start of the span. + ReadOnlySpan span = new ReadOnlySpan(new char[] { '0', '1', '2', '3', '4', '5' }); + ReadOnlySpan value = new ReadOnlySpan(new char[] { '2' }); + int index = span.LastIndexOf(value); + Assert.Equal(2, index); + } + + [Fact] + public static void LastIndexOfSequenceLengthOneValueAtVeryEnd_Char() + { + // A zero-length value is always "found" at the start of the span. + ReadOnlySpan span = new ReadOnlySpan(new char[] { '0', '1', '2', '3', '4', '5' }); + ReadOnlySpan value = new ReadOnlySpan(new char[] { '5' }); + int index = span.LastIndexOf(value); + Assert.Equal(5, index); + } + + [Fact] + public static void LastIndexOfSequenceLengthOneValueMultipleTimes_Char() + { + // A zero-length value is always "found" at the start of the span. + ReadOnlySpan span = new ReadOnlySpan(new char[] { '0', '1', '5', '3', '4', '5' }); + ReadOnlySpan value = new ReadOnlySpan(new char[] { '5' }); + int index = span.LastIndexOf(value); + Assert.Equal(5, index); + } + + [Fact] + public static void LastIndexOfSequenceLengthOneValueJustPasttVeryEnd_Char() + { + // A zero-length value is always "found" at the start of the span. + ReadOnlySpan span = new ReadOnlySpan(new char[] { '0', '1', '2', '3', '4', '5' }, 0, 5); + ReadOnlySpan value = new ReadOnlySpan(new char[] { '5' }); + int index = span.LastIndexOf(value); + Assert.Equal(-1, index); + } + } +} diff --git a/src/System.Memory/tests/Span/LastIndexOfSequence.T.cs b/src/System.Memory/tests/Span/LastIndexOfSequence.T.cs new file mode 100644 index 000000000000..7ca8c26181b6 --- /dev/null +++ b/src/System.Memory/tests/Span/LastIndexOfSequence.T.cs @@ -0,0 +1,133 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using Xunit; + +namespace System.SpanTests +{ + public static partial class SpanTests + { + [Fact] + public static void LastIndexOfSequenceMatchAtStart() + { + Span span = new Span(new int[] { 5, 1, 77, 2, 3, 77, 77, 4, 5, 77, 77, 77, 88, 6, 6, 77, 77, 88, 9 }); + Span value = new Span(new int[] { 5, 1, 77 }); + int index = span.LastIndexOf(value); + Assert.Equal(0, index); + } + + [Fact] + public static void LastIndexOfSequenceMultipleMatch() + { + Span span = new Span(new int[] { 1, 2, 3, 1, 2, 3, 1, 2, 3, 1 }); + Span value = new Span(new int[] { 2, 3 }); + int index = span.LastIndexOf(value); + Assert.Equal(7, index); + } + + [Fact] + public static void LastIndexOfSequenceRestart() + { + Span span = new Span(new int[] { 0, 1, 77, 2, 3, 77, 77, 4, 5, 77, 77, 77, 88, 6, 6, 77, 77, 8, 9, 77, 0, 1 }); + Span value = new Span(new int[] { 77, 77, 88 }); + int index = span.LastIndexOf(value); + Assert.Equal(10, index); + } + + [Fact] + public static void LastIndexOfSequenceNoMatch() + { + Span span = new Span(new int[] { 0, 1, 77, 2, 3, 77, 77, 4, 5, 77, 77, 77, 88, 6, 6, 77, 77, 88, 9 }); + Span value = new Span(new int[] { 77, 77, 88, 99 }); + int index = span.LastIndexOf(value); + Assert.Equal(-1, index); + } + + [Fact] + public static void LastIndexOfSequenceNotEvenAHeadMatch() + { + Span span = new Span(new int[] { 0, 1, 77, 2, 3, 77, 77, 4, 5, 77, 77, 77, 88, 6, 6, 77, 77, 88, 9 }); + Span value = new Span(new int[] { 100, 77, 88, 99 }); + int index = span.LastIndexOf(value); + Assert.Equal(-1, index); + } + + [Fact] + public static void LastIndexOfSequenceMatchAtVeryEnd() + { + Span span = new Span(new int[] { 0, 1, 2, 3, 4, 5 }); + Span value = new Span(new int[] { 3, 4, 5 }); + int index = span.LastIndexOf(value); + Assert.Equal(3, index); + } + + [Fact] + public static void LastIndexOfSequenceJustPastVeryEnd() + { + Span span = new Span(new int[] { 0, 1, 2, 3, 4, 5 }, 0, 5); + Span value = new Span(new int[] { 3, 4, 5 }); + int index = span.LastIndexOf(value); + Assert.Equal(-1, index); + } + + [Fact] + public static void LastIndexOfSequenceZeroLengthValue() + { + // A zero-length value is always "found" at the start of the span. + Span span = new Span(new int[] { 0, 1, 77, 2, 3, 77, 77, 4, 5, 77, 77, 77, 88, 6, 6, 77, 77, 88, 9 }); + Span value = new Span(Array.Empty()); + int index = span.LastIndexOf(value); + Assert.Equal(0, index); + } + + [Fact] + public static void LastIndexOfSequenceZeroLengthSpan() + { + Span span = new Span(Array.Empty()); + Span value = new Span(new int[] { 1, 2, 3 }); + int index = span.LastIndexOf(value); + Assert.Equal(-1, index); + } + + [Fact] + public static void LastIndexOfSequenceLengthOneValue() + { + // A zero-length value is always "found" at the start of the span. + Span span = new Span(new int[] { 0, 1, 2, 3, 4, 5 }); + Span value = new Span(new int[] { 2 }); + int index = span.LastIndexOf(value); + Assert.Equal(2, index); + } + + [Fact] + public static void LastIndexOfSequenceLengthOneValueAtVeryEnd() + { + // A zero-length value is always "found" at the start of the span. + Span span = new Span(new int[] { 0, 1, 2, 3, 4, 5 }); + Span value = new Span(new int[] { 5 }); + int index = span.LastIndexOf(value); + Assert.Equal(5, index); + } + + [Fact] + public static void LastIndexOfSequenceLengthOneValueMultipleTimes() + { + // A zero-length value is always "found" at the start of the span. + Span span = new Span(new int[] { 0, 1, 5, 3, 4, 5 }); + Span value = new Span(new int[] { 5 }); + int index = span.LastIndexOf(value); + Assert.Equal(5, index); + } + + [Fact] + public static void LastIndexOfSequenceLengthOneValueJustPasttVeryEnd() + { + // A zero-length value is always "found" at the start of the span. + Span span = new Span(new int[] { 0, 1, 2, 3, 4, 5 }, 0, 5); + Span value = new Span(new int[] { 5 }); + int index = span.LastIndexOf(value); + Assert.Equal(-1, index); + } + } +} diff --git a/src/System.Memory/tests/Span/LastIndexOfSequence.byte.cs b/src/System.Memory/tests/Span/LastIndexOfSequence.byte.cs new file mode 100644 index 000000000000..6aef9db54204 --- /dev/null +++ b/src/System.Memory/tests/Span/LastIndexOfSequence.byte.cs @@ -0,0 +1,133 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using Xunit; + +namespace System.SpanTests +{ + public static partial class SpanTests + { + [Fact] + public static void LastIndexOfSequenceMatchAtStart_Byte() + { + Span span = new Span(new byte[] { 5, 1, 77, 2, 3, 77, 77, 4, 5, 77, 77, 77, 88, 6, 6, 77, 77, 88, 9 }); + Span value = new Span(new byte[] { 5, 1, 77 }); + int index = span.LastIndexOf(value); + Assert.Equal(0, index); + } + + [Fact] + public static void LastIndexOfSequenceMultipleMatch_Byte() + { + Span span = new Span(new byte[] { 1, 2, 3, 1, 2, 3, 1, 2, 3, 1 }); + Span value = new Span(new byte[] { 2, 3 }); + int index = span.LastIndexOf(value); + Assert.Equal(7, index); + } + + [Fact] + public static void LastIndexOfSequenceRestart_Byte() + { + Span span = new Span(new byte[] { 0, 1, 77, 2, 3, 77, 77, 4, 5, 77, 77, 77, 88, 6, 6, 77, 77, 8, 9, 77, 0, 1 }); + Span value = new Span(new byte[] { 77, 77, 88 }); + int index = span.LastIndexOf(value); + Assert.Equal(10, index); + } + + [Fact] + public static void LastIndexOfSequenceNoMatch_Byte() + { + Span span = new Span(new byte[] { 0, 1, 77, 2, 3, 77, 77, 4, 5, 77, 77, 77, 88, 6, 6, 77, 77, 88, 9 }); + Span value = new Span(new byte[] { 77, 77, 88, 99 }); + int index = span.LastIndexOf(value); + Assert.Equal(-1, index); + } + + [Fact] + public static void LastIndexOfSequenceNotEvenAHeadMatch_Byte() + { + Span span = new Span(new byte[] { 0, 1, 77, 2, 3, 77, 77, 4, 5, 77, 77, 77, 88, 6, 6, 77, 77, 88, 9 }); + Span value = new Span(new byte[] { 100, 77, 88, 99 }); + int index = span.LastIndexOf(value); + Assert.Equal(-1, index); + } + + [Fact] + public static void LastIndexOfSequenceMatchAtVeryEnd_Byte() + { + Span span = new Span(new byte[] { 0, 1, 2, 3, 4, 5 }); + Span value = new Span(new byte[] { 3, 4, 5 }); + int index = span.LastIndexOf(value); + Assert.Equal(3, index); + } + + [Fact] + public static void LastIndexOfSequenceJustPastVeryEnd_Byte() + { + Span span = new Span(new byte[] { 0, 1, 2, 3, 4, 5 }, 0, 5); + Span value = new Span(new byte[] { 3, 4, 5 }); + int index = span.LastIndexOf(value); + Assert.Equal(-1, index); + } + + [Fact] + public static void LastIndexOfSequenceZeroLengthValue_Byte() + { + // A zero-length value is always "found" at the start of the span. + Span span = new Span(new byte[] { 0, 1, 77, 2, 3, 77, 77, 4, 5, 77, 77, 77, 88, 6, 6, 77, 77, 88, 9 }); + Span value = new Span(Array.Empty()); + int index = span.LastIndexOf(value); + Assert.Equal(0, index); + } + + [Fact] + public static void LastIndexOfSequenceZeroLengthSpan_Byte() + { + Span span = new Span(Array.Empty()); + Span value = new Span(new byte[] { 1, 2, 3 }); + int index = span.LastIndexOf(value); + Assert.Equal(-1, index); + } + + [Fact] + public static void LastIndexOfSequenceLengthOneValue_Byte() + { + // A zero-length value is always "found" at the start of the span. + Span span = new Span(new byte[] { 0, 1, 2, 3, 4, 5 }); + Span value = new Span(new byte[] { 2 }); + int index = span.LastIndexOf(value); + Assert.Equal(2, index); + } + + [Fact] + public static void LastIndexOfSequenceLengthOneValueAtVeryEnd_Byte() + { + // A zero-length value is always "found" at the start of the span. + Span span = new Span(new byte[] { 0, 1, 2, 3, 4, 5 }); + Span value = new Span(new byte[] { 5 }); + int index = span.LastIndexOf(value); + Assert.Equal(5, index); + } + + [Fact] + public static void LastIndexOfSequenceLengthOneValueMultipleTimes_Byte() + { + // A zero-length value is always "found" at the start of the span. + Span span = new Span(new byte[] { 0, 1, 5, 3, 4, 5 }); + Span value = new Span(new byte[] { 5 }); + int index = span.LastIndexOf(value); + Assert.Equal(5, index); + } + + [Fact] + public static void LastIndexOfSequenceLengthOneValueJustPasttVeryEnd_Byte() + { + // A zero-length value is always "found" at the start of the span. + Span span = new Span(new byte[] { 0, 1, 2, 3, 4, 5 }, 0, 5); + Span value = new Span(new byte[] { 5 }); + int index = span.LastIndexOf(value); + Assert.Equal(-1, index); + } + } +} diff --git a/src/System.Memory/tests/Span/LastIndexOfSequence.char.cs b/src/System.Memory/tests/Span/LastIndexOfSequence.char.cs new file mode 100644 index 000000000000..af027cb54a12 --- /dev/null +++ b/src/System.Memory/tests/Span/LastIndexOfSequence.char.cs @@ -0,0 +1,133 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using Xunit; + +namespace System.SpanTests +{ + public static partial class SpanTests + { + [Fact] + public static void LastIndexOfSequenceMatchAtStart_Char() + { + Span span = new Span(new char[] { '5', '1', '7', '2', '3', '7', '7', '4', '5', '7', '7', '7', '8', '6', '6', '7', '7', '8', '9' }); + Span value = new Span(new char[] { '5', '1', '7' }); + int index = span.LastIndexOf(value); + Assert.Equal(0, index); + } + + [Fact] + public static void LastIndexOfSequenceMultipleMatch_Char() + { + Span span = new Span(new char[] { '1', '2', '3', '1', '2', '3', '1', '2', '3', '1' }); + Span value = new Span(new char[] { '2', '3' }); + int index = span.LastIndexOf(value); + Assert.Equal(7, index); + } + + [Fact] + public static void LastIndexOfSequenceRestart_Char() + { + Span span = new Span(new char[] { '5', '1', '7', '2', '3', '7', '7', '4', '5', '7', '7', '7', '8', '6', '6', '7', '7', '6', '9', '7', '0', '1' }); + Span value = new Span(new char[] { '7', '7', '8' }); + int index = span.LastIndexOf(value); + Assert.Equal(10, index); + } + + [Fact] + public static void LastIndexOfSequenceNoMatch_Char() + { + Span span = new Span(new char[] { '0', '1', '7', '2', '3', '7', '7', '4', '5', '7', '7', '7', '8', '6', '6', '7', '7', '8', '9' }); + Span value = new Span(new char[] { '7', '7', '8', 'X' }); + int index = span.LastIndexOf(value); + Assert.Equal(-1, index); + } + + [Fact] + public static void LastIndexOfSequenceNotEvenAHeadMatch_Char() + { + Span span = new Span(new char[] { '0', '1', '7', '2', '3', '7', '7', '4', '5', '7', '7', '7', '8', '6', '6', '7', '7', '8', '9' }); + Span value = new Span(new char[] { 'X', '7', '8', '9' }); + int index = span.LastIndexOf(value); + Assert.Equal(-1, index); + } + + [Fact] + public static void LastIndexOfSequenceMatchAtVeryEnd_Char() + { + Span span = new Span(new char[] { '0', '1', '2', '3', '4', '5' }); + Span value = new Span(new char[] { '3', '4', '5' }); + int index = span.LastIndexOf(value); + Assert.Equal(3, index); + } + + [Fact] + public static void LastIndexOfSequenceJustPastVeryEnd_Char() + { + Span span = new Span(new char[] { '0', '1', '2', '3', '4', '5' }, 0, 5); + Span value = new Span(new char[] { '3', '4', '5' }); + int index = span.LastIndexOf(value); + Assert.Equal(-1, index); + } + + [Fact] + public static void LastIndexOfSequenceZeroLengthValue_Char() + { + // A zero-length value is always "found" at the start of the span. + Span span = new Span(new char[] { '0', '1', '7', '2', '3', '7', '7', '4', '5', '7', '7', '7', '8', '6', '6', '7', '7', '8', '9' }); + Span value = new Span(Array.Empty()); + int index = span.LastIndexOf(value); + Assert.Equal(0, index); + } + + [Fact] + public static void LastIndexOfSequenceZeroLengthSpan_Char() + { + Span span = new Span(Array.Empty()); + Span value = new Span(new char[] { '1', '2', '3' }); + int index = span.LastIndexOf(value); + Assert.Equal(-1, index); + } + + [Fact] + public static void LastIndexOfSequenceLengthOneValue_Char() + { + // A zero-length value is always "found" at the start of the span. + Span span = new Span(new char[] { '0', '1', '2', '3', '4', '5' }); + Span value = new Span(new char[] { '2' }); + int index = span.LastIndexOf(value); + Assert.Equal(2, index); + } + + [Fact] + public static void LastIndexOfSequenceLengthOneValueAtVeryEnd_Char() + { + // A zero-length value is always "found" at the start of the span. + Span span = new Span(new char[] { '0', '1', '2', '3', '4', '5' }); + Span value = new Span(new char[] { '5' }); + int index = span.LastIndexOf(value); + Assert.Equal(5, index); + } + + [Fact] + public static void LastIndexOfSequenceLengthOneValueMultipleTimes_Char() + { + // A zero-length value is always "found" at the start of the span. + Span span = new Span(new char[] { '0', '1', '5', '3', '4', '5' }); + Span value = new Span(new char[] { '5' }); + int index = span.LastIndexOf(value); + Assert.Equal(5, index); + } + + [Fact] + public static void LastIndexOfSequenceLengthOneValueJustPasttVeryEnd_Char() + { + // A zero-length value is always "found" at the start of the span. + Span span = new Span(new char[] { '0', '1', '2', '3', '4', '5' }, 0, 5); + Span value = new Span(new char[] { '5' }); + int index = span.LastIndexOf(value); + Assert.Equal(-1, index); + } + } +} diff --git a/src/System.Memory/tests/System.Memory.Tests.csproj b/src/System.Memory/tests/System.Memory.Tests.csproj index 3b97a7784b1f..8a9cb59d7d31 100644 --- a/src/System.Memory/tests/System.Memory.Tests.csproj +++ b/src/System.Memory/tests/System.Memory.Tests.csproj @@ -41,6 +41,9 @@ + + + @@ -76,6 +79,9 @@ + + + From a9810f98c454fd7e1fd2c13aa77d4a721fdb1777 Mon Sep 17 00:00:00 2001 From: ahsonkhan Date: Tue, 5 Dec 2017 23:04:26 -0800 Subject: [PATCH 3/9] Vectorize LastIndexOf similar to IndexOf --- .../src/System/SpanHelpers.byte.cs | 136 ++++++++++++++---- 1 file changed, 108 insertions(+), 28 deletions(-) diff --git a/src/System.Memory/src/System/SpanHelpers.byte.cs b/src/System.Memory/src/System/SpanHelpers.byte.cs index cd8eec6d5c29..04d5247444a6 100644 --- a/src/System.Memory/src/System/SpanHelpers.byte.cs +++ b/src/System.Memory/src/System/SpanHelpers.byte.cs @@ -220,67 +220,109 @@ public static unsafe int LastIndexOf(ref byte searchSpace, byte value, int lengt { Debug.Assert(length >= 0); - while (length >= 8) + uint uValue = value; // Use uint for comparisons to avoid unnecessary 8->32 extensions + IntPtr index = (IntPtr)(uint)length; // Use UIntPtr for arithmetic to avoid unnecessary 64->32->64 truncations + IntPtr nLength = (IntPtr)(uint)length; +#if !netstandard11 + if (Vector.IsHardwareAccelerated && length >= Vector.Count * 2) { - length -= 8; + unchecked + { + int unaligned = (int)(byte*)Unsafe.AsPointer(ref searchSpace) & (Vector.Count - 1); + nLength = (IntPtr)(((length & (Vector.Count - 1)) + unaligned) & (Vector.Count - 1)); + } + } +SequentialScan: +#endif + while ((byte*)nLength >= (byte*)8) + { + nLength -= 8; + index -= 8; - if (value.Equals(Unsafe.Add(ref searchSpace, length + 7))) + if (uValue == Unsafe.Add(ref searchSpace, index + 7)) goto Found7; - if (value.Equals(Unsafe.Add(ref searchSpace, length + 6))) + if (uValue == Unsafe.Add(ref searchSpace, index + 6)) goto Found6; - if (value.Equals(Unsafe.Add(ref searchSpace, length + 5))) + if (uValue == Unsafe.Add(ref searchSpace, index + 5)) goto Found5; - if (value.Equals(Unsafe.Add(ref searchSpace, length + 4))) + if (uValue == Unsafe.Add(ref searchSpace, index + 4)) goto Found4; - if (value.Equals(Unsafe.Add(ref searchSpace, length + 3))) + if (uValue == Unsafe.Add(ref searchSpace, index + 3)) goto Found3; - if (value.Equals(Unsafe.Add(ref searchSpace, length + 2))) + if (uValue == Unsafe.Add(ref searchSpace, index + 2)) goto Found2; - if (value.Equals(Unsafe.Add(ref searchSpace, length + 1))) + if (uValue == Unsafe.Add(ref searchSpace, index + 1)) goto Found1; - if (value.Equals(Unsafe.Add(ref searchSpace, length))) + if (uValue == Unsafe.Add(ref searchSpace, index)) goto Found; } - if (length >= 4) + if ((byte*)nLength >= (byte*)4) { - length -= 4; + nLength -= 4; + index -= 4; - if (value.Equals(Unsafe.Add(ref searchSpace, length + 3))) + if (uValue == Unsafe.Add(ref searchSpace, index + 3)) goto Found3; - if (value.Equals(Unsafe.Add(ref searchSpace, length + 2))) + if (uValue == Unsafe.Add(ref searchSpace, index + 2)) goto Found2; - if (value.Equals(Unsafe.Add(ref searchSpace, length + 1))) + if (uValue == Unsafe.Add(ref searchSpace, index + 1)) goto Found1; - if (value.Equals(Unsafe.Add(ref searchSpace, length))) + if (uValue == Unsafe.Add(ref searchSpace, index)) goto Found; } - while (length > 0) + while ((byte*)nLength > (byte*)0) { - length--; + nLength -= 1; + index -= 1; - if (value.Equals(Unsafe.Add(ref searchSpace, length))) + if (uValue == Unsafe.Add(ref searchSpace, index)) goto Found; } - return -1; +#if !netstandard11 + if (Vector.IsHardwareAccelerated && ((int)(byte*)index > 0)) + { + nLength = (IntPtr)(uint)((uint)index & ~(Vector.Count - 1)); + // Get comparison Vector + Vector vComparison = GetVector(value); + while ((byte*)nLength > (byte*)(Vector.Count - 1)) + { + var vMatches = Vector.Equals(vComparison, Unsafe.ReadUnaligned>(ref Unsafe.AddByteOffset(ref searchSpace, index - Vector.Count))); + if (Vector.Zero.Equals(vMatches)) + { + index -= Vector.Count; + nLength -= Vector.Count; + continue; + } + // Find offset of first match + return (int)(byte*)(index) - Vector.Count + LocateLastFoundByte(vMatches); + } + if ((int)(byte*)index > 0) + { + nLength = index; + goto SequentialScan; + } + } +#endif + return -1; Found: // Workaround for https://github.com/dotnet/coreclr/issues/13549 - return length; + return (int)(byte*)index; Found1: - return length + 1; + return (int)(byte*)(index + 1); Found2: - return length + 2; + return (int)(byte*)(index + 2); Found3: - return length + 3; + return (int)(byte*)(index + 3); Found4: - return length + 4; + return (int)(byte*)(index + 4); Found5: - return length + 5; + return (int)(byte*)(index + 5); Found6: - return length + 6; + return (int)(byte*)(index + 6); Found7: - return length + 7; + return (int)(byte*)(index + 7); } public static unsafe int IndexOfAny(ref byte searchSpace, byte value0, byte value1, int length) @@ -637,6 +679,29 @@ private static int LocateFirstFoundByte(Vector match) } #endif +#if !netstandard11 + // Vector sub-search adapted from https://github.com/aspnet/KestrelHttpServer/pull/1138 + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private static int LocateLastFoundByte(Vector match) + { + var vector64 = Vector.AsVectorUInt64(match); + ulong candidate = 0; + int i = Vector.Count - 1; + // Pattern unrolled by jit https://github.com/dotnet/coreclr/pull/8001 + for (; i >= 0; i--) + { + candidate = vector64[i]; + if (candidate != 0) + { + break; + } + } + + // Single LEA instruction with jitted const (using function result) + return i * 8 + LocateLastFoundByte(candidate); + } +#endif + #if !netstandard11 [MethodImpl(MethodImplOptions.AggressiveInlining)] private static int LocateFirstFoundByte(ulong match) @@ -651,6 +716,21 @@ private static int LocateFirstFoundByte(ulong match) } #endif +#if !netstandard11 + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private static int LocateLastFoundByte(ulong match) + { + // Find the most significant byte that has its highest bit set + int index = 7; + while((long)match > 0) + { + match = match << 8; + index--; + } + return index; + } +#endif + #if !netstandard11 [MethodImpl(MethodImplOptions.AggressiveInlining)] private static Vector GetVector(byte vectorByte) From 7ceb7949253e7a3f32492e27ef70aae2ca428d1d Mon Sep 17 00:00:00 2001 From: ahsonkhan Date: Tue, 5 Dec 2017 23:22:52 -0800 Subject: [PATCH 4/9] Add LastIndexOf performance tests --- .../tests/Performance/Perf.Span.IndexOf.cs | 76 +++++++++++++++++++ 1 file changed, 76 insertions(+) diff --git a/src/System.Memory/tests/Performance/Perf.Span.IndexOf.cs b/src/System.Memory/tests/Performance/Perf.Span.IndexOf.cs index 75575338a6ac..8deac1000ec9 100644 --- a/src/System.Memory/tests/Performance/Perf.Span.IndexOf.cs +++ b/src/System.Memory/tests/Performance/Perf.Span.IndexOf.cs @@ -86,5 +86,81 @@ public void StringIndexOfChar(int size) } Assert.Equal(size/2, index); } + + [Benchmark(InnerIterationCount = InnerCount)] + [InlineData(1)] + [InlineData(10)] + [InlineData(100)] + [InlineData(1000)] + public void SpanLastIndexOfChar(int size) + { + Span charSpan = new char[size]; + charSpan[size / 2] = '5'; + + int index = 0; + foreach (BenchmarkIteration iteration in Benchmark.Iterations) + { + using (iteration.StartMeasurement()) + { + for (int i = 0; i < Benchmark.InnerIterationCount; i++) + { + index |= charSpan.LastIndexOf('5'); + } + } + } + Assert.Equal(size / 2, index); + } + + [Benchmark(InnerIterationCount = InnerCount)] + [InlineData(1)] + [InlineData(10)] + [InlineData(100)] + [InlineData(1000)] + public void SpanLastIndexOfCharAsBytes(int size) + { + Span charSpan = new char[size]; + charSpan[size / 2] = '5'; + Span byteSpan = charSpan.AsBytes(); + + int index = 0; + foreach (BenchmarkIteration iteration in Benchmark.Iterations) + { + using (iteration.StartMeasurement()) + { + for (int i = 0; i < Benchmark.InnerIterationCount; i++) + { + index |= byteSpan.LastIndexOf(53); // '5' = 53 + } + } + } + Assert.Equal(size > 1 ? size : 0, index); + } + + [Benchmark(InnerIterationCount = InnerCount)] + [InlineData(1)] + [InlineData(10)] + [InlineData(100)] + [InlineData(1000)] + public void StringLastIndexOfChar(int size) + { + string str = new string('0', size / 2) + "5"; + if (size > 1) + { + str += new string('0', size / 2 - 1); + } + + int index = 0; + foreach (BenchmarkIteration iteration in Benchmark.Iterations) + { + using (iteration.StartMeasurement()) + { + for (int i = 0; i < Benchmark.InnerIterationCount; i++) + { + index |= str.LastIndexOf('5'); + } + } + } + Assert.Equal(size / 2, index); + } } } From 46e85e3d55546f8ea781c4c2fff0cce195ccbe80 Mon Sep 17 00:00:00 2001 From: ahsonkhan Date: Wed, 6 Dec 2017 16:44:02 -0800 Subject: [PATCH 5/9] Adding IndexOf and LastIndexOf tests for reference type (string). --- .../tests/ReadOnlySpan/IndexOf.T.cs | 69 +++++++++++ .../tests/ReadOnlySpan/IndexOfSequence.T.cs | 112 ++++++++++++++++++ .../tests/ReadOnlySpan/LastIndexOf.T.cs | 69 +++++++++++ .../ReadOnlySpan/LastIndexOfSequence.T.cs | 112 ++++++++++++++++++ src/System.Memory/tests/Span/IndexOf.T.cs | 69 +++++++++++ .../tests/Span/IndexOfSequence.T.cs | 112 ++++++++++++++++++ src/System.Memory/tests/Span/LastIndexOf.T.cs | 69 +++++++++++ .../tests/Span/LastIndexOfSequence.T.cs | 112 ++++++++++++++++++ 8 files changed, 724 insertions(+) diff --git a/src/System.Memory/tests/ReadOnlySpan/IndexOf.T.cs b/src/System.Memory/tests/ReadOnlySpan/IndexOf.T.cs index 3ace67ee0e72..d0f4c1b14d50 100644 --- a/src/System.Memory/tests/ReadOnlySpan/IndexOf.T.cs +++ b/src/System.Memory/tests/ReadOnlySpan/IndexOf.T.cs @@ -116,5 +116,74 @@ public static void MakeSureNoChecksGoOutOfRange() Assert.Equal(-1, idx); } } + + [Fact] + public static void ZeroLengthIndexOf_String() + { + ReadOnlySpan sp = new ReadOnlySpan(Array.Empty()); + int idx = sp.IndexOf("a"); + Assert.Equal(-1, idx); + } + + [Fact] + public static void TestMatchIndexOf_String() + { + for (int length = 0; length < 32; length++) + { + string[] a = new string[length]; + for (int i = 0; i < length; i++) + { + a[i] = (10 * (i + 1)).ToString(); + } + ReadOnlySpan span = new ReadOnlySpan(a); + + for (int targetIndex = 0; targetIndex < length; targetIndex++) + { + string target = a[targetIndex]; + int idx = span.IndexOf(target); + Assert.Equal(targetIndex, idx); + } + } + } + + [Fact] + public static void TestNoMatchIndexOf_String() + { + var rnd = new Random(42); + for (int length = 0; length <= byte.MaxValue; length++) + { + string[] a = new string[length]; + string target = (rnd.Next(0, 256)).ToString(); + for (int i = 0; i < length; i++) + { + string val = (i + 1).ToString(); + a[i] = val == target ? (target + 1) : val; + } + ReadOnlySpan span = new ReadOnlySpan(a); + + int idx = span.IndexOf(target); + Assert.Equal(-1, idx); + } + } + + [Fact] + public static void TestMultipleMatchIndexOf_String() + { + for (int length = 2; length < 32; length++) + { + string[] a = new string[length]; + for (int i = 0; i < length; i++) + { + a[i] = (10 * (i + 1)).ToString(); + } + + a[length - 1] = "5555"; + a[length - 2] = "5555"; + + ReadOnlySpan span = new ReadOnlySpan(a); + int idx = span.IndexOf("5555"); + Assert.Equal(length - 2, idx); + } + } } } diff --git a/src/System.Memory/tests/ReadOnlySpan/IndexOfSequence.T.cs b/src/System.Memory/tests/ReadOnlySpan/IndexOfSequence.T.cs index 49a863acb279..c699e4febffa 100644 --- a/src/System.Memory/tests/ReadOnlySpan/IndexOfSequence.T.cs +++ b/src/System.Memory/tests/ReadOnlySpan/IndexOfSequence.T.cs @@ -119,5 +119,117 @@ public static void IndexOfSequenceLengthOneValueJustPasttVeryEnd() int index = span.IndexOf(value); Assert.Equal(-1, index); } + + [Fact] + public static void IndexOfSequenceMatchAtStart_String() + { + ReadOnlySpan span = new ReadOnlySpan(new string[] { "5", "1", "77", "2", "3", "77", "77", "4", "5", "77", "77", "77", "88", "6", "6", "77", "77", "88", "9" }); + ReadOnlySpan value = new ReadOnlySpan(new string[] { "5", "1", "77" }); + int index = span.IndexOf(value); + Assert.Equal(0, index); + } + + [Fact] + public static void IndexOfSequenceMultipleMatch_String() + { + ReadOnlySpan span = new ReadOnlySpan(new string[] { "1", "2", "3", "1", "2", "3", "1", "2", "3" }); + ReadOnlySpan value = new ReadOnlySpan(new string[] { "2", "3" }); + int index = span.IndexOf(value); + Assert.Equal(1, index); + } + + [Fact] + public static void IndexOfSequenceRestart_String() + { + ReadOnlySpan span = new ReadOnlySpan(new string[] { "0", "1", "77", "2", "3", "77", "77", "4", "5", "77", "77", "77", "88", "6", "6", "77", "77", "88", "9" }); + ReadOnlySpan value = new ReadOnlySpan(new string[] { "77", "77", "88" }); + int index = span.IndexOf(value); + Assert.Equal(10, index); + } + + [Fact] + public static void IndexOfSequenceNoMatch_String() + { + ReadOnlySpan span = new ReadOnlySpan(new string[] { "0", "1", "77", "2", "3", "77", "77", "4", "5", "77", "77", "77", "88", "6", "6", "77", "77", "88", "9" }); + ReadOnlySpan value = new ReadOnlySpan(new string[] { "77", "77", "88", "99" }); + int index = span.IndexOf(value); + Assert.Equal(-1, index); + } + + [Fact] + public static void IndexOfSequenceNotEvenAHeadMatch_String() + { + ReadOnlySpan span = new ReadOnlySpan(new string[] { "0", "1", "77", "2", "3", "77", "77", "4", "5", "77", "77", "77", "88", "6", "6", "77", "77", "88", "9" }); + ReadOnlySpan value = new ReadOnlySpan(new string[] { "100", "77", "88", "99" }); + int index = span.IndexOf(value); + Assert.Equal(-1, index); + } + + [Fact] + public static void IndexOfSequenceMatchAtVeryEnd_String() + { + ReadOnlySpan span = new ReadOnlySpan(new string[] { "0", "1", "2", "3", "4", "5" }); + ReadOnlySpan value = new ReadOnlySpan(new string[] { "3", "4", "5" }); + int index = span.IndexOf(value); + Assert.Equal(3, index); + } + + [Fact] + public static void IndexOfSequenceJustPastVeryEnd_String() + { + ReadOnlySpan span = new ReadOnlySpan(new string[] { "0", "1", "2", "3", "4", "5" }, 0, 5); + ReadOnlySpan value = new ReadOnlySpan(new string[] { "3", "4", "5" }); + int index = span.IndexOf(value); + Assert.Equal(-1, index); + } + + [Fact] + public static void IndexOfSequenceZeroLengthValue_String() + { + // A zero-length value is always "found" at the start of the span. + ReadOnlySpan span = new ReadOnlySpan(new string[] { "0", "1", "77", "2", "3", "77", "77", "4", "5", "77", "77", "77", "88", "6", "6", "77", "77", "88", "9" }); + ReadOnlySpan value = new ReadOnlySpan(Array.Empty()); + int index = span.IndexOf(value); + Assert.Equal(0, index); + } + + [Fact] + public static void IndexOfSequenceZeroLengthSpan_String() + { + ReadOnlySpan span = new ReadOnlySpan(Array.Empty()); + ReadOnlySpan value = new ReadOnlySpan(new string[] { "1", "2", "3" }); + int index = span.IndexOf(value); + Assert.Equal(-1, index); + } + + [Fact] + public static void IndexOfSequenceLengthOneValue_String() + { + // A zero-length value is always "found" at the start of the span. + ReadOnlySpan span = new ReadOnlySpan(new string[] { "0", "1", "2", "3", "4", "5" }); + ReadOnlySpan value = new ReadOnlySpan(new string[] { "2" }); + int index = span.IndexOf(value); + Assert.Equal(2, index); + } + + [Fact] + public static void IndexOfSequenceLengthOneValueAtVeryEnd_String() + { + // A zero-length value is always "found" at the start of the span. + ReadOnlySpan span = new ReadOnlySpan(new string[] { "0", "1", "2", "3", "4", "5" }); + ReadOnlySpan value = new ReadOnlySpan(new string[] { "5" }); + int index = span.IndexOf(value); + Assert.Equal(5, index); + } + + [Fact] + public static void IndexOfSequenceLengthOneValueJustPasttVeryEnd_String() + { + // A zero-length value is always "found" at the start of the span. + ReadOnlySpan span = new ReadOnlySpan(new string[] { "0", "1", "2", "3", "4", "5" }, 0, 5 ); + ReadOnlySpan value = new ReadOnlySpan(new string[] { "5" }); + int index = span.IndexOf(value); + Assert.Equal(-1, index); + } } } diff --git a/src/System.Memory/tests/ReadOnlySpan/LastIndexOf.T.cs b/src/System.Memory/tests/ReadOnlySpan/LastIndexOf.T.cs index 036635b6c076..136be532220c 100644 --- a/src/System.Memory/tests/ReadOnlySpan/LastIndexOf.T.cs +++ b/src/System.Memory/tests/ReadOnlySpan/LastIndexOf.T.cs @@ -116,5 +116,74 @@ public static void MakeSureNoChecksGoOutOfRangeLastIndexOf() Assert.Equal(-1, idx); } } + + [Fact] + public static void ZeroLengthLastIndexOf_String() + { + ReadOnlySpan sp = new ReadOnlySpan(Array.Empty()); + int idx = sp.LastIndexOf("a"); + Assert.Equal(-1, idx); + } + + [Fact] + public static void TestMatchLastIndexOf_String() + { + for (int length = 0; length < 32; length++) + { + string[] a = new string[length]; + for (int i = 0; i < length; i++) + { + a[i] = (10 * (i + 1)).ToString(); + } + ReadOnlySpan span = new ReadOnlySpan(a); + + for (int targetIndex = 0; targetIndex < length; targetIndex++) + { + string target = a[targetIndex]; + int idx = span.LastIndexOf(target); + Assert.Equal(targetIndex, idx); + } + } + } + + [Fact] + public static void TestNoMatchLastIndexOf_String() + { + var rnd = new Random(42); + for (int length = 0; length <= byte.MaxValue; length++) + { + string[] a = new string[length]; + string target = (rnd.Next(0, 256)).ToString(); + for (int i = 0; i < length; i++) + { + string val = (i + 1).ToString(); + a[i] = val == target ? (target + 1) : val; + } + ReadOnlySpan span = new ReadOnlySpan(a); + + int idx = span.LastIndexOf(target); + Assert.Equal(-1, idx); + } + } + + [Fact] + public static void TestMultipleMatchLastIndexOf_String() + { + for (int length = 2; length < 32; length++) + { + string[] a = new string[length]; + for (int i = 0; i < length; i++) + { + a[i] = (10 * (i + 1)).ToString(); + } + + a[length - 1] = "5555"; + a[length - 2] = "5555"; + + ReadOnlySpan span = new ReadOnlySpan(a); + int idx = span.LastIndexOf("5555"); + Assert.Equal(length - 1, idx); + } + } } } diff --git a/src/System.Memory/tests/ReadOnlySpan/LastIndexOfSequence.T.cs b/src/System.Memory/tests/ReadOnlySpan/LastIndexOfSequence.T.cs index f5876a20d2ad..2dde13b32204 100644 --- a/src/System.Memory/tests/ReadOnlySpan/LastIndexOfSequence.T.cs +++ b/src/System.Memory/tests/ReadOnlySpan/LastIndexOfSequence.T.cs @@ -129,5 +129,117 @@ public static void LastIndexOfSequenceLengthOneValueJustPasttVeryEnd() int index = span.LastIndexOf(value); Assert.Equal(-1, index); } + + [Fact] + public static void LastIndexOfSequenceMatchAtStart_String() + { + ReadOnlySpan span = new ReadOnlySpan(new string[] { "5", "1", "77", "2", "3", "77", "77", "4", "5", "77", "77", "77", "88", "6", "6", "77", "77", "88", "9" }); + ReadOnlySpan value = new ReadOnlySpan(new string[] { "5", "1", "77" }); + int index = span.LastIndexOf(value); + Assert.Equal(0, index); + } + + [Fact] + public static void LastIndexOfSequenceMultipleMatch_String() + { + ReadOnlySpan span = new ReadOnlySpan(new string[] { "1", "2", "3", "1", "2", "3", "1", "2", "3" }); + ReadOnlySpan value = new ReadOnlySpan(new string[] { "2", "3" }); + int index = span.LastIndexOf(value); + Assert.Equal(7, index); + } + + [Fact] + public static void LastIndexOfSequenceRestart_String() + { + ReadOnlySpan span = new ReadOnlySpan(new string[] { "0", "1", "77", "2", "3", "77", "77", "4", "5", "77", "77", "77", "88", "6", "6", "77", "77", "8", "9", "77", "0", "1" }); + ReadOnlySpan value = new ReadOnlySpan(new string[] { "77", "77", "88" }); + int index = span.LastIndexOf(value); + Assert.Equal(10, index); + } + + [Fact] + public static void LastIndexOfSequenceNoMatch_String() + { + ReadOnlySpan span = new ReadOnlySpan(new string[] { "0", "1", "77", "2", "3", "77", "77", "4", "5", "77", "77", "77", "88", "6", "6", "77", "77", "88", "9" }); + ReadOnlySpan value = new ReadOnlySpan(new string[] { "77", "77", "88", "99" }); + int index = span.LastIndexOf(value); + Assert.Equal(-1, index); + } + + [Fact] + public static void LastIndexOfSequenceNotEvenAHeadMatch_String() + { + ReadOnlySpan span = new ReadOnlySpan(new string[] { "0", "1", "77", "2", "3", "77", "77", "4", "5", "77", "77", "77", "88", "6", "6", "77", "77", "88", "9" }); + ReadOnlySpan value = new ReadOnlySpan(new string[] { "100", "77", "88", "99" }); + int index = span.LastIndexOf(value); + Assert.Equal(-1, index); + } + + [Fact] + public static void LastIndexOfSequenceMatchAtVeryEnd_String() + { + ReadOnlySpan span = new ReadOnlySpan(new string[] { "0", "1", "2", "3", "4", "5" }); + ReadOnlySpan value = new ReadOnlySpan(new string[] { "3", "4", "5" }); + int index = span.LastIndexOf(value); + Assert.Equal(3, index); + } + + [Fact] + public static void LastIndexOfSequenceJustPastVeryEnd_String() + { + ReadOnlySpan span = new ReadOnlySpan(new string[] { "0", "1", "2", "3", "4", "5" }, 0, 5); + ReadOnlySpan value = new ReadOnlySpan(new string[] { "3", "4", "5" }); + int index = span.LastIndexOf(value); + Assert.Equal(-1, index); + } + + [Fact] + public static void LastIndexOfSequenceZeroLengthValue_String() + { + // A zero-length value is always "found" at the start of the span. + ReadOnlySpan span = new ReadOnlySpan(new string[] { "0", "1", "77", "2", "3", "77", "77", "4", "5", "77", "77", "77", "88", "6", "6", "77", "77", "88", "9" }); + ReadOnlySpan value = new ReadOnlySpan(Array.Empty()); + int index = span.LastIndexOf(value); + Assert.Equal(0, index); + } + + [Fact] + public static void LastIndexOfSequenceZeroLengthSpan_String() + { + ReadOnlySpan span = new ReadOnlySpan(Array.Empty()); + ReadOnlySpan value = new ReadOnlySpan(new string[] { "1", "2", "3" }); + int index = span.LastIndexOf(value); + Assert.Equal(-1, index); + } + + [Fact] + public static void LastIndexOfSequenceLengthOneValue_String() + { + // A zero-length value is always "found" at the start of the span. + ReadOnlySpan span = new ReadOnlySpan(new string[] { "0", "1", "2", "3", "4", "5" }); + ReadOnlySpan value = new ReadOnlySpan(new string[] { "2" }); + int index = span.LastIndexOf(value); + Assert.Equal(2, index); + } + + [Fact] + public static void LastIndexOfSequenceLengthOneValueAtVeryEnd_String() + { + // A zero-length value is always "found" at the start of the span. + ReadOnlySpan span = new ReadOnlySpan(new string[] { "0", "1", "2", "3", "4", "5" }); + ReadOnlySpan value = new ReadOnlySpan(new string[] { "5" }); + int index = span.LastIndexOf(value); + Assert.Equal(5, index); + } + + [Fact] + public static void LastIndexOfSequenceLengthOneValueJustPasttVeryEnd_String() + { + // A zero-length value is always "found" at the start of the span. + ReadOnlySpan span = new ReadOnlySpan(new string[] { "0", "1", "2", "3", "4", "5" }, 0, 5); + ReadOnlySpan value = new ReadOnlySpan(new string[] { "5" }); + int index = span.LastIndexOf(value); + Assert.Equal(-1, index); + } } } diff --git a/src/System.Memory/tests/Span/IndexOf.T.cs b/src/System.Memory/tests/Span/IndexOf.T.cs index 8d9736be832b..775f4baadd17 100644 --- a/src/System.Memory/tests/Span/IndexOf.T.cs +++ b/src/System.Memory/tests/Span/IndexOf.T.cs @@ -116,5 +116,74 @@ public static void MakeSureNoChecksGoOutOfRange() Assert.Equal(-1, idx); } } + + [Fact] + public static void ZeroLengthIndexOf_String() + { + Span sp = new Span(Array.Empty()); + int idx = sp.IndexOf("a"); + Assert.Equal(-1, idx); + } + + [Fact] + public static void TestMatchIndexOf_String() + { + for (int length = 0; length < 32; length++) + { + string[] a = new string[length]; + for (int i = 0; i < length; i++) + { + a[i] = (10 * (i + 1)).ToString(); + } + Span span = new Span(a); + + for (int targetIndex = 0; targetIndex < length; targetIndex++) + { + string target = a[targetIndex]; + int idx = span.IndexOf(target); + Assert.Equal(targetIndex, idx); + } + } + } + + [Fact] + public static void TestNoMatchIndexOf_String() + { + var rnd = new Random(42); + for (int length = 0; length <= byte.MaxValue; length++) + { + string[] a = new string[length]; + string target = (rnd.Next(0, 256)).ToString(); + for (int i = 0; i < length; i++) + { + string val = (i + 1).ToString(); + a[i] = val == target ? (target + 1) : val; + } + Span span = new Span(a); + + int idx = span.IndexOf(target); + Assert.Equal(-1, idx); + } + } + + [Fact] + public static void TestMultipleMatchIndexOf_String() + { + for (int length = 2; length < 32; length++) + { + string[] a = new string[length]; + for (int i = 0; i < length; i++) + { + a[i] = (10 * (i + 1)).ToString(); + } + + a[length - 1] = "5555"; + a[length - 2] = "5555"; + + Span span = new Span(a); + int idx = span.IndexOf("5555"); + Assert.Equal(length - 2, idx); + } + } } } diff --git a/src/System.Memory/tests/Span/IndexOfSequence.T.cs b/src/System.Memory/tests/Span/IndexOfSequence.T.cs index 9c2ffc5b9117..e8c270c0a2d2 100644 --- a/src/System.Memory/tests/Span/IndexOfSequence.T.cs +++ b/src/System.Memory/tests/Span/IndexOfSequence.T.cs @@ -119,5 +119,117 @@ public static void IndexOfSequenceLengthOneValueJustPasttVeryEnd() int index = span.IndexOf(value); Assert.Equal(-1, index); } + + [Fact] + public static void IndexOfSequenceMatchAtStart_String() + { + Span span = new Span(new string[] { "5", "1", "77", "2", "3", "77", "77", "4", "5", "77", "77", "77", "88", "6", "6", "77", "77", "88", "9" }); + Span value = new Span(new string[] { "5", "1", "77" }); + int index = span.IndexOf(value); + Assert.Equal(0, index); + } + + [Fact] + public static void IndexOfSequenceMultipleMatch_String() + { + Span span = new Span(new string[] { "1", "2", "3", "1", "2", "3", "1", "2", "3" }); + Span value = new Span(new string[] { "2", "3" }); + int index = span.IndexOf(value); + Assert.Equal(1, index); + } + + [Fact] + public static void IndexOfSequenceRestart_String() + { + Span span = new Span(new string[] { "0", "1", "77", "2", "3", "77", "77", "4", "5", "77", "77", "77", "88", "6", "6", "77", "77", "88", "9" }); + Span value = new Span(new string[] { "77", "77", "88" }); + int index = span.IndexOf(value); + Assert.Equal(10, index); + } + + [Fact] + public static void IndexOfSequenceNoMatch_String() + { + Span span = new Span(new string[] { "0", "1", "77", "2", "3", "77", "77", "4", "5", "77", "77", "77", "88", "6", "6", "77", "77", "88", "9" }); + Span value = new Span(new string[] { "77", "77", "88", "99" }); + int index = span.IndexOf(value); + Assert.Equal(-1, index); + } + + [Fact] + public static void IndexOfSequenceNotEvenAHeadMatch_String() + { + Span span = new Span(new string[] { "0", "1", "77", "2", "3", "77", "77", "4", "5", "77", "77", "77", "88", "6", "6", "77", "77", "88", "9" }); + Span value = new Span(new string[] { "100", "77", "88", "99" }); + int index = span.IndexOf(value); + Assert.Equal(-1, index); + } + + [Fact] + public static void IndexOfSequenceMatchAtVeryEnd_String() + { + Span span = new Span(new string[] { "0", "1", "2", "3", "4", "5" }); + Span value = new Span(new string[] { "3", "4", "5" }); + int index = span.IndexOf(value); + Assert.Equal(3, index); + } + + [Fact] + public static void IndexOfSequenceJustPastVeryEnd_String() + { + Span span = new Span(new string[] { "0", "1", "2", "3", "4", "5" }, 0, 5); + Span value = new Span(new string[] { "3", "4", "5" }); + int index = span.IndexOf(value); + Assert.Equal(-1, index); + } + + [Fact] + public static void IndexOfSequenceZeroLengthValue_String() + { + // A zero-length value is always "found" at the start of the span. + Span span = new Span(new string[] { "0", "1", "77", "2", "3", "77", "77", "4", "5", "77", "77", "77", "88", "6", "6", "77", "77", "88", "9" }); + Span value = new Span(Array.Empty()); + int index = span.IndexOf(value); + Assert.Equal(0, index); + } + + [Fact] + public static void IndexOfSequenceZeroLengthSpan_String() + { + Span span = new Span(Array.Empty()); + Span value = new Span(new string[] { "1", "2", "3" }); + int index = span.IndexOf(value); + Assert.Equal(-1, index); + } + + [Fact] + public static void IndexOfSequenceLengthOneValue_String() + { + // A zero-length value is always "found" at the start of the span. + Span span = new Span(new string[] { "0", "1", "2", "3", "4", "5" }); + Span value = new Span(new string[] { "2" }); + int index = span.IndexOf(value); + Assert.Equal(2, index); + } + + [Fact] + public static void IndexOfSequenceLengthOneValueAtVeryEnd_String() + { + // A zero-length value is always "found" at the start of the span. + Span span = new Span(new string[] { "0", "1", "2", "3", "4", "5" }); + Span value = new Span(new string[] { "5" }); + int index = span.IndexOf(value); + Assert.Equal(5, index); + } + + [Fact] + public static void IndexOfSequenceLengthOneValueJustPasttVeryEnd_String() + { + // A zero-length value is always "found" at the start of the span. + Span span = new Span(new string[] { "0", "1", "2", "3", "4", "5" }, 0, 5); + Span value = new Span(new string[] { "5" }); + int index = span.IndexOf(value); + Assert.Equal(-1, index); + } } } diff --git a/src/System.Memory/tests/Span/LastIndexOf.T.cs b/src/System.Memory/tests/Span/LastIndexOf.T.cs index 427ff80a4e7b..1394d9af5706 100644 --- a/src/System.Memory/tests/Span/LastIndexOf.T.cs +++ b/src/System.Memory/tests/Span/LastIndexOf.T.cs @@ -116,5 +116,74 @@ public static void MakeSureNoChecksGoOutOfRangeLastIndexOf() Assert.Equal(-1, idx); } } + + [Fact] + public static void ZeroLengthLastIndexOf_String() + { + Span sp = new Span(Array.Empty()); + int idx = sp.LastIndexOf("a"); + Assert.Equal(-1, idx); + } + + [Fact] + public static void TestMatchLastIndexOf_String() + { + for (int length = 0; length < 32; length++) + { + string[] a = new string[length]; + for (int i = 0; i < length; i++) + { + a[i] = (10 * (i + 1)).ToString(); + } + Span span = new Span(a); + + for (int targetIndex = 0; targetIndex < length; targetIndex++) + { + string target = a[targetIndex]; + int idx = span.LastIndexOf(target); + Assert.Equal(targetIndex, idx); + } + } + } + + [Fact] + public static void TestNoMatchLastIndexOf_String() + { + var rnd = new Random(42); + for (int length = 0; length <= byte.MaxValue; length++) + { + string[] a = new string[length]; + string target = (rnd.Next(0, 256)).ToString(); + for (int i = 0; i < length; i++) + { + string val = (i + 1).ToString(); + a[i] = val == target ? (target + 1) : val; + } + Span span = new Span(a); + + int idx = span.LastIndexOf(target); + Assert.Equal(-1, idx); + } + } + + [Fact] + public static void TestMultipleMatchLastIndexOf_String() + { + for (int length = 2; length < 32; length++) + { + string[] a = new string[length]; + for (int i = 0; i < length; i++) + { + a[i] = (10 * (i + 1)).ToString(); + } + + a[length - 1] = "5555"; + a[length - 2] = "5555"; + + Span span = new Span(a); + int idx = span.LastIndexOf("5555"); + Assert.Equal(length - 1, idx); + } + } } } diff --git a/src/System.Memory/tests/Span/LastIndexOfSequence.T.cs b/src/System.Memory/tests/Span/LastIndexOfSequence.T.cs index 7ca8c26181b6..833d80c200e6 100644 --- a/src/System.Memory/tests/Span/LastIndexOfSequence.T.cs +++ b/src/System.Memory/tests/Span/LastIndexOfSequence.T.cs @@ -129,5 +129,117 @@ public static void LastIndexOfSequenceLengthOneValueJustPasttVeryEnd() int index = span.LastIndexOf(value); Assert.Equal(-1, index); } + + [Fact] + public static void LastIndexOfSequenceMatchAtStart_String() + { + Span span = new Span(new string[] { "5", "1", "77", "2", "3", "77", "77", "4", "5", "77", "77", "77", "88", "6", "6", "77", "77", "88", "9" }); + Span value = new Span(new string[] { "5", "1", "77" }); + int index = span.LastIndexOf(value); + Assert.Equal(0, index); + } + + [Fact] + public static void LastIndexOfSequenceMultipleMatch_String() + { + Span span = new Span(new string[] { "1", "2", "3", "1", "2", "3", "1", "2", "3" }); + Span value = new Span(new string[] { "2", "3" }); + int index = span.LastIndexOf(value); + Assert.Equal(7, index); + } + + [Fact] + public static void LastIndexOfSequenceRestart_String() + { + Span span = new Span(new string[] { "0", "1", "77", "2", "3", "77", "77", "4", "5", "77", "77", "77", "88", "6", "6", "77", "77", "8", "9", "77", "0", "1" }); + Span value = new Span(new string[] { "77", "77", "88" }); + int index = span.LastIndexOf(value); + Assert.Equal(10, index); + } + + [Fact] + public static void LastIndexOfSequenceNoMatch_String() + { + Span span = new Span(new string[] { "0", "1", "77", "2", "3", "77", "77", "4", "5", "77", "77", "77", "88", "6", "6", "77", "77", "88", "9" }); + Span value = new Span(new string[] { "77", "77", "88", "99" }); + int index = span.LastIndexOf(value); + Assert.Equal(-1, index); + } + + [Fact] + public static void LastIndexOfSequenceNotEvenAHeadMatch_String() + { + Span span = new Span(new string[] { "0", "1", "77", "2", "3", "77", "77", "4", "5", "77", "77", "77", "88", "6", "6", "77", "77", "88", "9" }); + Span value = new Span(new string[] { "100", "77", "88", "99" }); + int index = span.LastIndexOf(value); + Assert.Equal(-1, index); + } + + [Fact] + public static void LastIndexOfSequenceMatchAtVeryEnd_String() + { + Span span = new Span(new string[] { "0", "1", "2", "3", "4", "5" }); + Span value = new Span(new string[] { "3", "4", "5" }); + int index = span.LastIndexOf(value); + Assert.Equal(3, index); + } + + [Fact] + public static void LastIndexOfSequenceJustPastVeryEnd_String() + { + Span span = new Span(new string[] { "0", "1", "2", "3", "4", "5" }, 0, 5); + Span value = new Span(new string[] { "3", "4", "5" }); + int index = span.LastIndexOf(value); + Assert.Equal(-1, index); + } + + [Fact] + public static void LastIndexOfSequenceZeroLengthValue_String() + { + // A zero-length value is always "found" at the start of the span. + Span span = new Span(new string[] { "0", "1", "77", "2", "3", "77", "77", "4", "5", "77", "77", "77", "88", "6", "6", "77", "77", "88", "9" }); + Span value = new Span(Array.Empty()); + int index = span.LastIndexOf(value); + Assert.Equal(0, index); + } + + [Fact] + public static void LastIndexOfSequenceZeroLengthSpan_String() + { + Span span = new Span(Array.Empty()); + Span value = new Span(new string[] { "1", "2", "3" }); + int index = span.LastIndexOf(value); + Assert.Equal(-1, index); + } + + [Fact] + public static void LastIndexOfSequenceLengthOneValue_String() + { + // A zero-length value is always "found" at the start of the span. + Span span = new Span(new string[] { "0", "1", "2", "3", "4", "5" }); + Span value = new Span(new string[] { "2" }); + int index = span.LastIndexOf(value); + Assert.Equal(2, index); + } + + [Fact] + public static void LastIndexOfSequenceLengthOneValueAtVeryEnd_String() + { + // A zero-length value is always "found" at the start of the span. + Span span = new Span(new string[] { "0", "1", "2", "3", "4", "5" }); + Span value = new Span(new string[] { "5" }); + int index = span.LastIndexOf(value); + Assert.Equal(5, index); + } + + [Fact] + public static void LastIndexOfSequenceLengthOneValueJustPasttVeryEnd_String() + { + // A zero-length value is always "found" at the start of the span. + Span span = new Span(new string[] { "0", "1", "2", "3", "4", "5" }, 0, 5); + Span value = new Span(new string[] { "5" }); + int index = span.LastIndexOf(value); + Assert.Equal(-1, index); + } } } From 5531cdf35c4ff009f83c5eff70f4e34ecbfde05e Mon Sep 17 00:00:00 2001 From: ahsonkhan Date: Wed, 6 Dec 2017 16:49:45 -0800 Subject: [PATCH 6/9] Use abbreviated version of 'default' literal --- src/System.Memory/ref/System.Memory.cs | 2 +- .../System/Buffers/Text/Utf8Parser/Utf8Parser.Date.cs | 4 ++-- .../Buffers/Text/Utf8Parser/Utf8Parser.Decimal.cs | 4 ++-- .../System/Buffers/Text/Utf8Parser/Utf8Parser.Float.cs | 4 ++-- .../System/Buffers/Text/Utf8Parser/Utf8Parser.Guid.cs | 2 +- .../Text/Utf8Parser/Utf8Parser.Integer.Signed.cs | 8 ++++---- .../Text/Utf8Parser/Utf8Parser.Integer.Unsigned.cs | 8 ++++---- .../Buffers/Text/Utf8Parser/Utf8Parser.TimeSpan.cs | 2 +- .../Formatter/TestData.Formatter.cs | 2 +- .../Parser/TestData.Parser.Date.cs | 4 ++-- .../Parser/TestData.Parser.Integer.cs | 10 +++++----- .../tests/ParsersAndFormatters/SupportedFormats.cs | 2 +- src/System.Memory/tests/ReadOnlySpan/IndexOf.byte.cs | 8 ++++---- .../tests/ReadOnlySpan/LastIndexOf.byte.cs | 2 +- src/System.Memory/tests/Span/Clear.cs | 8 ++++---- src/System.Memory/tests/Span/IndexOf.byte.cs | 8 ++++---- src/System.Memory/tests/Span/LastIndexOf.byte.cs | 2 +- 17 files changed, 40 insertions(+), 40 deletions(-) diff --git a/src/System.Memory/ref/System.Memory.cs b/src/System.Memory/ref/System.Memory.cs index 2d6193bb9582..a615d728c8be 100644 --- a/src/System.Memory/ref/System.Memory.cs +++ b/src/System.Memory/ref/System.Memory.cs @@ -206,7 +206,7 @@ namespace System.Buffers public unsafe struct MemoryHandle : IDisposable { [CLSCompliant(false)] - public MemoryHandle(IRetainable owner, void* pointer = null, System.Runtime.InteropServices.GCHandle handle = default(System.Runtime.InteropServices.GCHandle)) { throw null; } + public MemoryHandle(IRetainable owner, void* pointer = null, System.Runtime.InteropServices.GCHandle handle = default) { throw null; } [CLSCompliant(false)] public void* Pointer { get { throw null; } } public bool HasPointer { get { throw null; } } diff --git a/src/System.Memory/src/System/Buffers/Text/Utf8Parser/Utf8Parser.Date.cs b/src/System.Memory/src/System/Buffers/Text/Utf8Parser/Utf8Parser.Date.cs index 1ebedd865b8c..d69ff7ce136f 100644 --- a/src/System.Memory/src/System/Buffers/Text/Utf8Parser/Utf8Parser.Date.cs +++ b/src/System.Memory/src/System/Buffers/Text/Utf8Parser/Utf8Parser.Date.cs @@ -89,7 +89,7 @@ public static bool TryParse(ReadOnlySpan text, out DateTime value, out int return true; } - case default(char): + case (default): case 'G': return TryParseDateTimeG(text, out value, out _, out bytesConsumed); @@ -132,7 +132,7 @@ public static bool TryParse(ReadOnlySpan text, out DateTimeOffset value, o case 'O': return TryParseDateTimeOffsetO(text, out value, out bytesConsumed, out _); - case default(char): + case (default): return TryParseDateTimeOffsetDefault(text, out value, out bytesConsumed); case 'G': diff --git a/src/System.Memory/src/System/Buffers/Text/Utf8Parser/Utf8Parser.Decimal.cs b/src/System.Memory/src/System/Buffers/Text/Utf8Parser/Utf8Parser.Decimal.cs index 35a8f0f9d34f..ee9612d18f20 100644 --- a/src/System.Memory/src/System/Buffers/Text/Utf8Parser/Utf8Parser.Decimal.cs +++ b/src/System.Memory/src/System/Buffers/Text/Utf8Parser/Utf8Parser.Decimal.cs @@ -33,7 +33,7 @@ public static bool TryParse(ReadOnlySpan text, out decimal value, out int ParseNumberOptions options; switch (standardFormat) { - case default(char): + case (default): case 'G': case 'g': case 'E': @@ -43,7 +43,7 @@ public static bool TryParse(ReadOnlySpan text, out decimal value, out int case 'F': case 'f': - options = default(ParseNumberOptions); + options = default; break; default: diff --git a/src/System.Memory/src/System/Buffers/Text/Utf8Parser/Utf8Parser.Float.cs b/src/System.Memory/src/System/Buffers/Text/Utf8Parser/Utf8Parser.Float.cs index c2d9dbbe44e8..eb1269d3b92e 100644 --- a/src/System.Memory/src/System/Buffers/Text/Utf8Parser/Utf8Parser.Float.cs +++ b/src/System.Memory/src/System/Buffers/Text/Utf8Parser/Utf8Parser.Float.cs @@ -81,7 +81,7 @@ private static bool TryParseNormalAsFloatingPoint(ReadOnlySpan text, out d ParseNumberOptions options; switch (standardFormat) { - case default(char): + case (default): case 'G': case 'g': case 'E': @@ -91,7 +91,7 @@ private static bool TryParseNormalAsFloatingPoint(ReadOnlySpan text, out d case 'F': case 'f': - options = default(ParseNumberOptions); + options = default; break; default: diff --git a/src/System.Memory/src/System/Buffers/Text/Utf8Parser/Utf8Parser.Guid.cs b/src/System.Memory/src/System/Buffers/Text/Utf8Parser/Utf8Parser.Guid.cs index d1a687bb85f2..82ea48d9e56b 100644 --- a/src/System.Memory/src/System/Buffers/Text/Utf8Parser/Utf8Parser.Guid.cs +++ b/src/System.Memory/src/System/Buffers/Text/Utf8Parser/Utf8Parser.Guid.cs @@ -31,7 +31,7 @@ public static bool TryParse(ReadOnlySpan text, out Guid value, out int byt { switch (standardFormat) { - case default(char): + case (default): case 'D': return TryParseGuidCore(text, false, ' ', ' ', out value, out bytesConsumed); case 'B': diff --git a/src/System.Memory/src/System/Buffers/Text/Utf8Parser/Utf8Parser.Integer.Signed.cs b/src/System.Memory/src/System/Buffers/Text/Utf8Parser/Utf8Parser.Integer.Signed.cs index b8ec994f4aa4..914ff9e5afba 100644 --- a/src/System.Memory/src/System/Buffers/Text/Utf8Parser/Utf8Parser.Integer.Signed.cs +++ b/src/System.Memory/src/System/Buffers/Text/Utf8Parser/Utf8Parser.Integer.Signed.cs @@ -37,7 +37,7 @@ public static bool TryParse(ReadOnlySpan text, out sbyte value, out int by { switch (standardFormat) { - case default(char): + case (default): case 'g': case 'G': case 'd': @@ -83,7 +83,7 @@ public static bool TryParse(ReadOnlySpan text, out short value, out int by { switch (standardFormat) { - case default(char): + case (default): case 'g': case 'G': case 'd': @@ -129,7 +129,7 @@ public static bool TryParse(ReadOnlySpan text, out int value, out int byte { switch (standardFormat) { - case default(char): + case (default): case 'g': case 'G': case 'd': @@ -175,7 +175,7 @@ public static bool TryParse(ReadOnlySpan text, out long value, out int byt { switch (standardFormat) { - case default(char): + case (default): case 'g': case 'G': case 'd': diff --git a/src/System.Memory/src/System/Buffers/Text/Utf8Parser/Utf8Parser.Integer.Unsigned.cs b/src/System.Memory/src/System/Buffers/Text/Utf8Parser/Utf8Parser.Integer.Unsigned.cs index 6158ee1288b3..78dfdebcd955 100644 --- a/src/System.Memory/src/System/Buffers/Text/Utf8Parser/Utf8Parser.Integer.Unsigned.cs +++ b/src/System.Memory/src/System/Buffers/Text/Utf8Parser/Utf8Parser.Integer.Unsigned.cs @@ -31,7 +31,7 @@ public static bool TryParse(ReadOnlySpan text, out byte value, out int byt { switch (standardFormat) { - case default(char): + case (default): case 'g': case 'G': case 'd': @@ -77,7 +77,7 @@ public static bool TryParse(ReadOnlySpan text, out ushort value, out int b { switch (standardFormat) { - case default(char): + case (default): case 'g': case 'G': case 'd': @@ -123,7 +123,7 @@ public static bool TryParse(ReadOnlySpan text, out uint value, out int byt { switch (standardFormat) { - case default(char): + case (default): case 'g': case 'G': case 'd': @@ -169,7 +169,7 @@ public static bool TryParse(ReadOnlySpan text, out ulong value, out int by { switch (standardFormat) { - case default(char): + case (default): case 'g': case 'G': case 'd': diff --git a/src/System.Memory/src/System/Buffers/Text/Utf8Parser/Utf8Parser.TimeSpan.cs b/src/System.Memory/src/System/Buffers/Text/Utf8Parser/Utf8Parser.TimeSpan.cs index e8a47b87cc0b..e971718fbb85 100644 --- a/src/System.Memory/src/System/Buffers/Text/Utf8Parser/Utf8Parser.TimeSpan.cs +++ b/src/System.Memory/src/System/Buffers/Text/Utf8Parser/Utf8Parser.TimeSpan.cs @@ -32,7 +32,7 @@ public static bool TryParse(ReadOnlySpan text, out TimeSpan value, out int { switch (standardFormat) { - case default(char): + case (default): case 'c': case 't': case 'T': diff --git a/src/System.Memory/tests/ParsersAndFormatters/Formatter/TestData.Formatter.cs b/src/System.Memory/tests/ParsersAndFormatters/Formatter/TestData.Formatter.cs index 211acdce86fa..62887900a0d1 100644 --- a/src/System.Memory/tests/ParsersAndFormatters/Formatter/TestData.Formatter.cs +++ b/src/System.Memory/tests/ParsersAndFormatters/Formatter/TestData.Formatter.cs @@ -85,7 +85,7 @@ private static IEnumerable> CreateFormatterTestData(IEnu if (format.IsDefault) { string expectedOutput = ComputeExpectedOutput(value, format.Symbol, StandardFormat.NoPrecision); - yield return new FormatterTestData(value, new SupportedFormat(default(char), format.SupportsPrecision), default(byte), expectedOutput); + yield return new FormatterTestData(value, new SupportedFormat(default, format.SupportsPrecision), default, expectedOutput); } if (!format.NoRepresentation) diff --git a/src/System.Memory/tests/ParsersAndFormatters/Parser/TestData.Parser.Date.cs b/src/System.Memory/tests/ParsersAndFormatters/Parser/TestData.Parser.Date.cs index a3d5612a2003..c4dad80bd1af 100644 --- a/src/System.Memory/tests/ParsersAndFormatters/Parser/TestData.Parser.Date.cs +++ b/src/System.Memory/tests/ParsersAndFormatters/Parser/TestData.Parser.Date.cs @@ -62,7 +62,7 @@ public static IEnumerable> DateTimeOffsetParserTe // Wrong day of week. yield return new ParserTestData("Thu, 13 Jan 2017 03:45:32 GMT", default, 'R', expectedSuccess: false); - foreach (ParserTestData bad in GenerateCorruptedDateTimeText("05/08/2017 10:30:45 +00:00", default(char))) + foreach (ParserTestData bad in GenerateCorruptedDateTimeText("05/08/2017 10:30:45 +00:00", default)) { yield return bad; } @@ -136,7 +136,7 @@ public static IEnumerable> DateTimeOffsetParserTe string text; if ((text = pseudoDateTime.DefaultString) != null) { - yield return new ParserTestData(text, expectedDto, default(char), pseudoDateTime.ExpectSuccess); + yield return new ParserTestData(text, expectedDto, default, pseudoDateTime.ExpectSuccess); } if ((text = pseudoDateTime.GFormatString) != null) diff --git a/src/System.Memory/tests/ParsersAndFormatters/Parser/TestData.Parser.Integer.cs b/src/System.Memory/tests/ParsersAndFormatters/Parser/TestData.Parser.Integer.cs index 2ec93e94cca8..ad6840dddd68 100644 --- a/src/System.Memory/tests/ParsersAndFormatters/Parser/TestData.Parser.Integer.cs +++ b/src/System.Memory/tests/ParsersAndFormatters/Parser/TestData.Parser.Integer.cs @@ -203,7 +203,7 @@ private static IEnumerable> GeneralIntegerParserTestData() { foreach (string integerNegativeInput in GeneralIntegerNegativeInputs) { - yield return new ParserTestData(integerNegativeInput, default(T), format.Symbol, expectedSuccess: false); + yield return new ParserTestData(integerNegativeInput, default, format.Symbol, expectedSuccess: false); } // The hex format always parses as an unsigned number. That violates the assumptions made by this next set of test data. @@ -226,13 +226,13 @@ private static IEnumerable> GeneralIntegerParserTestData() { BigInteger bigValue = maxValue + offset; string text = bigValue.ToString(format.Symbol.ToString()); - yield return new ParserTestData(text, default(T), format.Symbol, expectedSuccess: false); + yield return new ParserTestData(text, default, format.Symbol, expectedSuccess: false); } { BigInteger bigValue = maxValue * 10; string text = bigValue.ToString(format.Symbol.ToString()); - yield return new ParserTestData(text, default(T), format.Symbol, expectedSuccess: false); + yield return new ParserTestData(text, default, format.Symbol, expectedSuccess: false); } if (isSigned) // No such thing as an underflow for unsigned integer parsing... @@ -252,13 +252,13 @@ private static IEnumerable> GeneralIntegerParserTestData() { BigInteger bigValue = minValue + offset; string text = bigValue.ToString(format.Symbol.ToString()); - yield return new ParserTestData(text, default(T), format.Symbol, expectedSuccess: false); + yield return new ParserTestData(text, default, format.Symbol, expectedSuccess: false); } { BigInteger bigValue = minValue * 10; string text = bigValue.ToString(format.Symbol.ToString()); - yield return new ParserTestData(text, default(T), format.Symbol, expectedSuccess: false); + yield return new ParserTestData(text, default, format.Symbol, expectedSuccess: false); } } } diff --git a/src/System.Memory/tests/ParsersAndFormatters/SupportedFormats.cs b/src/System.Memory/tests/ParsersAndFormatters/SupportedFormats.cs index c1afc443588e..929e9e286725 100644 --- a/src/System.Memory/tests/ParsersAndFormatters/SupportedFormats.cs +++ b/src/System.Memory/tests/ParsersAndFormatters/SupportedFormats.cs @@ -116,7 +116,7 @@ public static IEnumerable DateTimeOffsetFormats get { // The "default" format for DateTimeOffset is weird - it's like "G" but also suffixes an offset so it doesn't exactly match any of the explicit offsets. - yield return new SupportedFormat(default(char), supportsPrecision: false) { IsDefault = true, NoRepresentation = true }; + yield return new SupportedFormat(default, supportsPrecision: false) { IsDefault = true, NoRepresentation = true }; yield return new SupportedFormat('G', supportsPrecision: false); yield return new SupportedFormat('R', supportsPrecision: false); yield return new SupportedFormat('l', supportsPrecision: false); diff --git a/src/System.Memory/tests/ReadOnlySpan/IndexOf.byte.cs b/src/System.Memory/tests/ReadOnlySpan/IndexOf.byte.cs index f37938f94140..4f902c7fc8f3 100644 --- a/src/System.Memory/tests/ReadOnlySpan/IndexOf.byte.cs +++ b/src/System.Memory/tests/ReadOnlySpan/IndexOf.byte.cs @@ -28,7 +28,7 @@ public static void DefaultFilledIndexOf_Byte() for (int i = 0; i < length; i++) { - byte target0 = default(byte); + byte target0 = default; int idx = span.IndexOf(target0); Assert.Equal(0, idx); } @@ -215,7 +215,7 @@ public static void DefaultFilledIndexOfTwo_Byte() byte[] a = new byte[length]; ReadOnlySpan span = new ReadOnlySpan(a); - byte[] targets = { default(byte), 99 }; + byte[] targets = { default, 99 }; for (int i = 0; i < length; i++) { @@ -346,7 +346,7 @@ public static void DefaultFilledIndexOfThree_Byte() byte[] a = new byte[length]; ReadOnlySpan span = new ReadOnlySpan(a); - byte[] targets = { default(byte), 99, 98 }; + byte[] targets = { default, 99, 98 }; for (int i = 0; i < length; i++) { @@ -486,7 +486,7 @@ public static void DefaultFilledIndexOfMany_Byte() byte[] a = new byte[length]; ReadOnlySpan span = new ReadOnlySpan(a); - var values = new ReadOnlySpan(new byte[] { default(byte), 99, 98, 0 }); + var values = new ReadOnlySpan(new byte[] { default, 99, 98, 0 }); for (int i = 0; i < length; i++) { diff --git a/src/System.Memory/tests/ReadOnlySpan/LastIndexOf.byte.cs b/src/System.Memory/tests/ReadOnlySpan/LastIndexOf.byte.cs index 5ede3d4423f6..0134bcad2d29 100644 --- a/src/System.Memory/tests/ReadOnlySpan/LastIndexOf.byte.cs +++ b/src/System.Memory/tests/ReadOnlySpan/LastIndexOf.byte.cs @@ -28,7 +28,7 @@ public static void DefaultFilledLastIndexOf_Byte() for (int i = 0; i < length; i++) { - byte target0 = default(byte); + byte target0 = default; int idx = span.LastIndexOf(target0); Assert.Equal(length - 1, idx); } diff --git a/src/System.Memory/tests/Span/Clear.cs b/src/System.Memory/tests/Span/Clear.cs index ecd0c4a34f86..0b8da2c95710 100644 --- a/src/System.Memory/tests/Span/Clear.cs +++ b/src/System.Memory/tests/Span/Clear.cs @@ -203,7 +203,7 @@ public static void ClearReferenceTypeLonger() public static void ClearEnumType() { TestEnum[] actual = {TestEnum.e0, TestEnum.e1, TestEnum.e2}; - TestEnum[] expected = {default(TestEnum), default(TestEnum), default(TestEnum) }; + TestEnum[] expected = {default, default, default }; var span = new Span(actual); span.Clear(); @@ -218,9 +218,9 @@ public static void ClearValueTypeWithReferences() new TestValueTypeWithReference() { I = 2, S = "b" }, new TestValueTypeWithReference() { I = 3, S = "c" } }; TestValueTypeWithReference[] expected = { - default(TestValueTypeWithReference), - default(TestValueTypeWithReference), - default(TestValueTypeWithReference) }; + default, + default, + default }; var span = new Span(actual); span.Clear(); diff --git a/src/System.Memory/tests/Span/IndexOf.byte.cs b/src/System.Memory/tests/Span/IndexOf.byte.cs index 71981631b5db..e4a535570aac 100644 --- a/src/System.Memory/tests/Span/IndexOf.byte.cs +++ b/src/System.Memory/tests/Span/IndexOf.byte.cs @@ -28,7 +28,7 @@ public static void DefaultFilledIndexOf_Byte() for (int i = 0; i < length; i++) { - byte target0 = default(byte); + byte target0 = default; int idx = span.IndexOf(target0); Assert.Equal(0, idx); } @@ -215,7 +215,7 @@ public static void DefaultFilledIndexOfTwo_Byte() byte[] a = new byte[length]; Span span = new Span(a); - byte[] targets = { default(byte), 99 }; + byte[] targets = { default, 99 }; for (int i = 0; i < length; i++) { @@ -346,7 +346,7 @@ public static void DefaultFilledIndexOfThree_Byte() byte[] a = new byte[length]; Span span = new Span(a); - byte[] targets = { default(byte), 99, 98 }; + byte[] targets = { default, 99, 98 }; for (int i = 0; i < length; i++) { @@ -486,7 +486,7 @@ public static void DefaultFilledIndexOfMany_Byte() byte[] a = new byte[length]; Span span = new Span(a); - var values = new ReadOnlySpan(new byte[] { default(byte), 99, 98, 0 }); + var values = new ReadOnlySpan(new byte[] { default, 99, 98, 0 }); for (int i = 0; i < length; i++) { diff --git a/src/System.Memory/tests/Span/LastIndexOf.byte.cs b/src/System.Memory/tests/Span/LastIndexOf.byte.cs index 1886a5f25d7a..696cd8f70e07 100644 --- a/src/System.Memory/tests/Span/LastIndexOf.byte.cs +++ b/src/System.Memory/tests/Span/LastIndexOf.byte.cs @@ -28,7 +28,7 @@ public static void DefaultFilledLastIndexOf_Byte() for (int i = 0; i < length; i++) { - byte target0 = default(byte); + byte target0 = default; int idx = span.LastIndexOf(target0); Assert.Equal(length - 1, idx); } From 290856a83ed2040ee78b7868b8f1c30f604c1aa9 Mon Sep 17 00:00:00 2001 From: ahsonkhan Date: Wed, 6 Dec 2017 16:51:43 -0800 Subject: [PATCH 7/9] Remove unnecessary type specifiers in generic function calls. --- .../tests/ReadOnlySpan/LastIndexOf.byte.cs | 6 ++--- .../ReadOnlySpan/LastIndexOfSequence.byte.cs | 26 +++++++++---------- .../tests/Span/LastIndexOf.byte.cs | 6 ++--- .../tests/Span/LastIndexOfSequence.byte.cs | 26 +++++++++---------- 4 files changed, 32 insertions(+), 32 deletions(-) diff --git a/src/System.Memory/tests/ReadOnlySpan/LastIndexOf.byte.cs b/src/System.Memory/tests/ReadOnlySpan/LastIndexOf.byte.cs index 0134bcad2d29..1a095e154886 100644 --- a/src/System.Memory/tests/ReadOnlySpan/LastIndexOf.byte.cs +++ b/src/System.Memory/tests/ReadOnlySpan/LastIndexOf.byte.cs @@ -29,7 +29,7 @@ public static void DefaultFilledLastIndexOf_Byte() for (int i = 0; i < length; i++) { byte target0 = default; - int idx = span.LastIndexOf(target0); + int idx = span.LastIndexOf(target0); Assert.Equal(length - 1, idx); } } @@ -50,7 +50,7 @@ public static void TestMatchLastIndexOf_Byte() for (int targetIndex = 0; targetIndex < length; targetIndex++) { byte target = a[targetIndex]; - int idx = span.LastIndexOf(target); + int idx = span.LastIndexOf(target); Assert.Equal(targetIndex, idx); } } @@ -71,7 +71,7 @@ public static void TestNoMatchLastIndexOf_Byte() } ReadOnlySpan span = new ReadOnlySpan(a); - int idx = span.LastIndexOf(target); + int idx = span.LastIndexOf(target); Assert.Equal(-1, idx); } } diff --git a/src/System.Memory/tests/ReadOnlySpan/LastIndexOfSequence.byte.cs b/src/System.Memory/tests/ReadOnlySpan/LastIndexOfSequence.byte.cs index 8b7adec168be..293920a2f79e 100644 --- a/src/System.Memory/tests/ReadOnlySpan/LastIndexOfSequence.byte.cs +++ b/src/System.Memory/tests/ReadOnlySpan/LastIndexOfSequence.byte.cs @@ -13,7 +13,7 @@ public static void LastIndexOfSequenceMatchAtStart_Byte() { ReadOnlySpan span = new ReadOnlySpan(new byte[] { 5, 1, 77, 2, 3, 77, 77, 4, 5, 77, 77, 77, 88, 6, 6, 77, 77, 88, 9 }); ReadOnlySpan value = new ReadOnlySpan(new byte[] { 5, 1, 77 }); - int index = span.LastIndexOf(value); + int index = span.LastIndexOf(value); Assert.Equal(0, index); } @@ -22,7 +22,7 @@ public static void LastIndexOfSequenceMultipleMatch_Byte() { ReadOnlySpan span = new ReadOnlySpan(new byte[] { 1, 2, 3, 1, 2, 3, 1, 2, 3, 1 }); ReadOnlySpan value = new ReadOnlySpan(new byte[] { 2, 3 }); - int index = span.LastIndexOf(value); + int index = span.LastIndexOf(value); Assert.Equal(7, index); } @@ -31,7 +31,7 @@ public static void LastIndexOfSequenceRestart_Byte() { ReadOnlySpan span = new ReadOnlySpan(new byte[] { 0, 1, 77, 2, 3, 77, 77, 4, 5, 77, 77, 77, 88, 6, 6, 77, 77, 8, 9, 77, 0, 1 }); ReadOnlySpan value = new ReadOnlySpan(new byte[] { 77, 77, 88 }); - int index = span.LastIndexOf(value); + int index = span.LastIndexOf(value); Assert.Equal(10, index); } @@ -40,7 +40,7 @@ public static void LastIndexOfSequenceNoMatch_Byte() { ReadOnlySpan span = new ReadOnlySpan(new byte[] { 0, 1, 77, 2, 3, 77, 77, 4, 5, 77, 77, 77, 88, 6, 6, 77, 77, 88, 9 }); ReadOnlySpan value = new ReadOnlySpan(new byte[] { 77, 77, 88, 99 }); - int index = span.LastIndexOf(value); + int index = span.LastIndexOf(value); Assert.Equal(-1, index); } @@ -49,7 +49,7 @@ public static void LastIndexOfSequenceNotEvenAHeadMatch_Byte() { ReadOnlySpan span = new ReadOnlySpan(new byte[] { 0, 1, 77, 2, 3, 77, 77, 4, 5, 77, 77, 77, 88, 6, 6, 77, 77, 88, 9 }); ReadOnlySpan value = new ReadOnlySpan(new byte[] { 100, 77, 88, 99 }); - int index = span.LastIndexOf(value); + int index = span.LastIndexOf(value); Assert.Equal(-1, index); } @@ -58,7 +58,7 @@ public static void LastIndexOfSequenceMatchAtVeryEnd_Byte() { ReadOnlySpan span = new ReadOnlySpan(new byte[] { 0, 1, 2, 3, 4, 5 }); ReadOnlySpan value = new ReadOnlySpan(new byte[] { 3, 4, 5 }); - int index = span.LastIndexOf(value); + int index = span.LastIndexOf(value); Assert.Equal(3, index); } @@ -67,7 +67,7 @@ public static void LastIndexOfSequenceJustPastVeryEnd_Byte() { ReadOnlySpan span = new ReadOnlySpan(new byte[] { 0, 1, 2, 3, 4, 5 }, 0, 5); ReadOnlySpan value = new ReadOnlySpan(new byte[] { 3, 4, 5 }); - int index = span.LastIndexOf(value); + int index = span.LastIndexOf(value); Assert.Equal(-1, index); } @@ -77,7 +77,7 @@ public static void LastIndexOfSequenceZeroLengthValue_Byte() // A zero-length value is always "found" at the start of the span. ReadOnlySpan span = new ReadOnlySpan(new byte[] { 0, 1, 77, 2, 3, 77, 77, 4, 5, 77, 77, 77, 88, 6, 6, 77, 77, 88, 9 }); ReadOnlySpan value = new ReadOnlySpan(Array.Empty()); - int index = span.LastIndexOf(value); + int index = span.LastIndexOf(value); Assert.Equal(0, index); } @@ -86,7 +86,7 @@ public static void LastIndexOfSequenceZeroLengthSpan_Byte() { ReadOnlySpan span = new ReadOnlySpan(Array.Empty()); ReadOnlySpan value = new ReadOnlySpan(new byte[] { 1, 2, 3 }); - int index = span.LastIndexOf(value); + int index = span.LastIndexOf(value); Assert.Equal(-1, index); } @@ -96,7 +96,7 @@ public static void LastIndexOfSequenceLengthOneValue_Byte() // A zero-length value is always "found" at the start of the span. ReadOnlySpan span = new ReadOnlySpan(new byte[] { 0, 1, 2, 3, 4, 5 }); ReadOnlySpan value = new ReadOnlySpan(new byte[] { 2 }); - int index = span.LastIndexOf(value); + int index = span.LastIndexOf(value); Assert.Equal(2, index); } @@ -106,7 +106,7 @@ public static void LastIndexOfSequenceLengthOneValueAtVeryEnd_Byte() // A zero-length value is always "found" at the start of the span. ReadOnlySpan span = new ReadOnlySpan(new byte[] { 0, 1, 2, 3, 4, 5 }); ReadOnlySpan value = new ReadOnlySpan(new byte[] { 5 }); - int index = span.LastIndexOf(value); + int index = span.LastIndexOf(value); Assert.Equal(5, index); } @@ -116,7 +116,7 @@ public static void LastIndexOfSequenceLengthOneValueMultipleTimes_Byte() // A zero-length value is always "found" at the start of the span. ReadOnlySpan span = new ReadOnlySpan(new byte[] { 0, 1, 5, 3, 4, 5 }); ReadOnlySpan value = new ReadOnlySpan(new byte[] { 5 }); - int index = span.LastIndexOf(value); + int index = span.LastIndexOf(value); Assert.Equal(5, index); } @@ -126,7 +126,7 @@ public static void LastIndexOfSequenceLengthOneValueJustPasttVeryEnd_Byte() // A zero-length value is always "found" at the start of the span. ReadOnlySpan span = new ReadOnlySpan(new byte[] { 0, 1, 2, 3, 4, 5 }, 0, 5); ReadOnlySpan value = new ReadOnlySpan(new byte[] { 5 }); - int index = span.LastIndexOf(value); + int index = span.LastIndexOf(value); Assert.Equal(-1, index); } } diff --git a/src/System.Memory/tests/Span/LastIndexOf.byte.cs b/src/System.Memory/tests/Span/LastIndexOf.byte.cs index 696cd8f70e07..62a369d41167 100644 --- a/src/System.Memory/tests/Span/LastIndexOf.byte.cs +++ b/src/System.Memory/tests/Span/LastIndexOf.byte.cs @@ -29,7 +29,7 @@ public static void DefaultFilledLastIndexOf_Byte() for (int i = 0; i < length; i++) { byte target0 = default; - int idx = span.LastIndexOf(target0); + int idx = span.LastIndexOf(target0); Assert.Equal(length - 1, idx); } } @@ -50,7 +50,7 @@ public static void TestMatchLastIndexOf_Byte() for (int targetIndex = 0; targetIndex < length; targetIndex++) { byte target = a[targetIndex]; - int idx = span.LastIndexOf(target); + int idx = span.LastIndexOf(target); Assert.Equal(targetIndex, idx); } } @@ -71,7 +71,7 @@ public static void TestNoMatchLastIndexOf_Byte() } Span span = new Span(a); - int idx = span.LastIndexOf(target); + int idx = span.LastIndexOf(target); Assert.Equal(-1, idx); } } diff --git a/src/System.Memory/tests/Span/LastIndexOfSequence.byte.cs b/src/System.Memory/tests/Span/LastIndexOfSequence.byte.cs index 6aef9db54204..96b229725e58 100644 --- a/src/System.Memory/tests/Span/LastIndexOfSequence.byte.cs +++ b/src/System.Memory/tests/Span/LastIndexOfSequence.byte.cs @@ -13,7 +13,7 @@ public static void LastIndexOfSequenceMatchAtStart_Byte() { Span span = new Span(new byte[] { 5, 1, 77, 2, 3, 77, 77, 4, 5, 77, 77, 77, 88, 6, 6, 77, 77, 88, 9 }); Span value = new Span(new byte[] { 5, 1, 77 }); - int index = span.LastIndexOf(value); + int index = span.LastIndexOf(value); Assert.Equal(0, index); } @@ -22,7 +22,7 @@ public static void LastIndexOfSequenceMultipleMatch_Byte() { Span span = new Span(new byte[] { 1, 2, 3, 1, 2, 3, 1, 2, 3, 1 }); Span value = new Span(new byte[] { 2, 3 }); - int index = span.LastIndexOf(value); + int index = span.LastIndexOf(value); Assert.Equal(7, index); } @@ -31,7 +31,7 @@ public static void LastIndexOfSequenceRestart_Byte() { Span span = new Span(new byte[] { 0, 1, 77, 2, 3, 77, 77, 4, 5, 77, 77, 77, 88, 6, 6, 77, 77, 8, 9, 77, 0, 1 }); Span value = new Span(new byte[] { 77, 77, 88 }); - int index = span.LastIndexOf(value); + int index = span.LastIndexOf(value); Assert.Equal(10, index); } @@ -40,7 +40,7 @@ public static void LastIndexOfSequenceNoMatch_Byte() { Span span = new Span(new byte[] { 0, 1, 77, 2, 3, 77, 77, 4, 5, 77, 77, 77, 88, 6, 6, 77, 77, 88, 9 }); Span value = new Span(new byte[] { 77, 77, 88, 99 }); - int index = span.LastIndexOf(value); + int index = span.LastIndexOf(value); Assert.Equal(-1, index); } @@ -49,7 +49,7 @@ public static void LastIndexOfSequenceNotEvenAHeadMatch_Byte() { Span span = new Span(new byte[] { 0, 1, 77, 2, 3, 77, 77, 4, 5, 77, 77, 77, 88, 6, 6, 77, 77, 88, 9 }); Span value = new Span(new byte[] { 100, 77, 88, 99 }); - int index = span.LastIndexOf(value); + int index = span.LastIndexOf(value); Assert.Equal(-1, index); } @@ -58,7 +58,7 @@ public static void LastIndexOfSequenceMatchAtVeryEnd_Byte() { Span span = new Span(new byte[] { 0, 1, 2, 3, 4, 5 }); Span value = new Span(new byte[] { 3, 4, 5 }); - int index = span.LastIndexOf(value); + int index = span.LastIndexOf(value); Assert.Equal(3, index); } @@ -67,7 +67,7 @@ public static void LastIndexOfSequenceJustPastVeryEnd_Byte() { Span span = new Span(new byte[] { 0, 1, 2, 3, 4, 5 }, 0, 5); Span value = new Span(new byte[] { 3, 4, 5 }); - int index = span.LastIndexOf(value); + int index = span.LastIndexOf(value); Assert.Equal(-1, index); } @@ -77,7 +77,7 @@ public static void LastIndexOfSequenceZeroLengthValue_Byte() // A zero-length value is always "found" at the start of the span. Span span = new Span(new byte[] { 0, 1, 77, 2, 3, 77, 77, 4, 5, 77, 77, 77, 88, 6, 6, 77, 77, 88, 9 }); Span value = new Span(Array.Empty()); - int index = span.LastIndexOf(value); + int index = span.LastIndexOf(value); Assert.Equal(0, index); } @@ -86,7 +86,7 @@ public static void LastIndexOfSequenceZeroLengthSpan_Byte() { Span span = new Span(Array.Empty()); Span value = new Span(new byte[] { 1, 2, 3 }); - int index = span.LastIndexOf(value); + int index = span.LastIndexOf(value); Assert.Equal(-1, index); } @@ -96,7 +96,7 @@ public static void LastIndexOfSequenceLengthOneValue_Byte() // A zero-length value is always "found" at the start of the span. Span span = new Span(new byte[] { 0, 1, 2, 3, 4, 5 }); Span value = new Span(new byte[] { 2 }); - int index = span.LastIndexOf(value); + int index = span.LastIndexOf(value); Assert.Equal(2, index); } @@ -106,7 +106,7 @@ public static void LastIndexOfSequenceLengthOneValueAtVeryEnd_Byte() // A zero-length value is always "found" at the start of the span. Span span = new Span(new byte[] { 0, 1, 2, 3, 4, 5 }); Span value = new Span(new byte[] { 5 }); - int index = span.LastIndexOf(value); + int index = span.LastIndexOf(value); Assert.Equal(5, index); } @@ -116,7 +116,7 @@ public static void LastIndexOfSequenceLengthOneValueMultipleTimes_Byte() // A zero-length value is always "found" at the start of the span. Span span = new Span(new byte[] { 0, 1, 5, 3, 4, 5 }); Span value = new Span(new byte[] { 5 }); - int index = span.LastIndexOf(value); + int index = span.LastIndexOf(value); Assert.Equal(5, index); } @@ -126,7 +126,7 @@ public static void LastIndexOfSequenceLengthOneValueJustPasttVeryEnd_Byte() // A zero-length value is always "found" at the start of the span. Span span = new Span(new byte[] { 0, 1, 2, 3, 4, 5 }, 0, 5); Span value = new Span(new byte[] { 5 }); - int index = span.LastIndexOf(value); + int index = span.LastIndexOf(value); Assert.Equal(-1, index); } } From 225589aed183380f36000aafed4e2b3c9ce2edf1 Mon Sep 17 00:00:00 2001 From: ahsonkhan Date: Wed, 6 Dec 2017 18:14:08 -0800 Subject: [PATCH 8/9] Cleanup and format all files in the solution to follow coding style. --- src/Common/src/System/NotImplemented.cs | 2 +- src/Common/tests/System/PerfUtils.cs | 3 +- .../Common/src/System/MutableDecimal.cs | 1 - src/System.Memory/ref/System.Memory.cs | 34 +-- .../src/System/Buffers/Binary/Reader.cs | 1 - .../Buffers/Binary/ReaderLittleEndian.cs | 2 +- .../src/System/Buffers/Binary/Writer.cs | 1 - .../src/System/Buffers/MemoryHandle.cs | 10 +- .../src/System/Buffers/OwnedMemory.cs | 6 +- .../src/System/Buffers/Text/Base64Decoder.cs | 70 ++++--- .../src/System/Buffers/Text/Base64Encoder.cs | 21 +- .../src/System/Buffers/Text/Utf8Constants.cs | 6 +- .../Text/Utf8Formatter/FormattingHelpers.cs | 18 +- .../Utf8Formatter/Utf8Formatter.Boolean.cs | 2 +- .../Utf8Formatter/Utf8Formatter.Date.G.cs | 4 +- .../Utf8Formatter/Utf8Formatter.Date.L.cs | 1 - .../Utf8Formatter/Utf8Formatter.Date.O.cs | 3 +- .../Utf8Formatter/Utf8Formatter.Date.R.cs | 1 - .../Text/Utf8Formatter/Utf8Formatter.Date.cs | 9 +- .../Utf8Formatter/Utf8Formatter.Decimal.E.cs | 2 - .../Utf8Formatter/Utf8Formatter.Decimal.F.cs | 1 - .../Utf8Formatter/Utf8Formatter.Decimal.cs | 1 - .../Text/Utf8Formatter/Utf8Formatter.Guid.cs | 1 - .../Utf8Formatter.Integer.Signed.D.cs | 1 - .../Utf8Formatter.Integer.Signed.Default.cs | 11 +- .../Utf8Formatter.Integer.Signed.cs | 3 - .../Utf8Formatter.Integer.Unsigned.D.cs | 3 - .../Utf8Formatter.Integer.Unsigned.Default.cs | 6 +- .../Utf8Formatter.Integer.Unsigned.N.cs | 1 - .../Utf8Formatter.Integer.Unsigned.X.cs | 1 - .../Utf8Formatter.Integer.Unsigned.cs | 3 - .../Utf8Formatter/Utf8Formatter.Integer.cs | 3 - .../Utf8Formatter/Utf8Formatter.TimeSpan.cs | 1 - .../Utf8Parser/Utf8Parser.Date.Default.cs | 3 - .../Text/Utf8Parser/Utf8Parser.Date.R.cs | 2 - .../Text/Utf8Parser/Utf8Parser.Decimal.cs | 2 - .../Text/Utf8Parser/Utf8Parser.Float.cs | 2 - .../Text/Utf8Parser/Utf8Parser.Guid.cs | 1 - .../Utf8Parser/Utf8Parser.Integer.Signed.D.cs | 12 +- .../Utf8Parser.Integer.Unsigned.D.cs | 12 +- .../Utf8Parser.Integer.Unsigned.N.cs | 2 - .../Utf8Parser/Utf8Parser.TimeSpan.LittleG.cs | 2 - src/System.Memory/src/System/Memory.cs | 6 +- .../src/System/MemoryExtensions.Fast.cs | 5 +- .../src/System/MemoryExtensions.Portable.cs | 1 - .../src/System/MemoryExtensions.cs | 41 ++-- .../src/System/Number/Decimal.DecCalc.cs | 2 - .../System/Number/Number.FormatAndParse.cs | 1 - src/System.Memory/src/System/Number/Number.cs | 5 - .../src/System/ReadOnlyMemory.cs | 6 +- src/System.Memory/src/System/ReadOnlySpan.cs | 1 - src/System.Memory/src/System/SpanHelpers.T.cs | 22 +- .../src/System/SpanHelpers.byte.cs | 24 +-- src/System.Memory/tests/AllocationHelper.cs | 10 +- .../tests/Base64/Base64DecoderUnitTests.cs | 31 +-- .../tests/Base64/Base64EncoderUnitTests.cs | 8 +- .../tests/Base64/Base64TestHelper.cs | 2 +- .../tests/Binary/BinaryReaderUnitTests.cs | 64 +++--- .../tests/Binary/BinaryWriterUnitTests.cs | 6 +- src/System.Memory/tests/Memory/CopyTo.cs | 4 +- .../tests/Memory/CustomMemoryForTest.cs | 3 +- src/System.Memory/tests/Memory/OwnedMemory.cs | 3 +- src/System.Memory/tests/Memory/ToArray.cs | 2 +- .../Formatter/FormatterTestData.cs | 10 +- .../Formatter/TestData.Formatter.cs | 4 +- .../Parser/ParserTestData.cs | 4 +- .../Parser/TestData.Parser.Date.cs | 2 +- .../TestData.Parser.DecimalsAndFloats.cs | 2 +- .../Parser/TestData.Parser.TimeSpan.cs | 30 +-- .../ParsersAndFormatters/PseudoDateTime.cs | 10 +- .../tests/ParsersAndFormatters/TestData.cs | 2 +- .../tests/ParsersAndFormatters/TestUtils.cs | 2 +- .../Performance/Perf.Base64EncodeDecode.cs | 39 ++-- .../tests/Performance/Perf.MemorySlice.cs | 14 +- .../Perf.Span.BinaryReadAndWrite.cs | 15 +- .../tests/Performance/Perf.Span.IndexOf.cs | 16 +- .../tests/Performance/Perf.Utf8Formatter.cs | 2 - .../tests/Performance/Perf.Utf8Parser.cs | 1 - .../tests/ReadOnlyMemory/CopyTo.cs | 2 +- .../ReadOnlyMemory/ImplicitConversion.cs | 4 +- .../tests/ReadOnlySpan/CopyTo.cs | 6 +- .../tests/ReadOnlySpan/CtorPointerInt.cs | 2 +- .../tests/ReadOnlySpan/IndexOf.T.cs | 2 +- .../tests/ReadOnlySpan/IndexOf.char.cs | 2 +- .../tests/ReadOnlySpan/IndexOfSequence.T.cs | 2 +- .../tests/ReadOnlySpan/LastIndexOf.T.cs | 2 +- .../tests/ReadOnlySpan/LastIndexOf.byte.cs | 2 +- .../tests/ReadOnlySpan/LastIndexOf.char.cs | 2 +- .../tests/ReadOnlySpan/Overflow.cs | 9 +- src/System.Memory/tests/Span/Clear.cs | 5 +- src/System.Memory/tests/Span/CopyTo.cs | 6 +- src/System.Memory/tests/Span/IndexOf.T.cs | 2 +- src/System.Memory/tests/Span/IndexOf.char.cs | 2 +- src/System.Memory/tests/Span/LastIndexOf.T.cs | 2 +- .../tests/Span/LastIndexOf.byte.cs | 2 +- .../tests/Span/LastIndexOf.char.cs | 2 +- src/System.Memory/tests/Span/Overflow.cs | 9 +- src/System.Memory/tests/TInt.cs | 2 +- src/System.Memory/tests/TestHelpers.cs | 56 ++--- src/System.Runtime/ref/System.Runtime.cs | 197 +++++++++--------- 100 files changed, 483 insertions(+), 508 deletions(-) diff --git a/src/Common/src/System/NotImplemented.cs b/src/Common/src/System/NotImplemented.cs index ffbec64447a7..fa0fe07fa79d 100644 --- a/src/Common/src/System/NotImplemented.cs +++ b/src/Common/src/System/NotImplemented.cs @@ -26,6 +26,6 @@ internal static Exception ByDesignWithMessage(string message) /// Temporary NotImplementedException with no message shown to user. /// Example: Exception.ActiveIssue("https://github.com/dotnet/corefx/issues/xxxx") or Exception.ActiveIssue("TFS xxxxxx"). /// - internal static Exception ActiveIssue(string issue) => new NotImplementedException(); + internal static Exception ActiveIssue(string issue) => new NotImplementedException(); } } diff --git a/src/Common/tests/System/PerfUtils.cs b/src/Common/tests/System/PerfUtils.cs index 5c5918b4ea1f..f205f0bf911d 100644 --- a/src/Common/tests/System/PerfUtils.cs +++ b/src/Common/tests/System/PerfUtils.cs @@ -4,7 +4,6 @@ using System.IO; using System.Runtime.CompilerServices; -using System.Text; namespace System { @@ -42,7 +41,7 @@ public string CreateString(int length) for (int i = 0; i < str.Length; i++) { // Add path separator so folders aren't too long. - if (i%20 == 0) + if (i % 20 == 0) { str[i] = Path.DirectorySeparatorChar; } diff --git a/src/System.Memory/Common/src/System/MutableDecimal.cs b/src/System.Memory/Common/src/System/MutableDecimal.cs index 2a66930ac79b..a5541a6f2a03 100644 --- a/src/System.Memory/Common/src/System/MutableDecimal.cs +++ b/src/System.Memory/Common/src/System/MutableDecimal.cs @@ -2,7 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using System.Diagnostics; using System.Runtime.InteropServices; namespace System diff --git a/src/System.Memory/ref/System.Memory.cs b/src/System.Memory/ref/System.Memory.cs index a615d728c8be..2ede32c3ab52 100644 --- a/src/System.Memory/ref/System.Memory.cs +++ b/src/System.Memory/ref/System.Memory.cs @@ -15,7 +15,7 @@ public readonly ref struct ReadOnlySpan [CLSCompliant(false)] public unsafe ReadOnlySpan(void* pointer, int length) { throw null; } public bool IsEmpty { get { throw null; } } - public T this[int index] { get { throw null; }} + public T this[int index] { get { throw null; } } public int Length { get { throw null; } } public void CopyTo(Span destination) { } [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] @@ -32,8 +32,8 @@ public void CopyTo(Span destination) { } public override int GetHashCode() { throw null; } #pragma warning restore 0809 public static bool operator ==(ReadOnlySpan left, ReadOnlySpan right) { throw null; } - public static implicit operator ReadOnlySpan (T[] array) { throw null; } - public static implicit operator ReadOnlySpan (ArraySegment arraySegment) { throw null; } + public static implicit operator ReadOnlySpan(T[] array) { throw null; } + public static implicit operator ReadOnlySpan(ArraySegment arraySegment) { throw null; } public static bool operator !=(ReadOnlySpan left, ReadOnlySpan right) { throw null; } public ReadOnlySpan Slice(int start) { throw null; } public ReadOnlySpan Slice(int start, int length) { throw null; } @@ -73,9 +73,9 @@ public void CopyTo(Span destination) { } public override int GetHashCode() { throw null; } #pragma warning restore 0809 public static bool operator ==(Span left, Span right) { throw null; } - public static implicit operator Span (T[] array) { throw null; } - public static implicit operator Span (ArraySegment arraySegment) { throw null; } - public static implicit operator ReadOnlySpan (Span span) { throw null; } + public static implicit operator Span(T[] array) { throw null; } + public static implicit operator Span(ArraySegment arraySegment) { throw null; } + public static implicit operator ReadOnlySpan(Span span) { throw null; } public static bool operator !=(Span left, Span right) { throw null; } public Span Slice(int start) { throw null; } public Span Slice(int start, int length) { throw null; } @@ -87,7 +87,7 @@ public ref struct Enumerator public ref T Current { get { throw null; } } } } - + public static class MemoryExtensions { public static int IndexOf(this Span span, T value) where T : IEquatable { throw null; } @@ -101,7 +101,7 @@ public static class MemoryExtensions public static int LastIndexOf(this Span span, ReadOnlySpan value) where T : IEquatable { throw null; } public static bool SequenceEqual(this Span first, ReadOnlySpan second) where T : IEquatable { throw null; } - + public static bool StartsWith(this Span span, ReadOnlySpan value) where T : IEquatable { throw null; } public static bool EndsWith(this Span span, ReadOnlySpan value) where T : IEquatable { throw null; } @@ -110,7 +110,7 @@ public static class MemoryExtensions public static Span AsBytes(this Span source) where T : struct { throw null; } public static Span NonPortableCast(this Span source) where TFrom : struct where TTo : struct { throw null; } - + public static ReadOnlySpan AsReadOnlySpan(this string text) { throw null; } public static ReadOnlyMemory AsReadOnlyMemory(this string text) { throw null; } @@ -139,7 +139,7 @@ public static class MemoryExtensions public static bool StartsWith(this ReadOnlySpan span, ReadOnlySpan value) where T : IEquatable { throw null; } public static ReadOnlySpan AsBytes(this ReadOnlySpan source) where T : struct { throw null; } - + public static ReadOnlySpan NonPortableCast(this ReadOnlySpan source) where TFrom : struct where TTo : struct { throw null; } public static bool TryGetString(this ReadOnlyMemory readOnlyMemory, out string text, out int start, out int length) { throw null; } @@ -203,23 +203,23 @@ public void CopyTo(Memory destination) { } namespace System.Buffers { - public unsafe struct MemoryHandle : IDisposable + public unsafe struct MemoryHandle : IDisposable { [CLSCompliant(false)] - public MemoryHandle(IRetainable owner, void* pointer = null, System.Runtime.InteropServices.GCHandle handle = default) { throw null; } + public MemoryHandle(IRetainable owner, void* pointer = null, System.Runtime.InteropServices.GCHandle handle = default) { throw null; } [CLSCompliant(false)] public void* Pointer { get { throw null; } } public bool HasPointer { get { throw null; } } public void Dispose() { throw null; } } - public interface IRetainable + public interface IRetainable { bool Release(); void Retain(); } - - public abstract class OwnedMemory : IDisposable, IRetainable + + public abstract class OwnedMemory : IDisposable, IRetainable { public Memory Memory { get { throw null; } } public abstract bool IsDisposed { get; } @@ -354,12 +354,12 @@ namespace System.Buffers { public const byte MaxPrecision = (byte)99; public const byte NoPrecision = (byte)255; - public StandardFormat(char symbol, byte precision=(byte)255) => throw null; + public StandardFormat(char symbol, byte precision = (byte)255) => throw null; public bool HasPrecision => throw null; public bool IsDefault => throw null; public byte Precision => throw null; public char Symbol => throw null; - public static implicit operator StandardFormat (char symbol) => throw null; + public static implicit operator StandardFormat(char symbol) => throw null; public static StandardFormat Parse(ReadOnlySpan format) => throw null; public static StandardFormat Parse(string format) => throw null; public override bool Equals(object obj) => throw null; diff --git a/src/System.Memory/src/System/Buffers/Binary/Reader.cs b/src/System.Memory/src/System/Buffers/Binary/Reader.cs index af2fad82a296..177d92a04a59 100644 --- a/src/System.Memory/src/System/Buffers/Binary/Reader.cs +++ b/src/System.Memory/src/System/Buffers/Binary/Reader.cs @@ -2,7 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using System.Runtime; using System.Runtime.CompilerServices; namespace System.Buffers.Binary diff --git a/src/System.Memory/src/System/Buffers/Binary/ReaderLittleEndian.cs b/src/System.Memory/src/System/Buffers/Binary/ReaderLittleEndian.cs index 05c26fbbc040..17cebf1f276f 100644 --- a/src/System.Memory/src/System/Buffers/Binary/ReaderLittleEndian.cs +++ b/src/System.Memory/src/System/Buffers/Binary/ReaderLittleEndian.cs @@ -94,7 +94,7 @@ public static ulong ReadUInt64LittleEndian(ReadOnlySpan buffer) } return result; } - + /// /// Reads an Int16 out of a read-only span of bytes as little endian. /// If the span is too small to contain an Int16, return false. diff --git a/src/System.Memory/src/System/Buffers/Binary/Writer.cs b/src/System.Memory/src/System/Buffers/Binary/Writer.cs index 2f0ea14caf41..2a7f11f05eba 100644 --- a/src/System.Memory/src/System/Buffers/Binary/Writer.cs +++ b/src/System.Memory/src/System/Buffers/Binary/Writer.cs @@ -2,7 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using System.Runtime; using System.Runtime.CompilerServices; namespace System.Buffers.Binary diff --git a/src/System.Memory/src/System/Buffers/MemoryHandle.cs b/src/System.Memory/src/System/Buffers/MemoryHandle.cs index 35d0ab6f0c8e..fb192d1a6bc9 100644 --- a/src/System.Memory/src/System/Buffers/MemoryHandle.cs +++ b/src/System.Memory/src/System/Buffers/MemoryHandle.cs @@ -63,20 +63,20 @@ internal void AddOffset(int offset) /// Frees the pinned handle and releases IRetainable. /// public void Dispose() - { - if (_handle.IsAllocated) + { + if (_handle.IsAllocated) { _handle.Free(); } - if (_retainable != null) + if (_retainable != null) { _retainable.Release(); _retainable = null; } - _pointer = null; + _pointer = null; } - + } } diff --git a/src/System.Memory/src/System/Buffers/OwnedMemory.cs b/src/System.Memory/src/System/Buffers/OwnedMemory.cs index 3daae843daec..0342ed9196bc 100644 --- a/src/System.Memory/src/System/Buffers/OwnedMemory.cs +++ b/src/System.Memory/src/System/Buffers/OwnedMemory.cs @@ -32,9 +32,9 @@ public abstract class OwnedMemory : IDisposable, IRetainable /// public Memory Memory { - get + get { - if (IsDisposed) + if (IsDisposed) { ThrowHelper.ThrowObjectDisposedException_MemoryDisposed(nameof(OwnedMemory)); } @@ -60,7 +60,7 @@ public Memory Memory /// public void Dispose() { - if (IsRetained) + if (IsRetained) { ThrowHelper.ThrowInvalidOperationException_OutstandingReferences(); } diff --git a/src/System.Memory/src/System/Buffers/Text/Base64Decoder.cs b/src/System.Memory/src/System/Buffers/Text/Base64Decoder.cs index c04ce0b4abe3..73d345a69512 100644 --- a/src/System.Memory/src/System/Buffers/Text/Base64Decoder.cs +++ b/src/System.Memory/src/System/Buffers/Text/Base64Decoder.cs @@ -2,8 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using System.Buffers; -using System.Diagnostics; using System.Runtime.CompilerServices; namespace System.Buffers.Text @@ -38,7 +36,8 @@ public static OperationStatus DecodeFromUtf8(ReadOnlySpan utf8, Span int sourceIndex = 0; int destIndex = 0; - if (utf8.Length == 0) goto DoneExit; + if (utf8.Length == 0) + goto DoneExit; ref sbyte decodingMap = ref s_decodingMap[0]; @@ -61,24 +60,27 @@ public static OperationStatus DecodeFromUtf8(ReadOnlySpan utf8, Span while (sourceIndex < maxSrcLength) { int result = Decode(ref Unsafe.Add(ref srcBytes, sourceIndex), ref decodingMap); - if (result < 0) goto InvalidExit; + if (result < 0) + goto InvalidExit; WriteThreeLowOrderBytes(ref Unsafe.Add(ref destBytes, destIndex), result); destIndex += 3; sourceIndex += 4; } - if (maxSrcLength != srcLength - skipLastChunk) goto DestinationSmallExit; + if (maxSrcLength != srcLength - skipLastChunk) + goto DestinationSmallExit; // If input is less than 4 bytes, srcLength == sourceIndex == 0 // If input is not a multiple of 4, sourceIndex == srcLength != 0 if (sourceIndex == srcLength) { - if (isFinalBlock) goto InvalidExit; + if (isFinalBlock) + goto InvalidExit; goto NeedMoreExit; } // if isFinalBlock is false, we will never reach this point - + int i0 = Unsafe.Add(ref srcBytes, srcLength - 4); int i1 = Unsafe.Add(ref srcBytes, srcLength - 3); int i2 = Unsafe.Add(ref srcBytes, srcLength - 2); @@ -102,8 +104,10 @@ public static OperationStatus DecodeFromUtf8(ReadOnlySpan utf8, Span i0 |= i3; i0 |= i2; - if (i0 < 0) goto InvalidExit; - if (destIndex > destLength - 3) goto DestinationSmallExit; + if (i0 < 0) + goto InvalidExit; + if (destIndex > destLength - 3) + goto DestinationSmallExit; WriteThreeLowOrderBytes(ref Unsafe.Add(ref destBytes, destIndex), i0); destIndex += 3; } @@ -115,41 +119,47 @@ public static OperationStatus DecodeFromUtf8(ReadOnlySpan utf8, Span i0 |= i2; - if (i0 < 0) goto InvalidExit; - if (destIndex > destLength - 2) goto DestinationSmallExit; + if (i0 < 0) + goto InvalidExit; + if (destIndex > destLength - 2) + goto DestinationSmallExit; Unsafe.Add(ref destBytes, destIndex) = (byte)(i0 >> 16); Unsafe.Add(ref destBytes, destIndex + 1) = (byte)(i0 >> 8); destIndex += 2; } else { - if (i0 < 0) goto InvalidExit; - if (destIndex > destLength - 1) goto DestinationSmallExit; + if (i0 < 0) + goto InvalidExit; + if (destIndex > destLength - 1) + goto DestinationSmallExit; Unsafe.Add(ref destBytes, destIndex) = (byte)(i0 >> 16); destIndex += 1; } sourceIndex += 4; - if (srcLength != utf8.Length) goto InvalidExit; + if (srcLength != utf8.Length) + goto InvalidExit; - DoneExit: + DoneExit: consumed = sourceIndex; written = destIndex; return OperationStatus.Done; - DestinationSmallExit: - if (srcLength != utf8.Length && isFinalBlock) goto InvalidExit; // if input is not a multiple of 4, and there is no more data, return invalid data instead + DestinationSmallExit: + if (srcLength != utf8.Length && isFinalBlock) + goto InvalidExit; // if input is not a multiple of 4, and there is no more data, return invalid data instead consumed = sourceIndex; written = destIndex; return OperationStatus.DestinationTooSmall; - NeedMoreExit: + NeedMoreExit: consumed = sourceIndex; written = destIndex; return OperationStatus.NeedMoreData; - InvalidExit: + InvalidExit: consumed = sourceIndex; written = destIndex; return OperationStatus.InvalidData; @@ -192,8 +202,10 @@ public static OperationStatus DecodeFromUtf8InPlace(Span buffer, out int w int destIndex = 0; // only decode input if it is a multiple of 4 - if (bufferLength != ((bufferLength >> 2) * 4)) goto InvalidExit; - if (bufferLength == 0) goto DoneExit; + if (bufferLength != ((bufferLength >> 2) * 4)) + goto InvalidExit; + if (bufferLength == 0) + goto DoneExit; ref byte bufferBytes = ref buffer.DangerousGetPinnableReference(); @@ -202,7 +214,8 @@ public static OperationStatus DecodeFromUtf8InPlace(Span buffer, out int w while (sourceIndex < bufferLength - 4) { int result = Decode(ref Unsafe.Add(ref bufferBytes, sourceIndex), ref decodingMap); - if (result < 0) goto InvalidExit; + if (result < 0) + goto InvalidExit; WriteThreeLowOrderBytes(ref Unsafe.Add(ref bufferBytes, destIndex), result); destIndex += 3; sourceIndex += 4; @@ -231,7 +244,8 @@ public static OperationStatus DecodeFromUtf8InPlace(Span buffer, out int w i0 |= i3; i0 |= i2; - if (i0 < 0) goto InvalidExit; + if (i0 < 0) + goto InvalidExit; WriteThreeLowOrderBytes(ref Unsafe.Add(ref bufferBytes, destIndex), i0); destIndex += 3; } @@ -243,23 +257,25 @@ public static OperationStatus DecodeFromUtf8InPlace(Span buffer, out int w i0 |= i2; - if (i0 < 0) goto InvalidExit; + if (i0 < 0) + goto InvalidExit; Unsafe.Add(ref bufferBytes, destIndex) = (byte)(i0 >> 16); Unsafe.Add(ref bufferBytes, destIndex + 1) = (byte)(i0 >> 8); destIndex += 2; } else { - if (i0 < 0) goto InvalidExit; + if (i0 < 0) + goto InvalidExit; Unsafe.Add(ref bufferBytes, destIndex) = (byte)(i0 >> 16); destIndex += 1; } - DoneExit: + DoneExit: written = destIndex; return OperationStatus.Done; - InvalidExit: + InvalidExit: written = destIndex; return OperationStatus.InvalidData; } diff --git a/src/System.Memory/src/System/Buffers/Text/Base64Encoder.cs b/src/System.Memory/src/System/Buffers/Text/Base64Encoder.cs index 050719017db3..8dac2ca80cdd 100644 --- a/src/System.Memory/src/System/Buffers/Text/Base64Encoder.cs +++ b/src/System.Memory/src/System/Buffers/Text/Base64Encoder.cs @@ -2,8 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using System.Buffers; -using System.Diagnostics; using System.Runtime.CompilerServices; namespace System.Buffers.Text @@ -60,9 +58,11 @@ public static OperationStatus EncodeToUtf8(ReadOnlySpan bytes, Span sourceIndex += 3; } - if (maxSrcLength != srcLength - 2) goto DestinationSmallExit; - - if (isFinalBlock != true) goto NeedMoreDataExit; + if (maxSrcLength != srcLength - 2) + goto DestinationSmallExit; + + if (isFinalBlock != true) + goto NeedMoreDataExit; if (sourceIndex == srcLength - 1) { @@ -83,12 +83,12 @@ public static OperationStatus EncodeToUtf8(ReadOnlySpan bytes, Span written = destIndex; return OperationStatus.Done; - NeedMoreDataExit: + NeedMoreDataExit: consumed = sourceIndex; written = destIndex; return OperationStatus.NeedMoreData; - DestinationSmallExit: + DestinationSmallExit: consumed = sourceIndex; written = destIndex; return OperationStatus.DestinationTooSmall; @@ -127,7 +127,8 @@ public static int GetMaxEncodedToUtf8Length(int length) public static OperationStatus EncodeToUtf8InPlace(Span buffer, int dataLength, out int written) { int encodedLength = GetMaxEncodedToUtf8Length(dataLength); - if (buffer.Length < encodedLength) goto FalseExit; + if (buffer.Length < encodedLength) + goto FalseExit; int leftover = dataLength - dataLength / 3 * 3; // how many bytes after packs of 3 @@ -137,7 +138,7 @@ public static OperationStatus EncodeToUtf8InPlace(Span buffer, int dataLen ref byte encodingMap = ref s_encodingMap[0]; ref byte bufferBytes = ref buffer.DangerousGetPinnableReference(); - + // encode last pack to avoid conditional in the main loop if (leftover != 0) { @@ -167,7 +168,7 @@ public static OperationStatus EncodeToUtf8InPlace(Span buffer, int dataLen written = encodedLength; return OperationStatus.Done; - FalseExit: + FalseExit: written = 0; return OperationStatus.DestinationTooSmall; } diff --git a/src/System.Memory/src/System/Buffers/Text/Utf8Constants.cs b/src/System.Memory/src/System/Buffers/Text/Utf8Constants.cs index 9a4769861557..49215b5f6643 100644 --- a/src/System.Memory/src/System/Buffers/Text/Utf8Constants.cs +++ b/src/System.Memory/src/System/Buffers/Text/Utf8Constants.cs @@ -21,12 +21,12 @@ internal static partial class Utf8Constants // ex. 1,234,567,890 public const int GroupSize = 3; - public static readonly byte[] s_True = { (byte)'T', (byte)'r', (byte)'u', (byte)'e' }; - public static readonly byte[] s_False = { (byte)'F', (byte)'a', (byte)'l', (byte)'s', (byte)'e' }; + public static readonly byte[] s_capitalizedTrue = { (byte)'T', (byte)'r', (byte)'u', (byte)'e' }; + public static readonly byte[] s_capitalizedFalse = { (byte)'F', (byte)'a', (byte)'l', (byte)'s', (byte)'e' }; public static readonly byte[] s_true = { (byte)'t', (byte)'r', (byte)'u', (byte)'e' }; public static readonly byte[] s_false = { (byte)'f', (byte)'a', (byte)'l', (byte)'s', (byte)'e' }; - public static readonly TimeSpan NullUtcOffset = TimeSpan.MinValue; // Utc offsets must range from -14:00 to 14:00 so this is never a valid offset. + public static readonly TimeSpan s_nullUtcOffset = TimeSpan.MinValue; // Utc offsets must range from -14:00 to 14:00 so this is never a valid offset. public const int DateTimeMaxUtcOffsetHours = 14; // The UTC offset portion of a TimeSpan or DateTime can be no more than 14 hours and no less than -14 hours. diff --git a/src/System.Memory/src/System/Buffers/Text/Utf8Formatter/FormattingHelpers.cs b/src/System.Memory/src/System/Buffers/Text/Utf8Formatter/FormattingHelpers.cs index 1cf02cad7eda..5a150126044f 100644 --- a/src/System.Memory/src/System/Buffers/Text/Utf8Formatter/FormattingHelpers.cs +++ b/src/System.Memory/src/System/Buffers/Text/Utf8Formatter/FormattingHelpers.cs @@ -83,7 +83,7 @@ public static void WriteDigits(ulong value, int digitCount, ref byte buffer, int left = DivMod(left, 10, out ulong num); Unsafe.Add(ref buffer, index + i) = (byte)('0' + num); } - + Debug.Assert(left == 0); } @@ -156,11 +156,11 @@ public static int CountDigits(ulong value) part = (uint)value; } - if (part < 10) - { + if (part < 10) + { // no-op } - else if (part < 100) + else if (part < 100) { digits += 1; } @@ -168,20 +168,20 @@ public static int CountDigits(ulong value) { digits += 2; } - else if (part < 10000) + else if (part < 10000) { digits += 3; } - else if (part < 100000) + else if (part < 100000) { digits += 4; } - else if (part < 1000000) + else if (part < 1000000) { digits += 5; } - else - { + else + { Debug.Assert(part < 10000000); digits += 6; } diff --git a/src/System.Memory/src/System/Buffers/Text/Utf8Formatter/Utf8Formatter.Boolean.cs b/src/System.Memory/src/System/Buffers/Text/Utf8Formatter/Utf8Formatter.Boolean.cs index f0fee509b47e..e27c47a68055 100644 --- a/src/System.Memory/src/System/Buffers/Text/Utf8Formatter/Utf8Formatter.Boolean.cs +++ b/src/System.Memory/src/System/Buffers/Text/Utf8Formatter/Utf8Formatter.Boolean.cs @@ -30,7 +30,7 @@ public static bool TryFormat(bool value, Span buffer, out int bytesWritten ReadOnlySpan result; if (format.IsDefault || format.Symbol == 'G') { - result = value ? Utf8Constants.s_True : Utf8Constants.s_False; + result = value ? Utf8Constants.s_capitalizedTrue : Utf8Constants.s_capitalizedFalse; } else if (format.Symbol == 'l') { diff --git a/src/System.Memory/src/System/Buffers/Text/Utf8Formatter/Utf8Formatter.Date.G.cs b/src/System.Memory/src/System/Buffers/Text/Utf8Formatter/Utf8Formatter.Date.G.cs index 44cc38f743c9..9c52817aa687 100644 --- a/src/System.Memory/src/System/Buffers/Text/Utf8Formatter/Utf8Formatter.Date.G.cs +++ b/src/System.Memory/src/System/Buffers/Text/Utf8Formatter/Utf8Formatter.Date.G.cs @@ -27,7 +27,7 @@ private static bool TryFormatDateTimeG(DateTime value, TimeSpan offset, Span public static bool TryFormat(DateTimeOffset value, Span buffer, out int bytesWritten, StandardFormat format = default) { - TimeSpan offset = Utf8Constants.NullUtcOffset; + TimeSpan offset = Utf8Constants.s_nullUtcOffset; char symbol = format.Symbol; if (format.IsDefault) { @@ -159,10 +156,10 @@ public static bool TryFormat(DateTime value, Span buffer, out int bytesWri return TryFormatDateTimeL(value, buffer, out bytesWritten); case 'O': - return TryFormatDateTimeO(value, Utf8Constants.NullUtcOffset, buffer, out bytesWritten); + return TryFormatDateTimeO(value, Utf8Constants.s_nullUtcOffset, buffer, out bytesWritten); case 'G': - return TryFormatDateTimeG(value, Utf8Constants.NullUtcOffset, buffer, out bytesWritten); + return TryFormatDateTimeG(value, Utf8Constants.s_nullUtcOffset, buffer, out bytesWritten); default: return ThrowHelper.TryFormatThrowFormatException(out bytesWritten); diff --git a/src/System.Memory/src/System/Buffers/Text/Utf8Formatter/Utf8Formatter.Decimal.E.cs b/src/System.Memory/src/System/Buffers/Text/Utf8Formatter/Utf8Formatter.Decimal.E.cs index eb922cee7e36..840e766d49ed 100644 --- a/src/System.Memory/src/System/Buffers/Text/Utf8Formatter/Utf8Formatter.Decimal.E.cs +++ b/src/System.Memory/src/System/Buffers/Text/Utf8Formatter/Utf8Formatter.Decimal.E.cs @@ -3,7 +3,6 @@ // See the LICENSE file in the project root for more information. using System.Diagnostics; -using System.Runtime.CompilerServices; namespace System.Buffers.Text { @@ -23,7 +22,6 @@ private static bool TryFormatDecimalE(ref NumberBuffer number, Span buffer + 2 // 'E' or 'e' followed by '+' or '-' + NumExponentDigits; // exponent digits - if (buffer.Length < numBytesNeeded) { bytesWritten = 0; diff --git a/src/System.Memory/src/System/Buffers/Text/Utf8Formatter/Utf8Formatter.Decimal.F.cs b/src/System.Memory/src/System/Buffers/Text/Utf8Formatter/Utf8Formatter.Decimal.F.cs index c93b97e7422a..d26ea4bd3e66 100644 --- a/src/System.Memory/src/System/Buffers/Text/Utf8Formatter/Utf8Formatter.Decimal.F.cs +++ b/src/System.Memory/src/System/Buffers/Text/Utf8Formatter/Utf8Formatter.Decimal.F.cs @@ -3,7 +3,6 @@ // See the LICENSE file in the project root for more information. using System.Diagnostics; -using System.Runtime.CompilerServices; namespace System.Buffers.Text { diff --git a/src/System.Memory/src/System/Buffers/Text/Utf8Formatter/Utf8Formatter.Decimal.cs b/src/System.Memory/src/System/Buffers/Text/Utf8Formatter/Utf8Formatter.Decimal.cs index 64d4edbae055..af292ae952a9 100644 --- a/src/System.Memory/src/System/Buffers/Text/Utf8Formatter/Utf8Formatter.Decimal.cs +++ b/src/System.Memory/src/System/Buffers/Text/Utf8Formatter/Utf8Formatter.Decimal.cs @@ -3,7 +3,6 @@ // See the LICENSE file in the project root for more information. using System.Diagnostics; -using System.Runtime.CompilerServices; namespace System.Buffers.Text { diff --git a/src/System.Memory/src/System/Buffers/Text/Utf8Formatter/Utf8Formatter.Guid.cs b/src/System.Memory/src/System/Buffers/Text/Utf8Formatter/Utf8Formatter.Guid.cs index 71a851c47eb8..59ee9f2c23f8 100644 --- a/src/System.Memory/src/System/Buffers/Text/Utf8Formatter/Utf8Formatter.Guid.cs +++ b/src/System.Memory/src/System/Buffers/Text/Utf8Formatter/Utf8Formatter.Guid.cs @@ -75,7 +75,6 @@ public static unsafe bool TryFormat(Guid value, Span buffer, out int bytes return ThrowHelper.TryFormatThrowFormatException(out bytesWritten); } - bytesWritten = GuidChars + (dash ? 4 : 0) + (bookEnds ? 2 : 0); if (buffer.Length < bytesWritten) { diff --git a/src/System.Memory/src/System/Buffers/Text/Utf8Formatter/Utf8Formatter.Integer.Signed.D.cs b/src/System.Memory/src/System/Buffers/Text/Utf8Formatter/Utf8Formatter.Integer.Signed.D.cs index 350b4ad2c038..87b477731abb 100644 --- a/src/System.Memory/src/System/Buffers/Text/Utf8Formatter/Utf8Formatter.Integer.Signed.D.cs +++ b/src/System.Memory/src/System/Buffers/Text/Utf8Formatter/Utf8Formatter.Integer.Signed.D.cs @@ -2,7 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using System.Diagnostics; using System.Runtime.CompilerServices; namespace System.Buffers.Text diff --git a/src/System.Memory/src/System/Buffers/Text/Utf8Formatter/Utf8Formatter.Integer.Signed.Default.cs b/src/System.Memory/src/System/Buffers/Text/Utf8Formatter/Utf8Formatter.Integer.Signed.Default.cs index eb54023de2b5..c21cab591975 100644 --- a/src/System.Memory/src/System/Buffers/Text/Utf8Formatter/Utf8Formatter.Integer.Signed.Default.cs +++ b/src/System.Memory/src/System/Buffers/Text/Utf8Formatter/Utf8Formatter.Integer.Signed.Default.cs @@ -13,17 +13,19 @@ private static bool TryFormatInt64Default(long value, Span buffer, out int { if ((ulong)value < 10) { - if (buffer.Length == 0) goto FalseExit; + if (buffer.Length == 0) + goto FalseExit; buffer[0] = (byte)('0' + value); bytesWritten = 1; return true; } - + if (value < 0) { value = -value; int digitCount = FormattingHelpers.CountDigits((ulong)value); - if (digitCount >= buffer.Length) goto FalseExit; + if (digitCount >= buffer.Length) + goto FalseExit; bytesWritten = digitCount + 1; buffer[0] = Utf8Constants.Minus; buffer = buffer.Slice(1, digitCount); @@ -31,7 +33,8 @@ private static bool TryFormatInt64Default(long value, Span buffer, out int else { int digitCount = FormattingHelpers.CountDigits((ulong)value); - if (digitCount > buffer.Length) goto FalseExit; + if (digitCount > buffer.Length) + goto FalseExit; bytesWritten = digitCount; buffer = buffer.Slice(0, digitCount); } diff --git a/src/System.Memory/src/System/Buffers/Text/Utf8Formatter/Utf8Formatter.Integer.Signed.cs b/src/System.Memory/src/System/Buffers/Text/Utf8Formatter/Utf8Formatter.Integer.Signed.cs index 565aa0d6ef64..971536fd75c6 100644 --- a/src/System.Memory/src/System/Buffers/Text/Utf8Formatter/Utf8Formatter.Integer.Signed.cs +++ b/src/System.Memory/src/System/Buffers/Text/Utf8Formatter/Utf8Formatter.Integer.Signed.cs @@ -2,9 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using System.Diagnostics; -using System.Runtime.CompilerServices; - namespace System.Buffers.Text { /// diff --git a/src/System.Memory/src/System/Buffers/Text/Utf8Formatter/Utf8Formatter.Integer.Unsigned.D.cs b/src/System.Memory/src/System/Buffers/Text/Utf8Formatter/Utf8Formatter.Integer.Unsigned.D.cs index 3b3b8d7803da..8b598934b1a7 100644 --- a/src/System.Memory/src/System/Buffers/Text/Utf8Formatter/Utf8Formatter.Integer.Unsigned.D.cs +++ b/src/System.Memory/src/System/Buffers/Text/Utf8Formatter/Utf8Formatter.Integer.Unsigned.D.cs @@ -2,9 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using System.Diagnostics; -using System.Runtime.CompilerServices; - namespace System.Buffers.Text { /// diff --git a/src/System.Memory/src/System/Buffers/Text/Utf8Formatter/Utf8Formatter.Integer.Unsigned.Default.cs b/src/System.Memory/src/System/Buffers/Text/Utf8Formatter/Utf8Formatter.Integer.Unsigned.Default.cs index 4871bfa044c7..bf3b05471e89 100644 --- a/src/System.Memory/src/System/Buffers/Text/Utf8Formatter/Utf8Formatter.Integer.Unsigned.Default.cs +++ b/src/System.Memory/src/System/Buffers/Text/Utf8Formatter/Utf8Formatter.Integer.Unsigned.Default.cs @@ -13,14 +13,16 @@ private static bool TryFormatUInt64Default(ulong value, Span buffer, out i { if (value < 10) { - if (buffer.Length == 0) goto FalseExit; + if (buffer.Length == 0) + goto FalseExit; buffer[0] = (byte)('0' + value); bytesWritten = 1; return true; } int digitCount = FormattingHelpers.CountDigits(value); - if (digitCount > buffer.Length) goto FalseExit; + if (digitCount > buffer.Length) + goto FalseExit; bytesWritten = digitCount; // WriteDigits does not do bounds checks FormattingHelpers.WriteDigits(value, buffer.Slice(0, digitCount)); diff --git a/src/System.Memory/src/System/Buffers/Text/Utf8Formatter/Utf8Formatter.Integer.Unsigned.N.cs b/src/System.Memory/src/System/Buffers/Text/Utf8Formatter/Utf8Formatter.Integer.Unsigned.N.cs index 2e3e731aec3f..1a25cefa0ba1 100644 --- a/src/System.Memory/src/System/Buffers/Text/Utf8Formatter/Utf8Formatter.Integer.Unsigned.N.cs +++ b/src/System.Memory/src/System/Buffers/Text/Utf8Formatter/Utf8Formatter.Integer.Unsigned.N.cs @@ -2,7 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using System.Diagnostics; using System.Runtime.CompilerServices; namespace System.Buffers.Text diff --git a/src/System.Memory/src/System/Buffers/Text/Utf8Formatter/Utf8Formatter.Integer.Unsigned.X.cs b/src/System.Memory/src/System/Buffers/Text/Utf8Formatter/Utf8Formatter.Integer.Unsigned.X.cs index 943e6e58b897..48fc223fd998 100644 --- a/src/System.Memory/src/System/Buffers/Text/Utf8Formatter/Utf8Formatter.Integer.Unsigned.X.cs +++ b/src/System.Memory/src/System/Buffers/Text/Utf8Formatter/Utf8Formatter.Integer.Unsigned.X.cs @@ -2,7 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using System.Diagnostics; using System.Runtime.CompilerServices; namespace System.Buffers.Text diff --git a/src/System.Memory/src/System/Buffers/Text/Utf8Formatter/Utf8Formatter.Integer.Unsigned.cs b/src/System.Memory/src/System/Buffers/Text/Utf8Formatter/Utf8Formatter.Integer.Unsigned.cs index eab646f51c0c..db06e505e3a9 100644 --- a/src/System.Memory/src/System/Buffers/Text/Utf8Formatter/Utf8Formatter.Integer.Unsigned.cs +++ b/src/System.Memory/src/System/Buffers/Text/Utf8Formatter/Utf8Formatter.Integer.Unsigned.cs @@ -2,9 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using System.Diagnostics; -using System.Runtime.CompilerServices; - namespace System.Buffers.Text { /// diff --git a/src/System.Memory/src/System/Buffers/Text/Utf8Formatter/Utf8Formatter.Integer.cs b/src/System.Memory/src/System/Buffers/Text/Utf8Formatter/Utf8Formatter.Integer.cs index ba5802a30931..a25155cab9ad 100644 --- a/src/System.Memory/src/System/Buffers/Text/Utf8Formatter/Utf8Formatter.Integer.cs +++ b/src/System.Memory/src/System/Buffers/Text/Utf8Formatter/Utf8Formatter.Integer.cs @@ -2,9 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using System.Diagnostics; -using System.Runtime.CompilerServices; - namespace System.Buffers.Text { /// diff --git a/src/System.Memory/src/System/Buffers/Text/Utf8Formatter/Utf8Formatter.TimeSpan.cs b/src/System.Memory/src/System/Buffers/Text/Utf8Formatter/Utf8Formatter.TimeSpan.cs index 433a8f6c5445..a1502d9e5ffc 100644 --- a/src/System.Memory/src/System/Buffers/Text/Utf8Formatter/Utf8Formatter.TimeSpan.cs +++ b/src/System.Memory/src/System/Buffers/Text/Utf8Formatter/Utf8Formatter.TimeSpan.cs @@ -2,7 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using System.Diagnostics; using System.Runtime.CompilerServices; namespace System.Buffers.Text diff --git a/src/System.Memory/src/System/Buffers/Text/Utf8Parser/Utf8Parser.Date.Default.cs b/src/System.Memory/src/System/Buffers/Text/Utf8Parser/Utf8Parser.Date.Default.cs index 227707a85f7d..73c21c853516 100644 --- a/src/System.Memory/src/System/Buffers/Text/Utf8Parser/Utf8Parser.Date.Default.cs +++ b/src/System.Memory/src/System/Buffers/Text/Utf8Parser/Utf8Parser.Date.Default.cs @@ -2,8 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using System.Diagnostics; - namespace System.Buffers.Text { public static partial class Utf8Parser @@ -47,7 +45,6 @@ private static bool TryParseDateTimeOffsetDefault(ReadOnlySpan text, out D return false; } - int offsetHours; { uint digit1 = text[21] - 48u; // '0' diff --git a/src/System.Memory/src/System/Buffers/Text/Utf8Parser/Utf8Parser.Date.R.cs b/src/System.Memory/src/System/Buffers/Text/Utf8Parser/Utf8Parser.Date.R.cs index 8781a746b553..af70ca62e5d4 100644 --- a/src/System.Memory/src/System/Buffers/Text/Utf8Parser/Utf8Parser.Date.R.cs +++ b/src/System.Memory/src/System/Buffers/Text/Utf8Parser/Utf8Parser.Date.R.cs @@ -2,8 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using System.Runtime.CompilerServices; - namespace System.Buffers.Text { public static partial class Utf8Parser diff --git a/src/System.Memory/src/System/Buffers/Text/Utf8Parser/Utf8Parser.Decimal.cs b/src/System.Memory/src/System/Buffers/Text/Utf8Parser/Utf8Parser.Decimal.cs index ee9612d18f20..59f74bb84738 100644 --- a/src/System.Memory/src/System/Buffers/Text/Utf8Parser/Utf8Parser.Decimal.cs +++ b/src/System.Memory/src/System/Buffers/Text/Utf8Parser/Utf8Parser.Decimal.cs @@ -2,8 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using System.Runtime.CompilerServices; - namespace System.Buffers.Text { public static partial class Utf8Parser diff --git a/src/System.Memory/src/System/Buffers/Text/Utf8Parser/Utf8Parser.Float.cs b/src/System.Memory/src/System/Buffers/Text/Utf8Parser/Utf8Parser.Float.cs index eb1269d3b92e..0b0e25e22d24 100644 --- a/src/System.Memory/src/System/Buffers/Text/Utf8Parser/Utf8Parser.Float.cs +++ b/src/System.Memory/src/System/Buffers/Text/Utf8Parser/Utf8Parser.Float.cs @@ -2,8 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using System.Diagnostics; - namespace System.Buffers.Text { public static partial class Utf8Parser diff --git a/src/System.Memory/src/System/Buffers/Text/Utf8Parser/Utf8Parser.Guid.cs b/src/System.Memory/src/System/Buffers/Text/Utf8Parser/Utf8Parser.Guid.cs index 82ea48d9e56b..2d38e6ec59b9 100644 --- a/src/System.Memory/src/System/Buffers/Text/Utf8Parser/Utf8Parser.Guid.cs +++ b/src/System.Memory/src/System/Buffers/Text/Utf8Parser/Utf8Parser.Guid.cs @@ -228,7 +228,6 @@ private static bool TryParseGuidCore(ReadOnlySpan text, bool ends, char be return false; // 12 digits } - if (ends && text[justConsumed] != end) { value = default; diff --git a/src/System.Memory/src/System/Buffers/Text/Utf8Parser/Utf8Parser.Integer.Signed.D.cs b/src/System.Memory/src/System/Buffers/Text/Utf8Parser/Utf8Parser.Integer.Signed.D.cs index 73946fe2dfe3..b5f7649181a9 100644 --- a/src/System.Memory/src/System/Buffers/Text/Utf8Parser/Utf8Parser.Integer.Signed.D.cs +++ b/src/System.Memory/src/System/Buffers/Text/Utf8Parser/Utf8Parser.Integer.Signed.D.cs @@ -80,12 +80,12 @@ private static bool TryParseSByteD(ReadOnlySpan text, out sbyte value, out goto FalseExit; } -FalseExit: + FalseExit: bytesConsumed = default; value = default; return false; -Done: + Done: bytesConsumed = index; value = (sbyte)(answer * sign); return true; @@ -181,12 +181,12 @@ private static bool TryParseInt16D(ReadOnlySpan text, out short value, out goto FalseExit; } -FalseExit: + FalseExit: bytesConsumed = default; value = default; return false; -Done: + Done: bytesConsumed = index; value = (short)(answer * sign); return true; @@ -324,12 +324,12 @@ private static bool TryParseInt32D(ReadOnlySpan text, out int value, out i goto FalseExit; } -FalseExit: + FalseExit: bytesConsumed = default; value = default; return false; -Done: + Done: bytesConsumed = index; value = answer * sign; return true; diff --git a/src/System.Memory/src/System/Buffers/Text/Utf8Parser/Utf8Parser.Integer.Unsigned.D.cs b/src/System.Memory/src/System/Buffers/Text/Utf8Parser/Utf8Parser.Integer.Unsigned.D.cs index 3248c7556f99..99aeceddd312 100644 --- a/src/System.Memory/src/System/Buffers/Text/Utf8Parser/Utf8Parser.Integer.Unsigned.D.cs +++ b/src/System.Memory/src/System/Buffers/Text/Utf8Parser/Utf8Parser.Integer.Unsigned.D.cs @@ -61,12 +61,12 @@ private static bool TryParseByteD(ReadOnlySpan text, out byte value, out i goto FalseExit; } -FalseExit: + FalseExit: bytesConsumed = default; value = default; return false; -Done: + Done: bytesConsumed = index; value = (byte)answer; return true; @@ -143,12 +143,12 @@ private static bool TryParseUInt16D(ReadOnlySpan text, out ushort value, o goto FalseExit; } -FalseExit: + FalseExit: bytesConsumed = default; value = default; return false; -Done: + Done: bytesConsumed = index; value = (ushort)answer; return true; @@ -265,12 +265,12 @@ private static bool TryParseUInt32D(ReadOnlySpan text, out uint value, out goto FalseExit; } -FalseExit: + FalseExit: bytesConsumed = default; value = default; return false; -Done: + Done: bytesConsumed = index; value = (uint)answer; return true; diff --git a/src/System.Memory/src/System/Buffers/Text/Utf8Parser/Utf8Parser.Integer.Unsigned.N.cs b/src/System.Memory/src/System/Buffers/Text/Utf8Parser/Utf8Parser.Integer.Unsigned.N.cs index 8f74fc8dc759..0990336af344 100644 --- a/src/System.Memory/src/System/Buffers/Text/Utf8Parser/Utf8Parser.Integer.Unsigned.N.cs +++ b/src/System.Memory/src/System/Buffers/Text/Utf8Parser/Utf8Parser.Integer.Unsigned.N.cs @@ -2,8 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using System.Diagnostics; - namespace System.Buffers.Text { // diff --git a/src/System.Memory/src/System/Buffers/Text/Utf8Parser/Utf8Parser.TimeSpan.LittleG.cs b/src/System.Memory/src/System/Buffers/Text/Utf8Parser/Utf8Parser.TimeSpan.LittleG.cs index bf21f987d037..ebf885ce9f06 100644 --- a/src/System.Memory/src/System/Buffers/Text/Utf8Parser/Utf8Parser.TimeSpan.LittleG.cs +++ b/src/System.Memory/src/System/Buffers/Text/Utf8Parser/Utf8Parser.TimeSpan.LittleG.cs @@ -2,8 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using System.Diagnostics; - namespace System.Buffers.Text { public static partial class Utf8Parser diff --git a/src/System.Memory/src/System/Memory.cs b/src/System.Memory/src/System/Memory.cs index d81caa28284c..e998455d2adb 100644 --- a/src/System.Memory/src/System/Memory.cs +++ b/src/System.Memory/src/System/Memory.cs @@ -78,7 +78,7 @@ public Memory(T[] array, int start, int length) _index = start; _length = length; } - + // Constructor for internal use only. [MethodImpl(MethodImplOptions.AggressiveInlining)] internal Memory(OwnedMemory owner, int index, int length) @@ -109,7 +109,7 @@ private Memory(object obj, int index, int length) /// Defines an implicit conversion of an array to a /// public static implicit operator Memory(T[] array) => new Memory(array); - + /// /// Defines an implicit conversion of a to a /// @@ -165,7 +165,7 @@ public Memory Slice(int start, int length) { if ((uint)start > (uint)_length || (uint)length > (uint)(_length - start)) ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.start); - + return new Memory(_object, _index + start, length); } diff --git a/src/System.Memory/src/System/MemoryExtensions.Fast.cs b/src/System.Memory/src/System/MemoryExtensions.Fast.cs index 9d08ab9d7a4a..23445c6afa0d 100644 --- a/src/System.Memory/src/System/MemoryExtensions.Fast.cs +++ b/src/System.Memory/src/System/MemoryExtensions.Fast.cs @@ -2,7 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using System.Diagnostics; using System.Runtime.CompilerServices; namespace System @@ -76,7 +75,7 @@ public static bool TryGetString(this ReadOnlyMemory readOnlyMemory, out st /// Thrown if the Length property of the new Span would exceed Int32.MaxValue. /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Span NonPortableCast(this Span source) + public static Span NonPortableCast(this Span source) where TFrom : struct where TTo : struct => Span.NonPortableCast(source); @@ -98,7 +97,7 @@ public static Span NonPortableCast(this Span source) [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ReadOnlySpan NonPortableCast(this ReadOnlySpan source) where TFrom : struct - where TTo : struct + where TTo : struct => Span.NonPortableCast(source); } } diff --git a/src/System.Memory/src/System/MemoryExtensions.Portable.cs b/src/System.Memory/src/System/MemoryExtensions.Portable.cs index 3d1e6e94fb9c..bc6dc0c0d474 100644 --- a/src/System.Memory/src/System/MemoryExtensions.Portable.cs +++ b/src/System.Memory/src/System/MemoryExtensions.Portable.cs @@ -165,7 +165,6 @@ public static ReadOnlySpan NonPortableCast(this ReadOnlySpan(Unsafe.As>(source.Pinnable), source.ByteOffset, newLength); } - internal static readonly IntPtr StringAdjustment = MeasureStringAdjustment(); private static IntPtr MeasureStringAdjustment() diff --git a/src/System.Memory/src/System/MemoryExtensions.cs b/src/System.Memory/src/System/MemoryExtensions.cs index dde616244430..5a3013eec224 100644 --- a/src/System.Memory/src/System/MemoryExtensions.cs +++ b/src/System.Memory/src/System/MemoryExtensions.cs @@ -2,7 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using System.Diagnostics; using System.Runtime.CompilerServices; namespace System @@ -21,10 +20,10 @@ public static partial class MemoryExtensions public static int IndexOf(this Span span, T value) where T : IEquatable { - if (typeof(T) == typeof(byte)) + if (typeof(T) == typeof(byte)) return SpanHelpers.IndexOf( - ref Unsafe.As(ref span.DangerousGetPinnableReference()), - Unsafe.As(ref value), + ref Unsafe.As(ref span.DangerousGetPinnableReference()), + Unsafe.As(ref value), span.Length); return SpanHelpers.IndexOf(ref span.DangerousGetPinnableReference(), value, span.Length); } @@ -38,11 +37,11 @@ ref Unsafe.As(ref span.DangerousGetPinnableReference()), public static int IndexOf(this Span span, ReadOnlySpan value) where T : IEquatable { - if (typeof(T) == typeof(byte)) + if (typeof(T) == typeof(byte)) return SpanHelpers.IndexOf( - ref Unsafe.As(ref span.DangerousGetPinnableReference()), - span.Length, - ref Unsafe.As(ref value.DangerousGetPinnableReference()), + ref Unsafe.As(ref span.DangerousGetPinnableReference()), + span.Length, + ref Unsafe.As(ref value.DangerousGetPinnableReference()), value.Length); return SpanHelpers.IndexOf(ref span.DangerousGetPinnableReference(), span.Length, ref value.DangerousGetPinnableReference(), value.Length); } @@ -108,10 +107,10 @@ ref Unsafe.As(ref second.DangerousGetPinnableReference()), public static int IndexOf(this ReadOnlySpan span, T value) where T : IEquatable { - if (typeof(T) == typeof(byte)) + if (typeof(T) == typeof(byte)) return SpanHelpers.IndexOf( - ref Unsafe.As(ref span.DangerousGetPinnableReference()), - Unsafe.As(ref value), + ref Unsafe.As(ref span.DangerousGetPinnableReference()), + Unsafe.As(ref value), span.Length); return SpanHelpers.IndexOf(ref span.DangerousGetPinnableReference(), value, span.Length); } @@ -125,11 +124,11 @@ ref Unsafe.As(ref span.DangerousGetPinnableReference()), public static int IndexOf(this ReadOnlySpan span, ReadOnlySpan value) where T : IEquatable { - if (typeof(T) == typeof(byte)) + if (typeof(T) == typeof(byte)) return SpanHelpers.IndexOf( - ref Unsafe.As(ref span.DangerousGetPinnableReference()), - span.Length, - ref Unsafe.As(ref value.DangerousGetPinnableReference()), + ref Unsafe.As(ref span.DangerousGetPinnableReference()), + span.Length, + ref Unsafe.As(ref value.DangerousGetPinnableReference()), value.Length); return SpanHelpers.IndexOf(ref span.DangerousGetPinnableReference(), span.Length, ref value.DangerousGetPinnableReference(), value.Length); } @@ -267,7 +266,7 @@ public static bool StartsWith(this Span span, ReadOnlySpan value) { int valueLength = value.Length; if (typeof(T) == typeof(byte)) - return valueLength <= span.Length && + return valueLength <= span.Length && SpanHelpers.SequenceEqual( ref Unsafe.As(ref span.DangerousGetPinnableReference()), ref Unsafe.As(ref value.DangerousGetPinnableReference()), @@ -284,7 +283,7 @@ public static bool StartsWith(this ReadOnlySpan span, ReadOnlySpan valu { int valueLength = value.Length; if (typeof(T) == typeof(byte)) - return valueLength <= span.Length && + return valueLength <= span.Length && SpanHelpers.SequenceEqual( ref Unsafe.As(ref span.DangerousGetPinnableReference()), ref Unsafe.As(ref value.DangerousGetPinnableReference()), @@ -307,10 +306,10 @@ public static bool EndsWith(this Span span, ReadOnlySpan value) ref Unsafe.As(ref Unsafe.Add(ref span.DangerousGetPinnableReference(), spanLength - valueLength)), ref Unsafe.As(ref value.DangerousGetPinnableReference()), valueLength); - return valueLength <= spanLength && + return valueLength <= spanLength && SpanHelpers.SequenceEqual( - ref Unsafe.Add(ref span.DangerousGetPinnableReference(), spanLength - valueLength), - ref value.DangerousGetPinnableReference(), + ref Unsafe.Add(ref span.DangerousGetPinnableReference(), spanLength - valueLength), + ref value.DangerousGetPinnableReference(), valueLength); } @@ -332,7 +331,7 @@ ref Unsafe.As(ref value.DangerousGetPinnableReference()), return valueLength <= spanLength && SpanHelpers.SequenceEqual( ref Unsafe.Add(ref span.DangerousGetPinnableReference(), spanLength - valueLength), - ref value.DangerousGetPinnableReference(), + ref value.DangerousGetPinnableReference(), valueLength); } diff --git a/src/System.Memory/src/System/Number/Decimal.DecCalc.cs b/src/System.Memory/src/System/Number/Decimal.DecCalc.cs index a585c4154be8..7592000372fa 100644 --- a/src/System.Memory/src/System/Number/Decimal.DecCalc.cs +++ b/src/System.Memory/src/System/Number/Decimal.DecCalc.cs @@ -2,8 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using System.Diagnostics; - // // This code is copied almost verbatim from the same-named file in CoreRT with mechanical changes to make it build outside of CoreLib. // diff --git a/src/System.Memory/src/System/Number/Number.FormatAndParse.cs b/src/System.Memory/src/System/Number/Number.FormatAndParse.cs index 5aca0f71301d..f251136ed1e2 100644 --- a/src/System.Memory/src/System/Number/Number.FormatAndParse.cs +++ b/src/System.Memory/src/System/Number/Number.FormatAndParse.cs @@ -455,7 +455,6 @@ private static unsafe double NumberToDouble(ref NumberBuffer number) val = Mul64Lossy(val, multval, ref exp); } - // round & scale down if (((int)val & (1 << 10)) != 0) { diff --git a/src/System.Memory/src/System/Number/Number.cs b/src/System.Memory/src/System/Number/Number.cs index c51cf65daa30..a30ae75750b5 100644 --- a/src/System.Memory/src/System/Number/Number.cs +++ b/src/System.Memory/src/System/Number/Number.cs @@ -2,11 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using System.Diagnostics; -using System.Text; -using System.Runtime.InteropServices; -using System.Runtime.CompilerServices; - // // This code is copied almost verbatim from the same-named file in CoreRT with mechanical changes to Span-ify it. // diff --git a/src/System.Memory/src/System/ReadOnlyMemory.cs b/src/System.Memory/src/System/ReadOnlyMemory.cs index 60af54a1be13..6a27ecf1e206 100644 --- a/src/System.Memory/src/System/ReadOnlyMemory.cs +++ b/src/System.Memory/src/System/ReadOnlyMemory.cs @@ -95,7 +95,7 @@ internal ReadOnlyMemory(object obj, int start, int length) /// Defines an implicit conversion of an array to a /// public static implicit operator ReadOnlyMemory(T[] array) => new ReadOnlyMemory(array); - + /// /// Defines an implicit conversion of a to a /// @@ -303,12 +303,12 @@ public bool Equals(ReadOnlyMemory other) /// /// Serves as the default hash function. /// - [EditorBrowsable( EditorBrowsableState.Never)] + [EditorBrowsable(EditorBrowsableState.Never)] public override int GetHashCode() { return _object != null ? CombineHashCodes(_object.GetHashCode(), _index.GetHashCode(), _length.GetHashCode()) : 0; } - + private static int CombineHashCodes(int left, int right) { return ((left << 5) + left) ^ right; diff --git a/src/System.Memory/src/System/ReadOnlySpan.cs b/src/System.Memory/src/System/ReadOnlySpan.cs index 8dae95629f23..9d74559c3c0c 100644 --- a/src/System.Memory/src/System/ReadOnlySpan.cs +++ b/src/System.Memory/src/System/ReadOnlySpan.cs @@ -172,7 +172,6 @@ public void CopyTo(Span destination) ThrowHelper.ThrowArgumentException_DestinationTooShort(); } - /// /// Copies the contents of this read-only span into destination span. If the source /// and destinations overlap, this method behaves as if the original values in diff --git a/src/System.Memory/src/System/SpanHelpers.T.cs b/src/System.Memory/src/System/SpanHelpers.T.cs index a228d1007f87..db119a89130c 100644 --- a/src/System.Memory/src/System/SpanHelpers.T.cs +++ b/src/System.Memory/src/System/SpanHelpers.T.cs @@ -23,7 +23,7 @@ public static int IndexOf(ref T searchSpace, int searchSpaceLength, ref T val int valueTailLength = valueLength - 1; int index = 0; - for (;;) + for (; ; ) { Debug.Assert(0 <= index && index <= searchSpaceLength); // Ensures no deceptive underflows in the computation of "remainingSearchSpaceLength". int remainingSearchSpaceLength = searchSpaceLength - index - valueTailLength; @@ -133,7 +133,7 @@ public static int LastIndexOf(ref T searchSpace, int searchSpaceLength, ref T int valueTailLength = valueLength - 1; int index = 0; - for (;;) + for (; ; ) { Debug.Assert(0 <= index && index <= searchSpaceLength); // Ensures no deceptive underflows in the computation of "remainingSearchSpaceLength". int remainingSearchSpaceLength = searchSpaceLength - index - valueTailLength; @@ -158,7 +158,7 @@ public static unsafe int LastIndexOf(ref T searchSpace, T value, int length) where T : IEquatable { Debug.Assert(length >= 0); - + while (length >= 8) { length -= 8; @@ -204,21 +204,21 @@ public static unsafe int LastIndexOf(ref T searchSpace, T value, int length) } return -1; -Found: // Workaround for https://github.com/dotnet/coreclr/issues/13549 + Found: // Workaround for https://github.com/dotnet/coreclr/issues/13549 return length; -Found1: + Found1: return length + 1; -Found2: + Found2: return length + 2; -Found3: + Found3: return length + 3; -Found4: + Found4: return length + 4; -Found5: + Found5: return length + 5; -Found6: + Found6: return length + 6; -Found7: + Found7: return length + 7; } diff --git a/src/System.Memory/src/System/SpanHelpers.byte.cs b/src/System.Memory/src/System/SpanHelpers.byte.cs index 04d5247444a6..54a6a34a47bd 100644 --- a/src/System.Memory/src/System/SpanHelpers.byte.cs +++ b/src/System.Memory/src/System/SpanHelpers.byte.cs @@ -26,7 +26,7 @@ public static int IndexOf(ref byte searchSpace, int searchSpaceLength, ref byte int valueTailLength = valueLength - 1; int index = 0; - for (;;) + for (; ; ) { Debug.Assert(0 <= index && index <= searchSpaceLength); // Ensures no deceptive underflows in the computation of "remainingSearchSpaceLength". int remainingSearchSpaceLength = searchSpaceLength - index - valueTailLength; @@ -195,7 +195,7 @@ public static int LastIndexOf(ref byte searchSpace, int searchSpaceLength, ref b int valueTailLength = valueLength - 1; int index = 0; - for (;;) + for (; ; ) { Debug.Assert(0 <= index && index <= searchSpaceLength); // Ensures no deceptive underflows in the computation of "remainingSearchSpaceLength". int remainingSearchSpaceLength = searchSpaceLength - index - valueTailLength; @@ -232,7 +232,7 @@ public static unsafe int LastIndexOf(ref byte searchSpace, byte value, int lengt nLength = (IntPtr)(((length & (Vector.Count - 1)) + unaligned) & (Vector.Count - 1)); } } -SequentialScan: + SequentialScan: #endif while ((byte*)nLength >= (byte*)8) { @@ -307,21 +307,21 @@ public static unsafe int LastIndexOf(ref byte searchSpace, byte value, int lengt } #endif return -1; -Found: // Workaround for https://github.com/dotnet/coreclr/issues/13549 + Found: // Workaround for https://github.com/dotnet/coreclr/issues/13549 return (int)(byte*)index; -Found1: + Found1: return (int)(byte*)(index + 1); -Found2: + Found2: return (int)(byte*)(index + 2); -Found3: + Found3: return (int)(byte*)(index + 3); -Found4: + Found4: return (int)(byte*)(index + 4); -Found5: + Found5: return (int)(byte*)(index + 5); -Found6: + Found6: return (int)(byte*)(index + 6); -Found7: + Found7: return (int)(byte*)(index + 7); } @@ -722,7 +722,7 @@ private static int LocateLastFoundByte(ulong match) { // Find the most significant byte that has its highest bit set int index = 7; - while((long)match > 0) + while ((long)match > 0) { match = match << 8; index--; diff --git a/src/System.Memory/tests/AllocationHelper.cs b/src/System.Memory/tests/AllocationHelper.cs index 69311ba0abbd..3496465d4905 100644 --- a/src/System.Memory/tests/AllocationHelper.cs +++ b/src/System.Memory/tests/AllocationHelper.cs @@ -11,14 +11,14 @@ namespace System.SpanTests /// static class AllocationHelper { - private static readonly Mutex MemoryLock = new Mutex(); - private static readonly TimeSpan WaitTimeout = TimeSpan.FromSeconds(120); + private static readonly Mutex s_memoryLock = new Mutex(); + private static readonly TimeSpan s_waitTimeout = TimeSpan.FromSeconds(120); public static bool TryAllocNative(IntPtr size, out IntPtr memory) { memory = IntPtr.Zero; - if (!MemoryLock.WaitOne(WaitTimeout)) + if (!s_memoryLock.WaitOne(s_waitTimeout)) return false; try @@ -28,7 +28,7 @@ public static bool TryAllocNative(IntPtr size, out IntPtr memory) catch (OutOfMemoryException) { memory = IntPtr.Zero; - MemoryLock.ReleaseMutex(); + s_memoryLock.ReleaseMutex(); } return memory != IntPtr.Zero; @@ -43,7 +43,7 @@ public static void ReleaseNative(ref IntPtr memory) } finally { - MemoryLock.ReleaseMutex(); + s_memoryLock.ReleaseMutex(); } } } diff --git a/src/System.Memory/tests/Base64/Base64DecoderUnitTests.cs b/src/System.Memory/tests/Base64/Base64DecoderUnitTests.cs index 2b0232f713f1..c7031c7da5f4 100644 --- a/src/System.Memory/tests/Base64/Base64DecoderUnitTests.cs +++ b/src/System.Memory/tests/Base64/Base64DecoderUnitTests.cs @@ -25,7 +25,7 @@ public void BasicDecoding() Base64TestHelper.InitalizeDecodableBytes(source, numBytes); Span decodedBytes = new byte[Base64.GetMaxDecodedFromUtf8Length(source.Length)]; - Assert.Equal(OperationStatus.Done, + Assert.Equal(OperationStatus.Done, Base64.DecodeFromUtf8(source, decodedBytes, out int consumed, out int decodedByteCount)); Assert.Equal(source.Length, consumed); Assert.Equal(decodedBytes.Length, decodedByteCount); @@ -39,7 +39,7 @@ public void DecodeEmptySpan() Span source = Span.Empty; Span decodedBytes = new byte[Base64.GetMaxDecodedFromUtf8Length(source.Length)]; - Assert.Equal(OperationStatus.Done, + Assert.Equal(OperationStatus.Done, Base64.DecodeFromUtf8(source, decodedBytes, out int consumed, out int decodedByteCount)); Assert.Equal(source.Length, consumed); Assert.Equal(decodedBytes.Length, decodedByteCount); @@ -63,7 +63,7 @@ public void BasicDecodingWithFinalBlockFalse() Span decodedBytes = new byte[Base64.GetMaxDecodedFromUtf8Length(source.Length)]; int expectedConsumed = source.Length / 4 * 4; // only consume closest multiple of four since isFinalBlock is false - Assert.Equal(OperationStatus.NeedMoreData, + Assert.Equal(OperationStatus.NeedMoreData, Base64.DecodeFromUtf8(source, decodedBytes, out int consumed, out int decodedByteCount, isFinalBlock: false)); Assert.Equal(expectedConsumed, consumed); Assert.Equal(decodedBytes.Length, decodedByteCount); @@ -152,7 +152,7 @@ public void DecodingInvalidBytes() // 123-255 byte[] invalidBytes = Base64TestHelper.InvalidBytes; Assert.Equal(byte.MaxValue + 1 - 64, invalidBytes.Length); // 192 - + for (int j = 0; j < 8; j++) { Span source = new byte[8] { 50, 50, 50, 50, 80, 80, 80, 80 }; // valid input - "2222PPPP" @@ -161,14 +161,15 @@ public void DecodingInvalidBytes() for (int i = 0; i < invalidBytes.Length; i++) { // Don't test padding (byte 61 i.e. '='), which is tested in DecodingInvalidBytesPadding - if (invalidBytes[i] == Base64TestHelper.s_encodingPad) continue; + if (invalidBytes[i] == Base64TestHelper.s_encodingPad) + continue; // replace one byte with an invalid input source[j] = invalidBytes[i]; Assert.Equal(OperationStatus.InvalidData, Base64.DecodeFromUtf8(source, decodedBytes, out int consumed, out int decodedByteCount)); - + if (j < 4) { Assert.Equal(0, consumed); @@ -303,7 +304,7 @@ public void DecodingOutputTooSmall() source[11] = Base64TestHelper.s_encodingPad; Span decodedBytes = new byte[6]; - Assert.Equal(OperationStatus.DestinationTooSmall, + Assert.Equal(OperationStatus.DestinationTooSmall, Base64.DecodeFromUtf8(source, decodedBytes, out int consumed, out int written)); int expectedConsumed = 8; Assert.Equal(expectedConsumed, consumed); @@ -317,7 +318,7 @@ public void DecodingOutputTooSmall() source[11] = Base64TestHelper.s_encodingPad; Span decodedBytes = new byte[7]; - Assert.Equal(OperationStatus.DestinationTooSmall, + Assert.Equal(OperationStatus.DestinationTooSmall, Base64.DecodeFromUtf8(source, decodedBytes, out int consumed, out int written)); int expectedConsumed = 8; Assert.Equal(expectedConsumed, consumed); @@ -336,10 +337,10 @@ public void DecodingOutputTooSmallRetry() int requiredSize = Base64.GetMaxDecodedFromUtf8Length(source.Length); Span decodedBytes = new byte[outputSize]; - Assert.Equal(OperationStatus.DestinationTooSmall, + Assert.Equal(OperationStatus.DestinationTooSmall, Base64.DecodeFromUtf8(source, decodedBytes, out int consumed, out int decodedByteCount)); int expectedConsumed = decodedBytes.Length / 3 * 4; - Assert.Equal(expectedConsumed, consumed); + Assert.Equal(expectedConsumed, consumed); Assert.Equal(decodedBytes.Length, decodedByteCount); Assert.True(Base64TestHelper.VerifyDecodingCorrectness(expectedConsumed, decodedBytes.Length, source, decodedBytes)); @@ -381,7 +382,6 @@ public void GetMaxDecodedLength() Assert.Throws(() => Base64.GetMaxDecodedFromUtf8Length(int.MinValue)); } - [Fact] public void DecodeInPlace() { @@ -430,7 +430,7 @@ public void EncodeAndDecodeInPlace() public void DecodeInPlaceInvalidBytes() { byte[] invalidBytes = Base64TestHelper.InvalidBytes; - + for (int j = 0; j < 8; j++) { for (int i = 0; i < invalidBytes.Length; i++) @@ -438,14 +438,15 @@ public void DecodeInPlaceInvalidBytes() Span buffer = new byte[8] { 50, 50, 50, 50, 80, 80, 80, 80 }; // valid input - "2222PPPP" // Don't test padding (byte 61 i.e. '='), which is tested in DecodeInPlaceInvalidBytesPadding - if (invalidBytes[i] == Base64TestHelper.s_encodingPad) continue; + if (invalidBytes[i] == Base64TestHelper.s_encodingPad) + continue; // replace one byte with an invalid input buffer[j] = invalidBytes[i]; string sourceString = Encoding.ASCII.GetString(buffer.Slice(0, 4).ToArray()); Assert.Equal(OperationStatus.InvalidData, Base64.DecodeFromUtf8InPlace(buffer, out int bytesWritten)); - + if (j < 4) { Assert.Equal(0, bytesWritten); @@ -524,7 +525,7 @@ public void DecodeInPlaceInvalidBytesPadding() Span expectedBytes = Convert.FromBase64String(sourceString); Assert.True(expectedBytes.SequenceEqual(buffer.Slice(0, bytesWritten))); } - + { Span buffer = new byte[] { 50, 50, 50, 50, 80, 80, 80, 80 }; buffer[7] = Base64TestHelper.s_encodingPad; // valid input - "2222PPP=" diff --git a/src/System.Memory/tests/Base64/Base64EncoderUnitTests.cs b/src/System.Memory/tests/Base64/Base64EncoderUnitTests.cs index 26fe6a9cb431..f43481a27a60 100644 --- a/src/System.Memory/tests/Base64/Base64EncoderUnitTests.cs +++ b/src/System.Memory/tests/Base64/Base64EncoderUnitTests.cs @@ -65,7 +65,7 @@ public void EncodeEmptySpan() { Span source = Span.Empty; Span encodedBytes = new byte[Base64.GetMaxEncodedToUtf8Length(source.Length)]; - + Assert.Equal(OperationStatus.Done, Base64.EncodeToUtf8(source, encodedBytes, out int consumed, out int encodedBytesCount)); Assert.Equal(source.Length, consumed); Assert.Equal(encodedBytes.Length, encodedBytesCount); @@ -80,7 +80,7 @@ public void EncodeTooLargeSpan() // CLR default limit of 2 gigabytes (GB). try { - // 1610612734, larger than MaximumEncodeLength, requires output buffer of size 2147483648 (which is > int.MaxValue) + // 1610612734, larger than MaximumEncodeLength, requires output buffer of size 2147483648 (which is > int.MaxValue) Span source = new byte[(int.MaxValue >> 2) * 3 + 1]; Span encodedBytes = new byte[2000000000]; Assert.Equal(OperationStatus.DestinationTooSmall, Base64.EncodeToUtf8(source, encodedBytes, out int consumed, out int encodedBytesCount)); @@ -250,7 +250,7 @@ public void EncodeInPlace() [Fact] public void EncodeInPlaceOutputTooSmall() { - byte[] testBytes = {1, 2, 3}; + byte[] testBytes = { 1, 2, 3 }; for (int numberOfBytesToTest = 1; numberOfBytesToTest <= testBytes.Length; numberOfBytesToTest++) { @@ -262,7 +262,7 @@ public void EncodeInPlaceOutputTooSmall() [Fact] public void EncodeInPlaceDataLengthTooLarge() { - byte[] testBytes = {1, 2, 3}; + byte[] testBytes = { 1, 2, 3 }; Assert.Equal(OperationStatus.DestinationTooSmall, Base64.EncodeToUtf8InPlace(testBytes, testBytes.Length + 1, out int bytesWritten)); Assert.Equal(0, bytesWritten); } diff --git a/src/System.Memory/tests/Base64/Base64TestHelper.cs b/src/System.Memory/tests/Base64/Base64TestHelper.cs index 1026a97683eb..1aa827167450 100644 --- a/src/System.Memory/tests/Base64/Base64TestHelper.cs +++ b/src/System.Memory/tests/Base64/Base64TestHelper.cs @@ -57,7 +57,7 @@ public static byte[] InvalidBytes // Workaroudn for indices.Cast().ToArray() since it throws // InvalidCastException: Unable to cast object of type 'System.Int32' to type 'System.Byte' byte[] bytes = new byte[indices.Length]; - for(int i = 0; i < indices.Length; i++) + for (int i = 0; i < indices.Length; i++) { bytes[i] = (byte)indices[i]; } diff --git a/src/System.Memory/tests/Binary/BinaryReaderUnitTests.cs b/src/System.Memory/tests/Binary/BinaryReaderUnitTests.cs index 5b776244dec2..cc078c1948df 100644 --- a/src/System.Memory/tests/Binary/BinaryReaderUnitTests.cs +++ b/src/System.Memory/tests/Binary/BinaryReaderUnitTests.cs @@ -20,7 +20,8 @@ public void SpanRead() ulong value = 0x8877665544332211; // [11 22 33 44 55 66 77 88] Span span; - unsafe { + unsafe + { span = new Span(&value, 8); } @@ -88,7 +89,8 @@ public void ReadOnlySpanRead() ulong value = 0x8877665544332211; // [11 22 33 44 55 66 77 88] ReadOnlySpan span; - unsafe { + unsafe + { span = new ReadOnlySpan(&value, 8); } @@ -226,18 +228,18 @@ public void SpanWriteAndReadBigEndianHeterogeneousStruct() Span spanBE = new byte[Unsafe.SizeOf()]; - WriteInt16BigEndian(spanBE, testStruct.S0); - WriteInt32BigEndian(spanBE.Slice(2), testStruct.I0); - WriteInt64BigEndian(spanBE.Slice(6), testStruct.L0); - WriteUInt16BigEndian(spanBE.Slice(14), testStruct.US0); - WriteUInt32BigEndian(spanBE.Slice(16), testStruct.UI0); - WriteUInt64BigEndian(spanBE.Slice(20), testStruct.UL0); - WriteInt16BigEndian(spanBE.Slice(28), testStruct.S1); - WriteInt32BigEndian(spanBE.Slice(30), testStruct.I1); - WriteInt64BigEndian(spanBE.Slice(34), testStruct.L1); - WriteUInt16BigEndian(spanBE.Slice(42), testStruct.US1); - WriteUInt32BigEndian(spanBE.Slice(44), testStruct.UI1); - WriteUInt64BigEndian(spanBE.Slice(48), testStruct.UL1); + WriteInt16BigEndian(spanBE, s_testStruct.S0); + WriteInt32BigEndian(spanBE.Slice(2), s_testStruct.I0); + WriteInt64BigEndian(spanBE.Slice(6), s_testStruct.L0); + WriteUInt16BigEndian(spanBE.Slice(14), s_testStruct.US0); + WriteUInt32BigEndian(spanBE.Slice(16), s_testStruct.UI0); + WriteUInt64BigEndian(spanBE.Slice(20), s_testStruct.UL0); + WriteInt16BigEndian(spanBE.Slice(28), s_testStruct.S1); + WriteInt32BigEndian(spanBE.Slice(30), s_testStruct.I1); + WriteInt64BigEndian(spanBE.Slice(34), s_testStruct.L1); + WriteUInt16BigEndian(spanBE.Slice(42), s_testStruct.US1); + WriteUInt32BigEndian(spanBE.Slice(44), s_testStruct.UI1); + WriteUInt64BigEndian(spanBE.Slice(48), s_testStruct.UL1); ReadOnlySpan readOnlySpanBE = new ReadOnlySpan(spanBE.ToArray()); @@ -273,8 +275,8 @@ public void SpanWriteAndReadBigEndianHeterogeneousStruct() UL1 = ReadUInt64BigEndian(readOnlySpanBE.Slice(48)) }; - Assert.Equal(testStruct, readStruct); - Assert.Equal(testStruct, readStructFromReadOnlySpan); + Assert.Equal(s_testStruct, readStruct); + Assert.Equal(s_testStruct, readStructFromReadOnlySpan); } [Fact] @@ -284,18 +286,18 @@ public void SpanWriteAndReadLittleEndianHeterogeneousStruct() Span spanLE = new byte[Unsafe.SizeOf()]; - WriteInt16LittleEndian(spanLE, testStruct.S0); - WriteInt32LittleEndian(spanLE.Slice(2), testStruct.I0); - WriteInt64LittleEndian(spanLE.Slice(6), testStruct.L0); - WriteUInt16LittleEndian(spanLE.Slice(14), testStruct.US0); - WriteUInt32LittleEndian(spanLE.Slice(16), testStruct.UI0); - WriteUInt64LittleEndian(spanLE.Slice(20), testStruct.UL0); - WriteInt16LittleEndian(spanLE.Slice(28), testStruct.S1); - WriteInt32LittleEndian(spanLE.Slice(30), testStruct.I1); - WriteInt64LittleEndian(spanLE.Slice(34), testStruct.L1); - WriteUInt16LittleEndian(spanLE.Slice(42), testStruct.US1); - WriteUInt32LittleEndian(spanLE.Slice(44), testStruct.UI1); - WriteUInt64LittleEndian(spanLE.Slice(48), testStruct.UL1); + WriteInt16LittleEndian(spanLE, s_testStruct.S0); + WriteInt32LittleEndian(spanLE.Slice(2), s_testStruct.I0); + WriteInt64LittleEndian(spanLE.Slice(6), s_testStruct.L0); + WriteUInt16LittleEndian(spanLE.Slice(14), s_testStruct.US0); + WriteUInt32LittleEndian(spanLE.Slice(16), s_testStruct.UI0); + WriteUInt64LittleEndian(spanLE.Slice(20), s_testStruct.UL0); + WriteInt16LittleEndian(spanLE.Slice(28), s_testStruct.S1); + WriteInt32LittleEndian(spanLE.Slice(30), s_testStruct.I1); + WriteInt64LittleEndian(spanLE.Slice(34), s_testStruct.L1); + WriteUInt16LittleEndian(spanLE.Slice(42), s_testStruct.US1); + WriteUInt32LittleEndian(spanLE.Slice(44), s_testStruct.UI1); + WriteUInt64LittleEndian(spanLE.Slice(48), s_testStruct.UL1); ReadOnlySpan readOnlySpanLE = new ReadOnlySpan(spanLE.ToArray()); @@ -331,8 +333,8 @@ public void SpanWriteAndReadLittleEndianHeterogeneousStruct() UL1 = ReadUInt64LittleEndian(readOnlySpanLE.Slice(48)) }; - Assert.Equal(testStruct, readStruct); - Assert.Equal(testStruct, readStructFromReadOnlySpan); + Assert.Equal(s_testStruct, readStruct); + Assert.Equal(s_testStruct, readStructFromReadOnlySpan); } [Fact] @@ -447,7 +449,7 @@ public void ReadingStructFieldByFieldOrReadAndReverseEndianness() Assert.Equal(testExplicitStruct, readStructFieldByFieldFromReadOnlySpan); } - private static TestStruct testStruct = new TestStruct + private static TestStruct s_testStruct = new TestStruct { S0 = short.MaxValue, I0 = int.MaxValue, diff --git a/src/System.Memory/tests/Binary/BinaryWriterUnitTests.cs b/src/System.Memory/tests/Binary/BinaryWriterUnitTests.cs index 7b2c8a06c29f..6d02d35eb11a 100644 --- a/src/System.Memory/tests/Binary/BinaryWriterUnitTests.cs +++ b/src/System.Memory/tests/Binary/BinaryWriterUnitTests.cs @@ -270,9 +270,9 @@ public void SpanWriteFail() uint uintValue = 1; long longValue = 1; ulong ulongValue = 1; - + Span span = new byte[1]; - + WriteMachineEndian(span, ref byteValue); byte read = ReadMachineEndian(span); Assert.Equal(byteValue, read); @@ -305,7 +305,7 @@ public void SpanWriteFail() TestHelpers.AssertThrows(span, (_span) => WriteMachineEndian(_span, ref ulongValue)); Assert.False(TryWriteMachineEndian(span, ref ulongValue)); - var structValue = new TestHelpers.TestValueTypeWithReference{ I = 1, S = "1" }; + var structValue = new TestHelpers.TestValueTypeWithReference { I = 1, S = "1" }; TestHelpers.AssertThrows(span, (_span) => WriteMachineEndian(_span, ref structValue)); TestHelpers.AssertThrows(span, (_span) => TryWriteMachineEndian(_span, ref structValue)); } diff --git a/src/System.Memory/tests/Memory/CopyTo.cs b/src/System.Memory/tests/Memory/CopyTo.cs index 5bfbf93a7afd..8305710d3767 100644 --- a/src/System.Memory/tests/Memory/CopyTo.cs +++ b/src/System.Memory/tests/Memory/CopyTo.cs @@ -92,7 +92,7 @@ public static void CopyToShorter() int[] dst = { 99, 100 }; Memory srcMemory = src; - Assert.Throws( () => srcMemory.CopyTo(dst) ); + Assert.Throws(() => srcMemory.CopyTo(dst)); int[] expected = { 99, 100 }; Assert.Equal(expected, dst); // CopyTo() checks for sufficient space before doing any copying. } @@ -177,7 +177,7 @@ public static void CopyToShorterArray() int[] src = { 1, 2, 3 }; Memory dst = new int[2] { 99, 100 }; - Assert.Throws( () => src.CopyTo(dst) ); + Assert.Throws(() => src.CopyTo(dst)); int[] expected = { 99, 100 }; Assert.Equal(expected, dst.ToArray()); // CopyTo() checks for sufficient space before doing any copying. } diff --git a/src/System.Memory/tests/Memory/CustomMemoryForTest.cs b/src/System.Memory/tests/Memory/CustomMemoryForTest.cs index ae23459eac65..04f6c2d30db5 100644 --- a/src/System.Memory/tests/Memory/CustomMemoryForTest.cs +++ b/src/System.Memory/tests/Memory/CustomMemoryForTest.cs @@ -2,7 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. - using System.Buffers; using System.Runtime.InteropServices; using System.Threading; @@ -68,7 +67,7 @@ protected override void Dispose(bool disposing) } _disposed = true; - + } public override void Retain() diff --git a/src/System.Memory/tests/Memory/OwnedMemory.cs b/src/System.Memory/tests/Memory/OwnedMemory.cs index 36d3a15520e0..42c409fde908 100644 --- a/src/System.Memory/tests/Memory/OwnedMemory.cs +++ b/src/System.Memory/tests/Memory/OwnedMemory.cs @@ -2,7 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. - using System.Buffers; using Xunit; @@ -118,6 +117,6 @@ public static void DisposeOwnedMemoryAfterRetainAndRelease() Assert.True(owner.IsDisposed); } } - + } diff --git a/src/System.Memory/tests/Memory/ToArray.cs b/src/System.Memory/tests/Memory/ToArray.cs index bac27ed72d61..23d70b28c53c 100644 --- a/src/System.Memory/tests/Memory/ToArray.cs +++ b/src/System.Memory/tests/Memory/ToArray.cs @@ -24,7 +24,7 @@ public static void ToArrayWithIndex() int[] a = { 91, 92, 93, 94, 95 }; var memory = new Memory(a); int[] copy = memory.Slice(2).ToArray(); - + Assert.Equal(new int[] { 93, 94, 95 }, copy); } diff --git a/src/System.Memory/tests/ParsersAndFormatters/Formatter/FormatterTestData.cs b/src/System.Memory/tests/ParsersAndFormatters/Formatter/FormatterTestData.cs index 7facd90e8a48..ac777162282c 100644 --- a/src/System.Memory/tests/ParsersAndFormatters/Formatter/FormatterTestData.cs +++ b/src/System.Memory/tests/ParsersAndFormatters/Formatter/FormatterTestData.cs @@ -42,10 +42,10 @@ public sealed override string ToString() // Take good care of this method: it affects Xunit output and makes a lot of difference in how annoying test investigations are. // - string formatString = (FormatSymbol == default) ? - "default" : - FormatSymbol + ((Precision == StandardFormat.NoPrecision) ? - string.Empty : + string formatString = (FormatSymbol == default) ? + "default" : + FormatSymbol + ((Precision == StandardFormat.NoPrecision) ? + string.Empty : Precision.ToString()); string bufferLengthString; @@ -55,7 +55,7 @@ public sealed override string ToString() } else if (PassedInBufferLength < ExpectedOutput.Length) { - bufferLengthString = $", Buffer Length = {PassedInBufferLength} bytes (too short)"; + bufferLengthString = $", Buffer Length = {PassedInBufferLength} bytes (too short)"; } else { diff --git a/src/System.Memory/tests/ParsersAndFormatters/Formatter/TestData.Formatter.cs b/src/System.Memory/tests/ParsersAndFormatters/Formatter/TestData.Formatter.cs index 62887900a0d1..36a36db89e11 100644 --- a/src/System.Memory/tests/ParsersAndFormatters/Formatter/TestData.Formatter.cs +++ b/src/System.Memory/tests/ParsersAndFormatters/Formatter/TestData.Formatter.cs @@ -46,7 +46,7 @@ public static IEnumerable TypesThatCanBeFormatted public static IEnumerable UInt16FormatterTheoryData => UInt16FormatterTestData.Select(td => new object[] { td }); public static IEnumerable Int32FormatterTheoryData => Int32FormatterTestData.Select(td => new object[] { td }); public static IEnumerable UInt32FormatterTheoryData => UInt32FormatterTestData.Select(td => new object[] { td }); - public static IEnumerable Int64FormatterTheoryData => Int64FormatterTestData.Select(td => new object[] { td }); + public static IEnumerable Int64FormatterTheoryData => Int64FormatterTestData.Select(td => new object[] { td }); public static IEnumerable UInt64FormatterTheoryData => UInt64FormatterTestData.Select(td => new object[] { td }); public static IEnumerable DecimalFormatterTheoryData => DecimalFormatterTestData.Select(td => new object[] { td }); public static IEnumerable DoubleFormatterTheoryData => DoubleFormatterTestData.Select(td => new object[] { td }); @@ -97,7 +97,7 @@ private static IEnumerable> CreateFormatterTestData(IEnu } else { - foreach (byte precision in TestData.Precisions) + foreach (byte precision in TestData.s_precisions) { string expectedOutput = ComputeExpectedOutput(value, format.Symbol, precision); yield return new FormatterTestData(value, format, precision, expectedOutput); diff --git a/src/System.Memory/tests/ParsersAndFormatters/Parser/ParserTestData.cs b/src/System.Memory/tests/ParsersAndFormatters/Parser/ParserTestData.cs index 697784956083..e6008305c9ed 100644 --- a/src/System.Memory/tests/ParsersAndFormatters/Parser/ParserTestData.cs +++ b/src/System.Memory/tests/ParsersAndFormatters/Parser/ParserTestData.cs @@ -36,8 +36,8 @@ public sealed override string ToString() // Take good care of this method: it affects Xunit output and makes a lot of difference in how annoying test investigations are. // - string formatString = (FormatSymbol == default) ? - "default" : + string formatString = (FormatSymbol == default) ? + "default" : FormatSymbol.ToString(); return $"[Parse{typeof(T).Name} '{Text}',{formatString} to {(ExpectedSuccess ? ExpectedValue.DisplayString() : "(should-not-parse)")})]"; diff --git a/src/System.Memory/tests/ParsersAndFormatters/Parser/TestData.Parser.Date.cs b/src/System.Memory/tests/ParsersAndFormatters/Parser/TestData.Parser.Date.cs index c4dad80bd1af..36eb81f6f197 100644 --- a/src/System.Memory/tests/ParsersAndFormatters/Parser/TestData.Parser.Date.cs +++ b/src/System.Memory/tests/ParsersAndFormatters/Parser/TestData.Parser.Date.cs @@ -125,7 +125,7 @@ public static IEnumerable> DateTimeOffsetParserTe } catch (ArgumentOutOfRangeException) { - throw new Exception($"Failed on converting {expectedDto.DateTime} to local time. This is probably a piece of data that fails only in certain time zones. Time zone on this machine is {TimeZoneInfo.Local}"); + throw new Exception($"Failed on converting {expectedDto.DateTime} to local time. This is probably a piece of data that fails only in certain time zones. Time zone on this machine is {TimeZoneInfo.Local}"); } } else diff --git a/src/System.Memory/tests/ParsersAndFormatters/Parser/TestData.Parser.DecimalsAndFloats.cs b/src/System.Memory/tests/ParsersAndFormatters/Parser/TestData.Parser.DecimalsAndFloats.cs index ec0d5b5c545f..9050d90c052f 100644 --- a/src/System.Memory/tests/ParsersAndFormatters/Parser/TestData.Parser.DecimalsAndFloats.cs +++ b/src/System.Memory/tests/ParsersAndFormatters/Parser/TestData.Parser.DecimalsAndFloats.cs @@ -23,7 +23,7 @@ public static IEnumerable> DecimalParserTestData continue; MutableDecimal d = ftd.Value.ToMutableDecimal(); - if (d.High == 0 && d.Mid == 0 && d.Low == 0 && d.IsNegative) + if (d.High == 0 && d.Mid == 0 && d.Low == 0 && d.IsNegative) continue; // -0 is not roundtrippable foreach (ParserTestData testData in new FormatterTestData[] { ftd }.ToParserTheoryDataCollection()) diff --git a/src/System.Memory/tests/ParsersAndFormatters/Parser/TestData.Parser.TimeSpan.cs b/src/System.Memory/tests/ParsersAndFormatters/Parser/TestData.Parser.TimeSpan.cs index 46b82a93676a..07b5d015f1c7 100644 --- a/src/System.Memory/tests/ParsersAndFormatters/Parser/TestData.Parser.TimeSpan.cs +++ b/src/System.Memory/tests/ParsersAndFormatters/Parser/TestData.Parser.TimeSpan.cs @@ -184,30 +184,30 @@ private static IEnumerable TimeSpanParserCTestData { get { - yield return "1"; - yield return "1.9999999"; - yield return "4294967295"; - yield return "1:2"; - yield return "1:2.9999999"; - yield return "1:4294967295"; + yield return "1"; + yield return "1.9999999"; + yield return "4294967295"; + yield return "1:2"; + yield return "1:2.9999999"; + yield return "1:4294967295"; yield return "1:2:3"; yield return "1.2:3"; yield return "1.2:3:4"; - yield return "1:2:3.9999999"; - yield return "1:2:3.$$$$$$$"; - yield return "1:2:4294967295"; - yield return "1:2:4294967295.9999999"; - yield return "1:2:3:4"; - yield return "1:2:3:4.9999999"; + yield return "1:2:3.9999999"; + yield return "1:2:3.$$$$$$$"; + yield return "1:2:4294967295"; + yield return "1:2:4294967295.9999999"; + yield return "1:2:3:4"; + yield return "1:2:3:4.9999999"; yield return "1:2:3:4.$$$$$$$"; - yield return "1:2:3:4294967295"; + yield return "1:2:3:4294967295"; yield return "1:2:3:4294967295.9999999"; yield return "1.2:3:4.9999999"; yield return "1.2:3:4.$$$$$$$"; yield return "1.2:3:4294967295"; yield return "1.2:3:4294967295.9999999"; - yield return "1.2:3:4:5"; - yield return "1.2:3:4:5.9999999"; + yield return "1.2:3:4:5"; + yield return "1.2:3:4:5.9999999"; yield return "1.2:3:4.9999999:"; yield return "1.2:3:4.9999999."; diff --git a/src/System.Memory/tests/ParsersAndFormatters/PseudoDateTime.cs b/src/System.Memory/tests/ParsersAndFormatters/PseudoDateTime.cs index 4b099248874d..930a86c2dddb 100644 --- a/src/System.Memory/tests/ParsersAndFormatters/PseudoDateTime.cs +++ b/src/System.Memory/tests/ParsersAndFormatters/PseudoDateTime.cs @@ -84,7 +84,7 @@ public string RFormatString if (OffsetNegative) offset = -offset; DateTimeOffset dto = new DateTimeOffset(year: Year, month: Month, day: Day, hour: Hour, minute: Minute, second: Second, offset: offset); - dayAbbreviation = s_DayAbbreviations[(int)(dto.DayOfWeek)]; + dayAbbreviation = s_dayAbbreviations[(int)(dto.DayOfWeek)]; } else { @@ -95,7 +95,7 @@ public string RFormatString string monthAbbrevation; if (Month >= 1 && Month <= 12) { - monthAbbrevation = s_MonthAbbreviations[Month - 1]; + monthAbbrevation = s_monthAbbreviations[Month - 1]; } else { @@ -124,7 +124,7 @@ public string OFormatStringNoOffset } } - public string OFormatStringZ => (OffsetHours != 0 || OffsetMinutes != 0)? null : OFormatStringNoOffset + "Z"; + public string OFormatStringZ => (OffsetHours != 0 || OffsetMinutes != 0) ? null : OFormatStringNoOffset + "Z"; public string OFormatStringOffset { get @@ -148,7 +148,7 @@ public string OFormatStringOffset public int OffsetMinutes { get; } public bool ExpectSuccess { get; } - private static readonly string[] s_DayAbbreviations = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" }; - private static readonly string[] s_MonthAbbreviations = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" }; + private static readonly string[] s_dayAbbreviations = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" }; + private static readonly string[] s_monthAbbreviations = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" }; } } diff --git a/src/System.Memory/tests/ParsersAndFormatters/TestData.cs b/src/System.Memory/tests/ParsersAndFormatters/TestData.cs index 357a3021cbf5..db125c47c1dd 100644 --- a/src/System.Memory/tests/ParsersAndFormatters/TestData.cs +++ b/src/System.Memory/tests/ParsersAndFormatters/TestData.cs @@ -12,7 +12,7 @@ namespace System.Buffers.Text.Tests // internal static partial class TestData { - public static readonly IEnumerable Precisions = new byte[] { StandardFormat.NoPrecision, 0, 1, 3, 10, StandardFormat.MaxPrecision }; + public static readonly IEnumerable s_precisions = new byte[] { StandardFormat.NoPrecision, 0, 1, 3, 10, StandardFormat.MaxPrecision }; public static IEnumerable IntegerTypesTheoryData => IntegerTypes.Select(t => new object[] { t }); diff --git a/src/System.Memory/tests/ParsersAndFormatters/TestUtils.cs b/src/System.Memory/tests/ParsersAndFormatters/TestUtils.cs index eb4119d1ae46..8d95c619fa7d 100644 --- a/src/System.Memory/tests/ParsersAndFormatters/TestUtils.cs +++ b/src/System.Memory/tests/ParsersAndFormatters/TestUtils.cs @@ -18,7 +18,7 @@ internal static class TestUtils public static MutableDecimal ToMutableDecimal(this decimal d) { int[] bits = decimal.GetBits(d); - return new MutableDecimal() { High = (uint)bits[0], Low = (uint)bits[1], Mid = (uint)bits[2], Flags = (uint)bits[3] }; + return new MutableDecimal() { High = (uint)bits[0], Low = (uint)bits[1], Mid = (uint)bits[2], Flags = (uint)bits[3] }; } public static decimal ToDecimal(this MutableDecimal md) diff --git a/src/System.Memory/tests/Performance/Perf.Base64EncodeDecode.cs b/src/System.Memory/tests/Performance/Perf.Base64EncodeDecode.cs index 97c5c73a0b91..201bd119426e 100644 --- a/src/System.Memory/tests/Performance/Perf.Base64EncodeDecode.cs +++ b/src/System.Memory/tests/Performance/Perf.Base64EncodeDecode.cs @@ -3,7 +3,6 @@ // See the LICENSE file in the project root for more information. using Microsoft.Xunit.Performance; -using System.Text; using Xunit; namespace System.Buffers.Text.Tests @@ -23,8 +22,10 @@ private static void Base64Encode(int numberOfBytes) Base64TestHelper.InitalizeBytes(source); Span destination = new byte[Base64.GetMaxEncodedToUtf8Length(numberOfBytes)]; - foreach (var iteration in Benchmark.Iterations) { - using (iteration.StartMeasurement()) { + foreach (var iteration in Benchmark.Iterations) + { + using (iteration.StartMeasurement()) + { for (int i = 0; i < Benchmark.InnerIterationCount; i++) Base64.EncodeToUtf8(source, destination, out int consumed, out int written); } @@ -46,8 +47,10 @@ private static void Base64EncodeDestinationTooSmall(int numberOfBytes) Base64TestHelper.InitalizeBytes(source); Span destination = new byte[Base64.GetMaxEncodedToUtf8Length(numberOfBytes) - 1]; - foreach (var iteration in Benchmark.Iterations) { - using (iteration.StartMeasurement()) { + foreach (var iteration in Benchmark.Iterations) + { + using (iteration.StartMeasurement()) + { for (int i = 0; i < Benchmark.InnerIterationCount; i++) Base64.EncodeToUtf8(source, destination, out int consumed, out int written); } @@ -65,8 +68,10 @@ private static void Base64EncodeBaseline(int numberOfBytes) Base64TestHelper.InitalizeBytes(source.AsSpan()); var destination = new char[Base64.GetMaxEncodedToUtf8Length(numberOfBytes)]; - foreach (var iteration in Benchmark.Iterations) { - using (iteration.StartMeasurement()) { + foreach (var iteration in Benchmark.Iterations) + { + using (iteration.StartMeasurement()) + { for (int i = 0; i < Benchmark.InnerIterationCount; i++) Convert.ToBase64CharArray(source, 0, source.Length, destination, 0); } @@ -85,8 +90,10 @@ private static void Base64Decode(int numberOfBytes) Span encoded = new byte[Base64.GetMaxEncodedToUtf8Length(numberOfBytes)]; Base64.EncodeToUtf8(source, encoded, out _, out _); - foreach (var iteration in Benchmark.Iterations) { - using (iteration.StartMeasurement()) { + foreach (var iteration in Benchmark.Iterations) + { + using (iteration.StartMeasurement()) + { for (int i = 0; i < Benchmark.InnerIterationCount; i++) Base64.DecodeFromUtf8(encoded, source, out int bytesConsumed, out int bytesWritten); } @@ -111,8 +118,10 @@ private static void Base64DecodeDetinationTooSmall(int numberOfBytes) source = source.Slice(0, source.Length - 1); - foreach (var iteration in Benchmark.Iterations) { - using (iteration.StartMeasurement()) { + foreach (var iteration in Benchmark.Iterations) + { + using (iteration.StartMeasurement()) + { for (int i = 0; i < Benchmark.InnerIterationCount; i++) Base64.DecodeFromUtf8(encoded, source, out int bytesConsumed, out int bytesWritten); } @@ -130,8 +139,10 @@ private static void Base64DecodeBaseline(int numberOfBytes) Base64TestHelper.InitalizeBytes(source); ReadOnlySpan encoded = Convert.ToBase64String(source.ToArray()).ToCharArray(); - foreach (var iteration in Benchmark.Iterations) { - using (iteration.StartMeasurement()) { + foreach (var iteration in Benchmark.Iterations) + { + using (iteration.StartMeasurement()) + { for (int i = 0; i < Benchmark.InnerIterationCount; i++) Convert.TryFromBase64Chars(encoded, source, out int bytesWritten); } @@ -208,7 +219,7 @@ private static void Base64DecodeInPlace(int numberOfBytes) int length = Base64.GetMaxEncodedToUtf8Length(numberOfBytes); Span encodedSpan = new byte[length]; Base64.EncodeToUtf8(source, encodedSpan, out _, out _); - + Span backupSpan = encodedSpan.ToArray(); int bytesWritten = 0; diff --git a/src/System.Memory/tests/Performance/Perf.MemorySlice.cs b/src/System.Memory/tests/Performance/Perf.MemorySlice.cs index f8f3aa2f3fe6..0d28fcb7f1d3 100644 --- a/src/System.Memory/tests/Performance/Perf.MemorySlice.cs +++ b/src/System.Memory/tests/Performance/Perf.MemorySlice.cs @@ -10,7 +10,7 @@ namespace System.Memory.Tests public class MemorySlice { private const int InnerCount = 1000; - volatile static int volatileInt = 0; + volatile static int s_volatileInt = 0; [Benchmark(InnerIterationCount = InnerCount)] [InlineData(1000)] @@ -34,7 +34,7 @@ private static void Memory_Byte_SliceThenGetSpan(int numberOfBytes) } } } - volatileInt = localInt; + s_volatileInt = localInt; } } @@ -60,7 +60,7 @@ private static void Memory_Byte_GetSpanThenSlice(int numberOfBytes) } } } - volatileInt = localInt; + s_volatileInt = localInt; } } @@ -87,7 +87,7 @@ private static void ReadOnlyMemory_Byte_GetSpanThenSlice(int numberOfBytes) } } } - volatileInt = localInt; + s_volatileInt = localInt; } } @@ -114,7 +114,7 @@ private static void ReadOnlyMemory_Char_GetSpanThenSlice(int numberOfChars) } } } - volatileInt = localInt; + s_volatileInt = localInt; } } @@ -136,7 +136,7 @@ public static void ReadOnlyMemory_Byte_TryGetArray() } } - volatileInt = result.Count; + s_volatileInt = result.Count; } [Benchmark(InnerIterationCount = InnerCount)] @@ -157,7 +157,7 @@ public static void ReadOnlyMemory_Char_TryGetArray() } } - volatileInt = result.Count; + s_volatileInt = result.Count; } } } diff --git a/src/System.Memory/tests/Performance/Perf.Span.BinaryReadAndWrite.cs b/src/System.Memory/tests/Performance/Perf.Span.BinaryReadAndWrite.cs index dbcdc998fb1f..8c561f961db8 100644 --- a/src/System.Memory/tests/Performance/Perf.Span.BinaryReadAndWrite.cs +++ b/src/System.Memory/tests/Performance/Perf.Span.BinaryReadAndWrite.cs @@ -7,7 +7,6 @@ using System.Net; using static System.Buffers.Binary.BinaryPrimitives; -using static System.TestHelpers; namespace System.Buffers.Binary.Tests { @@ -47,7 +46,7 @@ private static void ReadStructAndReverseBE() } } - Assert.Equal(TestHelpers.testExplicitStruct, readStruct); + Assert.Equal(TestHelpers.s_testExplicitStruct, readStruct); } [Benchmark(InnerIterationCount = InnerCount)] @@ -82,7 +81,7 @@ private static void ReadStructAndReverseLE() } } - Assert.Equal(TestHelpers.testExplicitStruct, readStruct); + Assert.Equal(TestHelpers.s_testExplicitStruct, readStruct); } [Benchmark(InnerIterationCount = InnerCount)] @@ -116,7 +115,7 @@ private static void ReadStructFieldByFieldBE() } } - Assert.Equal(TestHelpers.testExplicitStruct, readStruct); + Assert.Equal(TestHelpers.s_testExplicitStruct, readStruct); } [Benchmark(InnerIterationCount = InnerCount)] @@ -150,7 +149,7 @@ private static void ReadStructFieldByFieldLE() } } - Assert.Equal(TestHelpers.testExplicitStruct, readStruct); + Assert.Equal(TestHelpers.s_testExplicitStruct, readStruct); } [Benchmark(InnerIterationCount = InnerCount)] @@ -185,7 +184,7 @@ private static void ReadStructFieldByFieldUsingBitConverterLE() } } - Assert.Equal(TestHelpers.testExplicitStruct, readStruct); + Assert.Equal(TestHelpers.s_testExplicitStruct, readStruct); } [Benchmark(InnerIterationCount = InnerCount)] @@ -235,14 +234,14 @@ private static void ReadStructFieldByFieldUsingBitConverterBE() } } - Assert.Equal(TestHelpers.testExplicitStruct, readStruct); + Assert.Equal(TestHelpers.s_testExplicitStruct, readStruct); } [Benchmark(InnerIterationCount = InnerCount)] private static void MeasureReverseEndianness() { var myArray = new int[1000]; - + foreach (var iteration in Benchmark.Iterations) { using (iteration.StartMeasurement()) diff --git a/src/System.Memory/tests/Performance/Perf.Span.IndexOf.cs b/src/System.Memory/tests/Performance/Perf.Span.IndexOf.cs index 8deac1000ec9..dd678920f40f 100644 --- a/src/System.Memory/tests/Performance/Perf.Span.IndexOf.cs +++ b/src/System.Memory/tests/Performance/Perf.Span.IndexOf.cs @@ -19,7 +19,7 @@ public class Perf_Span_IndexOf public void SpanIndexOfChar(int size) { Span charSpan = new char[size]; - charSpan[size/2] = '5'; + charSpan[size / 2] = '5'; int index = 0; foreach (BenchmarkIteration iteration in Benchmark.Iterations) @@ -32,9 +32,9 @@ public void SpanIndexOfChar(int size) } } } - Assert.Equal(size/2, index); + Assert.Equal(size / 2, index); } - + [Benchmark(InnerIterationCount = InnerCount)] [InlineData(1)] [InlineData(10)] @@ -43,7 +43,7 @@ public void SpanIndexOfChar(int size) public void SpanIndexOfCharAsBytes(int size) { Span charSpan = new char[size]; - charSpan[size/2] = '5'; + charSpan[size / 2] = '5'; Span byteSpan = charSpan.AsBytes(); int index = 0; @@ -59,7 +59,7 @@ public void SpanIndexOfCharAsBytes(int size) } Assert.Equal(size > 1 ? size : 0, index); } - + [Benchmark(InnerIterationCount = InnerCount)] [InlineData(1)] [InlineData(10)] @@ -67,10 +67,10 @@ public void SpanIndexOfCharAsBytes(int size) [InlineData(1000)] public void StringIndexOfChar(int size) { - string str = new string('0', size/2) + "5"; + string str = new string('0', size / 2) + "5"; if (size > 1) { - str += new string('0', size/2 - 1); + str += new string('0', size / 2 - 1); } int index = 0; @@ -84,7 +84,7 @@ public void StringIndexOfChar(int size) } } } - Assert.Equal(size/2, index); + Assert.Equal(size / 2, index); } [Benchmark(InnerIterationCount = InnerCount)] diff --git a/src/System.Memory/tests/Performance/Perf.Utf8Formatter.cs b/src/System.Memory/tests/Performance/Perf.Utf8Formatter.cs index 4466041dc0e6..f18bae264640 100644 --- a/src/System.Memory/tests/Performance/Perf.Utf8Formatter.cs +++ b/src/System.Memory/tests/Performance/Perf.Utf8Formatter.cs @@ -2,8 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using System.Text; -using System.Runtime.CompilerServices; using Microsoft.Xunit.Performance; using Xunit; diff --git a/src/System.Memory/tests/Performance/Perf.Utf8Parser.cs b/src/System.Memory/tests/Performance/Perf.Utf8Parser.cs index 7794ad752da6..7d1294f70dcd 100644 --- a/src/System.Memory/tests/Performance/Perf.Utf8Parser.cs +++ b/src/System.Memory/tests/Performance/Perf.Utf8Parser.cs @@ -3,7 +3,6 @@ // See the LICENSE file in the project root for more information. using System.Text; -using System.Runtime.CompilerServices; using Microsoft.Xunit.Performance; using Xunit; diff --git a/src/System.Memory/tests/ReadOnlyMemory/CopyTo.cs b/src/System.Memory/tests/ReadOnlyMemory/CopyTo.cs index e18af04510c3..0229cecce95e 100644 --- a/src/System.Memory/tests/ReadOnlyMemory/CopyTo.cs +++ b/src/System.Memory/tests/ReadOnlyMemory/CopyTo.cs @@ -92,7 +92,7 @@ public static void CopyToShorter() int[] dst = { 99, 100 }; ReadOnlyMemory srcMemory = src; - Assert.Throws( () => srcMemory.CopyTo(dst) ); + Assert.Throws(() => srcMemory.CopyTo(dst)); int[] expected = { 99, 100 }; Assert.Equal(expected, dst); // CopyTo() checks for sufficient space before doing any copying. } diff --git a/src/System.Memory/tests/ReadOnlyMemory/ImplicitConversion.cs b/src/System.Memory/tests/ReadOnlyMemory/ImplicitConversion.cs index 205dfd28c3c4..c3cc2f902abc 100644 --- a/src/System.Memory/tests/ReadOnlyMemory/ImplicitConversion.cs +++ b/src/System.Memory/tests/ReadOnlyMemory/ImplicitConversion.cs @@ -45,7 +45,7 @@ public static void CtorImplicitArraySegment() long[] b = { 1, -3, 7, -15, 31 }; ArraySegment segmentLong = new ArraySegment(b, 1, 3); CastReadOnly(segmentLong, -3, 7, -15); - + object o1 = new object(); object o2 = new object(); object o3 = new object(); @@ -61,7 +61,7 @@ public static void CtorImplicitZeroLengthArraySegment() int[] empty = Array.Empty(); ArraySegment emptySegment = new ArraySegment(empty); CastReadOnly(emptySegment); - + int[] a = { 19, -17 }; ArraySegment segmentInt = new ArraySegment(a, 1, 0); CastReadOnly(segmentInt); diff --git a/src/System.Memory/tests/ReadOnlySpan/CopyTo.cs b/src/System.Memory/tests/ReadOnlySpan/CopyTo.cs index a964c32808b0..077459be1c8b 100644 --- a/src/System.Memory/tests/ReadOnlySpan/CopyTo.cs +++ b/src/System.Memory/tests/ReadOnlySpan/CopyTo.cs @@ -181,8 +181,10 @@ public static void CopyToLargeSizeTest(long bufferSize) } finally { - if (allocatedFirst) AllocationHelper.ReleaseNative(ref memBlockFirst); - if (allocatedSecond) AllocationHelper.ReleaseNative(ref memBlockSecond); + if (allocatedFirst) + AllocationHelper.ReleaseNative(ref memBlockFirst); + if (allocatedSecond) + AllocationHelper.ReleaseNative(ref memBlockSecond); } } } diff --git a/src/System.Memory/tests/ReadOnlySpan/CtorPointerInt.cs b/src/System.Memory/tests/ReadOnlySpan/CtorPointerInt.cs index 3cf399b05531..8f2d42f6f90b 100644 --- a/src/System.Memory/tests/ReadOnlySpan/CtorPointerInt.cs +++ b/src/System.Memory/tests/ReadOnlySpan/CtorPointerInt.cs @@ -17,7 +17,7 @@ public static void CtorPointerInt() unsafe { int[] a = { 90, 91, 92 }; - fixed (int *pa = a) + fixed (int* pa = a) { ReadOnlySpan span = new ReadOnlySpan(pa, 3); span.Validate(90, 91, 92); diff --git a/src/System.Memory/tests/ReadOnlySpan/IndexOf.T.cs b/src/System.Memory/tests/ReadOnlySpan/IndexOf.T.cs index d0f4c1b14d50..2c80369662bf 100644 --- a/src/System.Memory/tests/ReadOnlySpan/IndexOf.T.cs +++ b/src/System.Memory/tests/ReadOnlySpan/IndexOf.T.cs @@ -27,7 +27,7 @@ public static void TestMatch() a[i] = 10 * (i + 1); } ReadOnlySpan span = new ReadOnlySpan(a); - + for (int targetIndex = 0; targetIndex < length; targetIndex++) { int target = a[targetIndex]; diff --git a/src/System.Memory/tests/ReadOnlySpan/IndexOf.char.cs b/src/System.Memory/tests/ReadOnlySpan/IndexOf.char.cs index 24ce08b73ece..2e71529b10fb 100644 --- a/src/System.Memory/tests/ReadOnlySpan/IndexOf.char.cs +++ b/src/System.Memory/tests/ReadOnlySpan/IndexOf.char.cs @@ -27,7 +27,7 @@ public static void TestMatch_Char() a[i] = (char)(i + 1); } ReadOnlySpan span = new ReadOnlySpan(a); - + for (int targetIndex = 0; targetIndex < length; targetIndex++) { char target = a[targetIndex]; diff --git a/src/System.Memory/tests/ReadOnlySpan/IndexOfSequence.T.cs b/src/System.Memory/tests/ReadOnlySpan/IndexOfSequence.T.cs index c699e4febffa..401e7c6aecbc 100644 --- a/src/System.Memory/tests/ReadOnlySpan/IndexOfSequence.T.cs +++ b/src/System.Memory/tests/ReadOnlySpan/IndexOfSequence.T.cs @@ -226,7 +226,7 @@ public static void IndexOfSequenceLengthOneValueAtVeryEnd_String() public static void IndexOfSequenceLengthOneValueJustPasttVeryEnd_String() { // A zero-length value is always "found" at the start of the span. - ReadOnlySpan span = new ReadOnlySpan(new string[] { "0", "1", "2", "3", "4", "5" }, 0, 5 ); + ReadOnlySpan span = new ReadOnlySpan(new string[] { "0", "1", "2", "3", "4", "5" }, 0, 5); ReadOnlySpan value = new ReadOnlySpan(new string[] { "5" }); int index = span.IndexOf(value); Assert.Equal(-1, index); diff --git a/src/System.Memory/tests/ReadOnlySpan/LastIndexOf.T.cs b/src/System.Memory/tests/ReadOnlySpan/LastIndexOf.T.cs index 136be532220c..973814262600 100644 --- a/src/System.Memory/tests/ReadOnlySpan/LastIndexOf.T.cs +++ b/src/System.Memory/tests/ReadOnlySpan/LastIndexOf.T.cs @@ -27,7 +27,7 @@ public static void TestMatchLastIndexOf() a[i] = 10 * (i + 1); } ReadOnlySpan span = new ReadOnlySpan(a); - + for (int targetIndex = 0; targetIndex < length; targetIndex++) { int target = a[targetIndex]; diff --git a/src/System.Memory/tests/ReadOnlySpan/LastIndexOf.byte.cs b/src/System.Memory/tests/ReadOnlySpan/LastIndexOf.byte.cs index 1a095e154886..466dfcff2c06 100644 --- a/src/System.Memory/tests/ReadOnlySpan/LastIndexOf.byte.cs +++ b/src/System.Memory/tests/ReadOnlySpan/LastIndexOf.byte.cs @@ -105,7 +105,7 @@ public static void TestAllignmentMatchLastIndexOf_Byte() var span = new ReadOnlySpan(array, i, 3 * Vector.Count); int idx = span.LastIndexOf(5); Assert.Equal(span.Length - 1, idx); - + span = new ReadOnlySpan(array, i, 3 * Vector.Count - 3); idx = span.LastIndexOf(5); Assert.Equal(span.Length - 1, idx); diff --git a/src/System.Memory/tests/ReadOnlySpan/LastIndexOf.char.cs b/src/System.Memory/tests/ReadOnlySpan/LastIndexOf.char.cs index b1caa690dc14..9a60ea90c96f 100644 --- a/src/System.Memory/tests/ReadOnlySpan/LastIndexOf.char.cs +++ b/src/System.Memory/tests/ReadOnlySpan/LastIndexOf.char.cs @@ -27,7 +27,7 @@ public static void TestMatchLastIndexOf_Char() a[i] = (char)(i + 1); } ReadOnlySpan span = new ReadOnlySpan(a); - + for (int targetIndex = 0; targetIndex < length; targetIndex++) { char target = a[targetIndex]; diff --git a/src/System.Memory/tests/ReadOnlySpan/Overflow.cs b/src/System.Memory/tests/ReadOnlySpan/Overflow.cs index dc9ed088e7a6..54f9fc7a93e2 100644 --- a/src/System.Memory/tests/ReadOnlySpan/Overflow.cs +++ b/src/System.Memory/tests/ReadOnlySpan/Overflow.cs @@ -36,9 +36,9 @@ public static void IndexOverflow() try { ref Guid memory = ref Unsafe.AsRef(memBlock.ToPointer()); - var span = new ReadOnlySpan(memBlock.ToPointer(), GuidThreeGiBLimit); + var span = new ReadOnlySpan(memBlock.ToPointer(), s_guidThreeGiBLimit); - int bigIndex = checked(GuidTwoGiBLimit + 1); + int bigIndex = checked(s_guidTwoGiBLimit + 1); uint byteOffset = checked((uint)bigIndex * (uint)sizeof(Guid)); Assert.True(byteOffset > int.MaxValue); // Make sure byteOffset actually overflows 2Gb, or this test is pointless. Guid expectedGuid = Guid.NewGuid(); @@ -65,8 +65,7 @@ public static void IndexOverflow() private const long TwoGiB = 2L * 1024L * 1024L * 1024L; private const long OneGiB = 1L * 1024L * 1024L * 1024L; - private static readonly int GuidThreeGiBLimit = (int)(ThreeGiB / Unsafe.SizeOf()); // sizeof(Guid) requires unsafe keyword and I don't want to mark the entire class unsafe. - private static readonly int GuidTwoGiBLimit = (int)(TwoGiB / Unsafe.SizeOf()); - private static readonly int GuidOneGiBLimit = (int)(OneGiB / Unsafe.SizeOf()); + private static readonly int s_guidThreeGiBLimit = (int)(ThreeGiB / Unsafe.SizeOf()); // sizeof(Guid) requires unsafe keyword and I don't want to mark the entire class unsafe. + private static readonly int s_guidTwoGiBLimit = (int)(TwoGiB / Unsafe.SizeOf()); } } diff --git a/src/System.Memory/tests/Span/Clear.cs b/src/System.Memory/tests/Span/Clear.cs index 0b8da2c95710..7fbb5cb6977c 100644 --- a/src/System.Memory/tests/Span/Clear.cs +++ b/src/System.Memory/tests/Span/Clear.cs @@ -131,7 +131,6 @@ public static void ClearIntPtrLonger() Assert.Equal(expected, actual); } - [Fact] public static void ClearValueTypeWithoutReferences() { @@ -202,8 +201,8 @@ public static void ClearReferenceTypeLonger() [Fact] public static void ClearEnumType() { - TestEnum[] actual = {TestEnum.e0, TestEnum.e1, TestEnum.e2}; - TestEnum[] expected = {default, default, default }; + TestEnum[] actual = { TestEnum.e0, TestEnum.e1, TestEnum.e2 }; + TestEnum[] expected = { default, default, default }; var span = new Span(actual); span.Clear(); diff --git a/src/System.Memory/tests/Span/CopyTo.cs b/src/System.Memory/tests/Span/CopyTo.cs index 22ff1d015008..213354214c9c 100644 --- a/src/System.Memory/tests/Span/CopyTo.cs +++ b/src/System.Memory/tests/Span/CopyTo.cs @@ -250,8 +250,10 @@ public static void CopyToLargeSizeTest(long bufferSize) } finally { - if (allocatedFirst) AllocationHelper.ReleaseNative(ref memBlockFirst); - if (allocatedSecond) AllocationHelper.ReleaseNative(ref memBlockSecond); + if (allocatedFirst) + AllocationHelper.ReleaseNative(ref memBlockFirst); + if (allocatedSecond) + AllocationHelper.ReleaseNative(ref memBlockSecond); } } } diff --git a/src/System.Memory/tests/Span/IndexOf.T.cs b/src/System.Memory/tests/Span/IndexOf.T.cs index 775f4baadd17..0da12edee9d0 100644 --- a/src/System.Memory/tests/Span/IndexOf.T.cs +++ b/src/System.Memory/tests/Span/IndexOf.T.cs @@ -27,7 +27,7 @@ public static void TestMatch() a[i] = 10 * (i + 1); } Span span = new Span(a); - + for (int targetIndex = 0; targetIndex < length; targetIndex++) { int target = a[targetIndex]; diff --git a/src/System.Memory/tests/Span/IndexOf.char.cs b/src/System.Memory/tests/Span/IndexOf.char.cs index 51c91ffa0e42..b77c3f7d7722 100644 --- a/src/System.Memory/tests/Span/IndexOf.char.cs +++ b/src/System.Memory/tests/Span/IndexOf.char.cs @@ -27,7 +27,7 @@ public static void TestMatch_Char() a[i] = (char)(i + 1); } Span span = new Span(a); - + for (int targetIndex = 0; targetIndex < length; targetIndex++) { char target = a[targetIndex]; diff --git a/src/System.Memory/tests/Span/LastIndexOf.T.cs b/src/System.Memory/tests/Span/LastIndexOf.T.cs index 1394d9af5706..e15858eb3f5d 100644 --- a/src/System.Memory/tests/Span/LastIndexOf.T.cs +++ b/src/System.Memory/tests/Span/LastIndexOf.T.cs @@ -27,7 +27,7 @@ public static void TestMatchLastIndexOf() a[i] = 10 * (i + 1); } Span span = new Span(a); - + for (int targetIndex = 0; targetIndex < length; targetIndex++) { int target = a[targetIndex]; diff --git a/src/System.Memory/tests/Span/LastIndexOf.byte.cs b/src/System.Memory/tests/Span/LastIndexOf.byte.cs index 62a369d41167..a741d8419ac3 100644 --- a/src/System.Memory/tests/Span/LastIndexOf.byte.cs +++ b/src/System.Memory/tests/Span/LastIndexOf.byte.cs @@ -105,7 +105,7 @@ public static void TestAllignmentMatchLastIndexOf_Byte() var span = new Span(array, i, 3 * Vector.Count); int idx = span.LastIndexOf(5); Assert.Equal(span.Length - 1, idx); - + span = new Span(array, i, 3 * Vector.Count - 3); idx = span.LastIndexOf(5); Assert.Equal(span.Length - 1, idx); diff --git a/src/System.Memory/tests/Span/LastIndexOf.char.cs b/src/System.Memory/tests/Span/LastIndexOf.char.cs index 1ca6bcaa3b5a..902150a35bb0 100644 --- a/src/System.Memory/tests/Span/LastIndexOf.char.cs +++ b/src/System.Memory/tests/Span/LastIndexOf.char.cs @@ -27,7 +27,7 @@ public static void TestMatchLastIndexOf_Char() a[i] = (char)(i + 1); } Span span = new Span(a); - + for (int targetIndex = 0; targetIndex < length; targetIndex++) { char target = a[targetIndex]; diff --git a/src/System.Memory/tests/Span/Overflow.cs b/src/System.Memory/tests/Span/Overflow.cs index b9f9070f1b99..77d036d3ea2c 100644 --- a/src/System.Memory/tests/Span/Overflow.cs +++ b/src/System.Memory/tests/Span/Overflow.cs @@ -36,9 +36,9 @@ public static void IndexOverflow() try { ref Guid memory = ref Unsafe.AsRef(memBlock.ToPointer()); - var span = new Span(memBlock.ToPointer(), GuidThreeGiBLimit); + var span = new Span(memBlock.ToPointer(), s_guidThreeGiBLimit); - int bigIndex = checked(GuidTwoGiBLimit + 1); + int bigIndex = checked(s_guidTwoGiBLimit + 1); uint byteOffset = checked((uint)bigIndex * (uint)sizeof(Guid)); Assert.True(byteOffset > int.MaxValue); // Make sure byteOffset actually overflows 2Gb, or this test is pointless. ref Guid expected = ref Unsafe.Add(ref memory, bigIndex); @@ -63,8 +63,7 @@ public static void IndexOverflow() private const long TwoGiB = 2L * 1024L * 1024L * 1024L; private const long OneGiB = 1L * 1024L * 1024L * 1024L; - private static readonly int GuidThreeGiBLimit = (int)(ThreeGiB / Unsafe.SizeOf()); // sizeof(Guid) requires unsafe keyword and I don't want to mark the entire class unsafe. - private static readonly int GuidTwoGiBLimit = (int)(TwoGiB / Unsafe.SizeOf()); - private static readonly int GuidOneGiBLimit = (int)(OneGiB / Unsafe.SizeOf()); + private static readonly int s_guidThreeGiBLimit = (int)(ThreeGiB / Unsafe.SizeOf()); // sizeof(Guid) requires unsafe keyword and I don't want to mark the entire class unsafe. + private static readonly int s_guidTwoGiBLimit = (int)(TwoGiB / Unsafe.SizeOf()); } } diff --git a/src/System.Memory/tests/TInt.cs b/src/System.Memory/tests/TInt.cs index e6dba18fe82f..2bceaa2c800b 100644 --- a/src/System.Memory/tests/TInt.cs +++ b/src/System.Memory/tests/TInt.cs @@ -13,7 +13,7 @@ namespace System internal struct TInt : IEquatable { public TInt(int value) - : this(value, (Action)null) + : this(value, (Action)null) { // This constructor does not report comparisons but is still useful for catching uses of the boxing Equals(). } diff --git a/src/System.Memory/tests/TestHelpers.cs b/src/System.Memory/tests/TestHelpers.cs index 29e5291ca2e6..c5c2fece6820 100644 --- a/src/System.Memory/tests/TestHelpers.cs +++ b/src/System.Memory/tests/TestHelpers.cs @@ -33,7 +33,7 @@ public static void ValidateReferenceType(this Span span, params T[] expect public delegate void AssertThrowsAction(Span span); // Cannot use standard Assert.Throws() when testing Span - Span and closures don't get along. - public static void AssertThrows(Span span, AssertThrowsAction action) where E:Exception + public static void AssertThrows(Span span, AssertThrowsAction action) where E : Exception { try { @@ -89,7 +89,7 @@ public static void ValidateReferenceType(this ReadOnlySpan span, params T[ public delegate void AssertThrowsActionReadOnly(ReadOnlySpan span); // Cannot use standard Assert.Throws() when testing Span - Span and closures don't get along. - public static void AssertThrows(ReadOnlySpan span, AssertThrowsActionReadOnly action) where E:Exception + public static void AssertThrows(ReadOnlySpan span, AssertThrowsActionReadOnly action) where E : Exception { try { @@ -163,7 +163,7 @@ public static void Validate(Span span, T value) where T : struct span.Clear(); } - public static TestStructExplicit testExplicitStruct = new TestStructExplicit + public static TestStructExplicit s_testExplicitStruct = new TestStructExplicit { S0 = short.MaxValue, I0 = int.MaxValue, @@ -183,18 +183,18 @@ public static Span GetSpanBE() { Span spanBE = new byte[Unsafe.SizeOf()]; - WriteInt16BigEndian(spanBE, testExplicitStruct.S0); - WriteInt32BigEndian(spanBE.Slice(2), testExplicitStruct.I0); - WriteInt64BigEndian(spanBE.Slice(6), testExplicitStruct.L0); - WriteUInt16BigEndian(spanBE.Slice(14), testExplicitStruct.US0); - WriteUInt32BigEndian(spanBE.Slice(16), testExplicitStruct.UI0); - WriteUInt64BigEndian(spanBE.Slice(20), testExplicitStruct.UL0); - WriteInt16BigEndian(spanBE.Slice(28), testExplicitStruct.S1); - WriteInt32BigEndian(spanBE.Slice(30), testExplicitStruct.I1); - WriteInt64BigEndian(spanBE.Slice(34), testExplicitStruct.L1); - WriteUInt16BigEndian(spanBE.Slice(42), testExplicitStruct.US1); - WriteUInt32BigEndian(spanBE.Slice(44), testExplicitStruct.UI1); - WriteUInt64BigEndian(spanBE.Slice(48), testExplicitStruct.UL1); + WriteInt16BigEndian(spanBE, s_testExplicitStruct.S0); + WriteInt32BigEndian(spanBE.Slice(2), s_testExplicitStruct.I0); + WriteInt64BigEndian(spanBE.Slice(6), s_testExplicitStruct.L0); + WriteUInt16BigEndian(spanBE.Slice(14), s_testExplicitStruct.US0); + WriteUInt32BigEndian(spanBE.Slice(16), s_testExplicitStruct.UI0); + WriteUInt64BigEndian(spanBE.Slice(20), s_testExplicitStruct.UL0); + WriteInt16BigEndian(spanBE.Slice(28), s_testExplicitStruct.S1); + WriteInt32BigEndian(spanBE.Slice(30), s_testExplicitStruct.I1); + WriteInt64BigEndian(spanBE.Slice(34), s_testExplicitStruct.L1); + WriteUInt16BigEndian(spanBE.Slice(42), s_testExplicitStruct.US1); + WriteUInt32BigEndian(spanBE.Slice(44), s_testExplicitStruct.UI1); + WriteUInt64BigEndian(spanBE.Slice(48), s_testExplicitStruct.UL1); Assert.Equal(56, spanBE.Length); return spanBE; @@ -204,23 +204,23 @@ public static Span GetSpanLE() { Span spanLE = new byte[Unsafe.SizeOf()]; - WriteInt16LittleEndian(spanLE, testExplicitStruct.S0); - WriteInt32LittleEndian(spanLE.Slice(2), testExplicitStruct.I0); - WriteInt64LittleEndian( spanLE.Slice(6), testExplicitStruct.L0); - WriteUInt16LittleEndian(spanLE.Slice(14), testExplicitStruct.US0); - WriteUInt32LittleEndian(spanLE.Slice(16), testExplicitStruct.UI0); - WriteUInt64LittleEndian(spanLE.Slice(20), testExplicitStruct.UL0); - WriteInt16LittleEndian(spanLE.Slice(28), testExplicitStruct.S1); - WriteInt32LittleEndian(spanLE.Slice(30), testExplicitStruct.I1); - WriteInt64LittleEndian(spanLE.Slice(34), testExplicitStruct.L1); - WriteUInt16LittleEndian(spanLE.Slice(42), testExplicitStruct.US1); - WriteUInt32LittleEndian(spanLE.Slice(44), testExplicitStruct.UI1); - WriteUInt64LittleEndian(spanLE.Slice(48), testExplicitStruct.UL1); + WriteInt16LittleEndian(spanLE, s_testExplicitStruct.S0); + WriteInt32LittleEndian(spanLE.Slice(2), s_testExplicitStruct.I0); + WriteInt64LittleEndian(spanLE.Slice(6), s_testExplicitStruct.L0); + WriteUInt16LittleEndian(spanLE.Slice(14), s_testExplicitStruct.US0); + WriteUInt32LittleEndian(spanLE.Slice(16), s_testExplicitStruct.UI0); + WriteUInt64LittleEndian(spanLE.Slice(20), s_testExplicitStruct.UL0); + WriteInt16LittleEndian(spanLE.Slice(28), s_testExplicitStruct.S1); + WriteInt32LittleEndian(spanLE.Slice(30), s_testExplicitStruct.I1); + WriteInt64LittleEndian(spanLE.Slice(34), s_testExplicitStruct.L1); + WriteUInt16LittleEndian(spanLE.Slice(42), s_testExplicitStruct.US1); + WriteUInt32LittleEndian(spanLE.Slice(44), s_testExplicitStruct.UI1); + WriteUInt64LittleEndian(spanLE.Slice(48), s_testExplicitStruct.UL1); Assert.Equal(56, spanLE.Length); return spanLE; } - + [StructLayout(LayoutKind.Explicit)] public struct TestStructExplicit { diff --git a/src/System.Runtime/ref/System.Runtime.cs b/src/System.Runtime/ref/System.Runtime.cs index 4a891241771d..821424950c0b 100644 --- a/src/System.Runtime/ref/System.Runtime.cs +++ b/src/System.Runtime/ref/System.Runtime.cs @@ -64,9 +64,9 @@ public static partial class Activator public static object CreateInstance(System.Type type) { throw null; } public static object CreateInstance(System.Type type, System.Boolean nonPublic) { throw null; } public static object CreateInstance(System.Type type, params object[] args) { throw null; } - public static object CreateInstance(System.Type type, object[] args, object[] activationAttributes) { throw null; } - public static object CreateInstance(System.Type type, System.Reflection.BindingFlags bindingAttr, System.Reflection.Binder binder, object[] args, System.Globalization.CultureInfo culture) { throw null; } - public static object CreateInstance(System.Type type, System.Reflection.BindingFlags bindingAttr, System.Reflection.Binder binder, object[] args, System.Globalization.CultureInfo culture, object[] activationAttributes) { throw null; } + public static object CreateInstance(System.Type type, object[] args, object[] activationAttributes) { throw null; } + public static object CreateInstance(System.Type type, System.Reflection.BindingFlags bindingAttr, System.Reflection.Binder binder, object[] args, System.Globalization.CultureInfo culture) { throw null; } + public static object CreateInstance(System.Type type, System.Reflection.BindingFlags bindingAttr, System.Reflection.Binder binder, object[] args, System.Globalization.CultureInfo culture, object[] activationAttributes) { throw null; } public static T CreateInstance() { throw null; } } @@ -78,7 +78,7 @@ public static void SetSwitch(string switchName, bool isEnabled) { } public static string TargetFrameworkName { get { throw null; } } public static object GetData(string name) { throw null; } } - + public partial class EntryPointNotFoundException : System.TypeLoadException { public EntryPointNotFoundException() { } @@ -402,14 +402,14 @@ protected Attribute() { } public static System.Attribute[] GetCustomAttributes(System.Reflection.ParameterInfo element, bool inherit) { throw null; } public static System.Attribute[] GetCustomAttributes(System.Reflection.ParameterInfo element, System.Type attributeType) { throw null; } public static System.Attribute[] GetCustomAttributes(System.Reflection.ParameterInfo element, System.Type attributeType, bool inherit) { throw null; } - public static bool IsDefined(System.Reflection.Assembly element, System.Type attributeType) { throw null; } - public static bool IsDefined(System.Reflection.Assembly element, System.Type attributeType, bool inherit) { throw null; } - public static bool IsDefined(System.Reflection.MemberInfo element, System.Type attributeType) { throw null; } - public static bool IsDefined(System.Reflection.MemberInfo element, System.Type attributeType, bool inherit) { throw null; } - public static bool IsDefined(System.Reflection.Module element, System.Type attributeType) { throw null; } - public static bool IsDefined(System.Reflection.Module element, System.Type attributeType, bool inherit) { throw null; } - public static bool IsDefined(System.Reflection.ParameterInfo element, System.Type attributeType) { throw null; } - public static bool IsDefined(System.Reflection.ParameterInfo element, System.Type attributeType, bool inherit) { throw null; } + public static bool IsDefined(System.Reflection.Assembly element, System.Type attributeType) { throw null; } + public static bool IsDefined(System.Reflection.Assembly element, System.Type attributeType, bool inherit) { throw null; } + public static bool IsDefined(System.Reflection.MemberInfo element, System.Type attributeType) { throw null; } + public static bool IsDefined(System.Reflection.MemberInfo element, System.Type attributeType, bool inherit) { throw null; } + public static bool IsDefined(System.Reflection.Module element, System.Type attributeType) { throw null; } + public static bool IsDefined(System.Reflection.Module element, System.Type attributeType, bool inherit) { throw null; } + public static bool IsDefined(System.Reflection.ParameterInfo element, System.Type attributeType) { throw null; } + public static bool IsDefined(System.Reflection.ParameterInfo element, System.Type attributeType, bool inherit) { throw null; } } [System.FlagsAttribute] public enum AttributeTargets @@ -614,7 +614,7 @@ public partial struct Char : System.IComparable, System.IComparable, Syste public static char ToUpperInvariant(char c) { throw null; } public static bool TryParse(string s, out char result) { throw null; } } - public sealed partial class CharEnumerator : System.Collections.Generic.IEnumerator, System.Collections.IEnumerator, System.ICloneable, System.IDisposable + public sealed partial class CharEnumerator : System.Collections.Generic.IEnumerator, System.Collections.IEnumerator, System.ICloneable, System.IDisposable { internal CharEnumerator() { } public char Current { get { throw null; } } @@ -930,38 +930,38 @@ void System.Runtime.Serialization.IDeserializationCallback.OnDeserialization(obj public static decimal operator --(decimal d) { throw null; } public static decimal operator /(decimal d1, decimal d2) { throw null; } public static bool operator ==(decimal d1, decimal d2) { throw null; } - public static explicit operator byte (decimal value) { throw null; } - public static explicit operator char (decimal value) { throw null; } - public static explicit operator double (decimal value) { throw null; } - public static explicit operator short (decimal value) { throw null; } - public static explicit operator int (decimal value) { throw null; } - public static explicit operator long (decimal value) { throw null; } + public static explicit operator byte(decimal value) { throw null; } + public static explicit operator char(decimal value) { throw null; } + public static explicit operator double(decimal value) { throw null; } + public static explicit operator short(decimal value) { throw null; } + public static explicit operator int(decimal value) { throw null; } + public static explicit operator long(decimal value) { throw null; } [System.CLSCompliantAttribute(false)] - public static explicit operator sbyte (decimal value) { throw null; } - public static explicit operator float (decimal value) { throw null; } + public static explicit operator sbyte(decimal value) { throw null; } + public static explicit operator float(decimal value) { throw null; } [System.CLSCompliantAttribute(false)] - public static explicit operator ushort (decimal value) { throw null; } + public static explicit operator ushort(decimal value) { throw null; } [System.CLSCompliantAttribute(false)] - public static explicit operator uint (decimal value) { throw null; } + public static explicit operator uint(decimal value) { throw null; } [System.CLSCompliantAttribute(false)] - public static explicit operator ulong (decimal value) { throw null; } - public static explicit operator decimal (double value) { throw null; } - public static explicit operator decimal (float value) { throw null; } + public static explicit operator ulong(decimal value) { throw null; } + public static explicit operator decimal(double value) { throw null; } + public static explicit operator decimal(float value) { throw null; } public static bool operator >(decimal d1, decimal d2) { throw null; } public static bool operator >=(decimal d1, decimal d2) { throw null; } - public static implicit operator decimal (byte value) { throw null; } - public static implicit operator decimal (char value) { throw null; } - public static implicit operator decimal (short value) { throw null; } - public static implicit operator decimal (int value) { throw null; } - public static implicit operator decimal (long value) { throw null; } + public static implicit operator decimal(byte value) { throw null; } + public static implicit operator decimal(char value) { throw null; } + public static implicit operator decimal(short value) { throw null; } + public static implicit operator decimal(int value) { throw null; } + public static implicit operator decimal(long value) { throw null; } [System.CLSCompliantAttribute(false)] - public static implicit operator decimal (sbyte value) { throw null; } + public static implicit operator decimal(sbyte value) { throw null; } [System.CLSCompliantAttribute(false)] - public static implicit operator decimal (ushort value) { throw null; } + public static implicit operator decimal(ushort value) { throw null; } [System.CLSCompliantAttribute(false)] - public static implicit operator decimal (uint value) { throw null; } + public static implicit operator decimal(uint value) { throw null; } [System.CLSCompliantAttribute(false)] - public static implicit operator decimal (ulong value) { throw null; } + public static implicit operator decimal(ulong value) { throw null; } public static decimal operator ++(decimal d) { throw null; } public static bool operator !=(decimal d1, decimal d2) { throw null; } public static bool operator <(decimal d1, decimal d2) { throw null; } @@ -1025,7 +1025,7 @@ void System.Runtime.Serialization.IDeserializationCallback.OnDeserialization(obj public static bool TryParse(System.ReadOnlySpan s, out decimal result) { throw null; } public static bool TryParse(System.ReadOnlySpan s, System.Globalization.NumberStyles style, System.IFormatProvider provider, out decimal result) { throw null; } } - public abstract partial class Delegate: System.ICloneable, System.Runtime.Serialization.ISerializable + public abstract partial class Delegate : System.ICloneable, System.Runtime.Serialization.ISerializable { protected Delegate(object target, string method) { } protected Delegate(System.Type target, string method) { } @@ -1177,7 +1177,7 @@ protected Enum() { } public override string ToString() { throw null; } public string ToString(string format) { throw null; } [System.ObsoleteAttribute("The provider argument is not used. Please use ToString().")] - public string ToString(System.IFormatProvider provider) { throw null; } + public string ToString(System.IFormatProvider provider) { throw null; } [System.ObsoleteAttribute("The provider argument is not used. Please use ToString(String).")] public string ToString(string format, System.IFormatProvider provider) { throw null; } public static bool TryParse(System.Type enumType, string value, out object result) { throw null; } @@ -1206,7 +1206,7 @@ protected Exception(System.Runtime.Serialization.SerializationInfo info, System. public virtual string Message { get { throw null; } } public virtual string Source { get { throw null; } set { } } public virtual string StackTrace { get { throw null; } } - public System.Reflection.MethodBase TargetSite { get { throw null; } } + public System.Reflection.MethodBase TargetSite { get { throw null; } } protected event System.EventHandler SerializeObjectState { add { } remove { } } public virtual System.Exception GetBaseException() { throw null; } public virtual void GetObjectData(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) { } @@ -1558,8 +1558,8 @@ void System.Runtime.Serialization.ISerializable.GetObjectData(System.Runtime.Ser public static bool operator ==(System.IntPtr value1, System.IntPtr value2) { throw null; } public static explicit operator System.IntPtr(int value) { throw null; } public static explicit operator System.IntPtr(long value) { throw null; } - public static explicit operator int (System.IntPtr value) { throw null; } - public static explicit operator long (System.IntPtr value) { throw null; } + public static explicit operator int(System.IntPtr value) { throw null; } + public static explicit operator long(System.IntPtr value) { throw null; } [System.CLSCompliantAttribute(false)] public static unsafe explicit operator void* (System.IntPtr value) { throw null; } [System.CLSCompliantAttribute(false)] @@ -3180,7 +3180,7 @@ public partial struct UInt64 : System.IComparable, System.IComparable, Sy } [System.CLSCompliantAttribute(false)] [System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)] - public partial struct UIntPtr : System.Runtime.Serialization.ISerializable, IEquatable + public partial struct UIntPtr : System.Runtime.Serialization.ISerializable, IEquatable { public static readonly System.UIntPtr Zero; public UIntPtr(uint value) { throw null; } @@ -3197,8 +3197,8 @@ void System.Runtime.Serialization.ISerializable.GetObjectData(System.Runtime.Ser public static bool operator ==(System.UIntPtr value1, System.UIntPtr value2) { throw null; } public static explicit operator System.UIntPtr(uint value) { throw null; } public static explicit operator System.UIntPtr(ulong value) { throw null; } - public static explicit operator uint (System.UIntPtr value) { throw null; } - public static explicit operator ulong (System.UIntPtr value) { throw null; } + public static explicit operator uint(System.UIntPtr value) { throw null; } + public static explicit operator ulong(System.UIntPtr value) { throw null; } [System.CLSCompliantAttribute(false)] public static unsafe explicit operator void* (System.UIntPtr value) { throw null; } [System.CLSCompliantAttribute(false)] @@ -3462,7 +3462,7 @@ public struct ValueTuple public static ValueTuple Create(T1 item1, T2 item2, T3 item3, T4 item4) { throw null; } public static ValueTuple Create(T1 item1, T2 item2, T3 item3, T4 item4, T5 item5) { throw null; } public static ValueTuple Create(T1 item1, T2 item2, T3 item3, T4 item4, T5 item5, T6 item6) { throw null; } - public static ValueTuple Create(T1 item1, T2 item2, T3 item3, T4 item4, T5 item5, T6 item6, T7 item7) { throw null; } + public static ValueTuple Create(T1 item1, T2 item2, T3 item3, T4 item4, T5 item5, T6 item6, T7 item7) { throw null; } public static ValueTuple> Create(T1 item1, T2 item2, T3 item3, T4 item4, T5 item5, T6 item6, T7 item7, T8 item8) { throw null; } } public struct ValueTuple @@ -3711,7 +3711,7 @@ public abstract partial class CriticalFinalizerObject protected CriticalFinalizerObject() { } ~CriticalFinalizerObject() { } } - + public enum Cer { MayFail = 1, @@ -3725,7 +3725,7 @@ public enum Consistency MayCorruptProcess = 0, WillNotCorruptState = 3, } - [System.AttributeUsageAttribute((System.AttributeTargets)(1133), Inherited=false)] + [System.AttributeUsageAttribute((System.AttributeTargets)(1133), Inherited = false)] public sealed partial class ReliabilityContractAttribute : System.Attribute { public ReliabilityContractAttribute(System.Runtime.ConstrainedExecution.Consistency consistencyGuarantee, System.Runtime.ConstrainedExecution.Cer cer) { } @@ -3864,23 +3864,23 @@ public void UnsafeOnCompleted(System.Action continuation) { } } namespace System.Buffers { - public unsafe struct MemoryHandle : IDisposable + public unsafe struct MemoryHandle : IDisposable { [System.CLSCompliantAttribute(false)] - public MemoryHandle(IRetainable owner, void* pointer = null, System.Runtime.InteropServices.GCHandle handle = default(System.Runtime.InteropServices.GCHandle)) { throw null; } + public MemoryHandle(IRetainable owner, void* pointer = null, System.Runtime.InteropServices.GCHandle handle = default(System.Runtime.InteropServices.GCHandle)) { throw null; } [System.CLSCompliantAttribute(false)] public void* Pointer { get { throw null; } } public bool HasPointer { get { throw null; } } public void Dispose() { throw null; } } - public interface IRetainable + public interface IRetainable { bool Release(); void Retain(); } - - public abstract class OwnedMemory : IDisposable, IRetainable + + public abstract class OwnedMemory : IDisposable, IRetainable { public Memory Memory { get { throw null; } } public abstract bool IsDisposed { get; } @@ -4064,7 +4064,7 @@ protected KeyNotFoundException(System.Runtime.Serialization.SerializationInfo in } public static class KeyValuePair { - public static KeyValuePair Create(TKey key, TValue value) { throw null; } + public static KeyValuePair Create(TKey key, TValue value) { throw null; } } [System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)] public readonly partial struct KeyValuePair @@ -4204,9 +4204,9 @@ public enum AssemblyHashAlgorithm } public enum AssemblyVersionCompatibility { - SameMachine = 1, - SameProcess = 2, - SameDomain = 3, + SameMachine = 1, + SameProcess = 2, + SameDomain = 3, } } namespace System.Diagnostics @@ -4953,7 +4953,7 @@ public IdnMapping() { } public string GetUnicode(string ascii) { throw null; } public string GetUnicode(string ascii, int index) { throw null; } public string GetUnicode(string ascii, int index, int count) { throw null; } - } + } public partial class CultureNotFoundException : System.ArgumentException, System.Runtime.Serialization.ISerializable { public CultureNotFoundException() { } @@ -5389,7 +5389,7 @@ public virtual void GetObjectData(System.Runtime.Serialization.SerializationInfo public static System.Reflection.Assembly ReflectionOnlyLoadFrom(string assemblyFile) { throw null; } public virtual bool IsDefined(Type attributeType, bool inherit) { throw null; } } - [System.AttributeUsageAttribute((System.AttributeTargets)(1), Inherited=false)] + [System.AttributeUsageAttribute((System.AttributeTargets)(1), Inherited = false)] public sealed partial class AssemblyAlgorithmIdAttribute : System.Attribute { public AssemblyAlgorithmIdAttribute(System.Configuration.Assemblies.AssemblyHashAlgorithm algorithmId) { } @@ -5574,7 +5574,7 @@ public enum BindingFlags CreateInstance = 512, DeclaredOnly = 2, Default = 0, - DoNotWrapExceptions = 33554432, + DoNotWrapExceptions = 33554432, ExactBinding = 65536, FlattenHierarchy = 64, GetField = 1024, @@ -5608,8 +5608,8 @@ public abstract partial class ConstructorInfo : System.Reflection.MethodBase public static readonly string TypeConstructorName; protected ConstructorInfo() { } public override bool Equals(object obj) { throw null; } - public static bool operator==(System.Reflection.ConstructorInfo left, System.Reflection.ConstructorInfo right) { throw null; } - public static bool operator!=(System.Reflection.ConstructorInfo left, System.Reflection.ConstructorInfo right) { throw null; } + public static bool operator ==(System.Reflection.ConstructorInfo left, System.Reflection.ConstructorInfo right) { throw null; } + public static bool operator !=(System.Reflection.ConstructorInfo left, System.Reflection.ConstructorInfo right) { throw null; } public override int GetHashCode() { throw null; } public object Invoke(object[] parameters) { throw null; } public abstract object Invoke(System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, object[] parameters, System.Globalization.CultureInfo culture); @@ -5757,7 +5757,7 @@ protected ExceptionHandlingClause() { } public override string ToString() { throw null; } } [System.FlagsAttribute] - public enum ExceptionHandlingClauseOptions: int + public enum ExceptionHandlingClauseOptions : int { Clause = 0, Filter = 1, @@ -6054,7 +6054,8 @@ protected MethodInfo() { } public override MemberTypes MemberType { get { throw null; } } public abstract System.Reflection.ICustomAttributeProvider ReturnTypeCustomAttributes { get; } } - public sealed class Missing : System.Runtime.Serialization.ISerializable { + public sealed class Missing : System.Runtime.Serialization.ISerializable + { internal Missing() { } public static readonly System.Reflection.Missing Value; void System.Runtime.Serialization.ISerializable.GetObjectData(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) { } @@ -6186,7 +6187,7 @@ public ParameterModifier(int parameterCount) { } [System.CLSCompliantAttribute(false)] public sealed class Pointer : System.Runtime.Serialization.ISerializable { - private Pointer() { } + private Pointer() { } public static unsafe object Box(void* ptr, System.Type type) { throw null; } public static unsafe void* Unbox(object ptr) { throw null; } unsafe void System.Runtime.Serialization.ISerializable.GetObjectData(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) { } @@ -6195,11 +6196,11 @@ unsafe void System.Runtime.Serialization.ISerializable.GetObjectData(System.Runt public enum PortableExecutableKinds { NotAPortableExecutableImage = 0, - ILOnly = 1, - Required32Bit = 2, - PE32Plus = 4, - Unmanaged32Bit = 8, - Preferred32Bit = 16, + ILOnly = 1, + Required32Bit = 2, + PE32Plus = 4, + Unmanaged32Bit = 8, + Preferred32Bit = 16, } public enum ProcessorArchitecture { @@ -6243,7 +6244,7 @@ protected PropertyInfo() { } public abstract object GetValue(object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, object[] index, System.Globalization.CultureInfo culture); public void SetValue(object obj, object value) { } public virtual void SetValue(object obj, object value, object[] index) { } - public abstract void SetValue(object obj, object value, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, object[] index, System.Globalization.CultureInfo culture); + public abstract void SetValue(object obj, object value, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, object[] index, System.Globalization.CultureInfo culture); public override MemberTypes MemberType { get { throw null; } } public MethodInfo[] GetAccessors() { throw null; } public abstract MethodInfo[] GetAccessors(bool nonPublic); @@ -6359,7 +6360,7 @@ protected TypeDelegator() { } public TypeDelegator(System.Type delegatingType) { } public override System.Guid GUID { get { throw null; } } public override int MetadataToken { get { throw null; } } - public override object InvokeMember(System.String name,System.Reflection.BindingFlags invokeAttr,System.Reflection.Binder binder,System.Object target, System.Object[] args,System.Reflection.ParameterModifier[] modifiers,System.Globalization.CultureInfo culture,System.String[] namedParameters) { throw null; } + public override object InvokeMember(System.String name, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object target, System.Object[] args, System.Reflection.ParameterModifier[] modifiers, System.Globalization.CultureInfo culture, System.String[] namedParameters) { throw null; } public override System.Reflection.Module Module { get { throw null; } } public override System.Reflection.Assembly Assembly { get { throw null; } } public override System.RuntimeTypeHandle TypeHandle { get { throw null; } } @@ -6368,22 +6369,22 @@ public TypeDelegator(System.Type delegatingType) { } public override System.String Namespace { get { throw null; } } public override System.String AssemblyQualifiedName { get { throw null; } } public override System.Type BaseType { get { throw null; } } - protected override System.Reflection.ConstructorInfo GetConstructorImpl(System.Reflection.BindingFlags bindingAttr,System.Reflection.Binder binder, System.Reflection.CallingConventions callConvention, System.Type[] types, System.Reflection.ParameterModifier[] modifiers) { throw null; } + protected override System.Reflection.ConstructorInfo GetConstructorImpl(System.Reflection.BindingFlags bindingAttr, System.Reflection.Binder binder, System.Reflection.CallingConventions callConvention, System.Type[] types, System.Reflection.ParameterModifier[] modifiers) { throw null; } public override System.Reflection.ConstructorInfo[] GetConstructors(System.Reflection.BindingFlags bindingAttr) { throw null; } - protected override System.Reflection.MethodInfo GetMethodImpl(System.String name,System.Reflection.BindingFlags bindingAttr,System.Reflection.Binder binder, System.Reflection.CallingConventions callConvention, System.Type[] types,System.Reflection.ParameterModifier[] modifiers) { throw null; } + protected override System.Reflection.MethodInfo GetMethodImpl(System.String name, System.Reflection.BindingFlags bindingAttr, System.Reflection.Binder binder, System.Reflection.CallingConventions callConvention, System.Type[] types, System.Reflection.ParameterModifier[] modifiers) { throw null; } public override System.Reflection.MethodInfo[] GetMethods(System.Reflection.BindingFlags bindingAttr) { throw null; } public override System.Reflection.FieldInfo GetField(System.String name, System.Reflection.BindingFlags bindingAttr) { throw null; } public override System.Reflection.FieldInfo[] GetFields(System.Reflection.BindingFlags bindingAttr) { throw null; } public override System.Type GetInterface(System.String name, bool ignoreCase) { throw null; } public override System.Type[] GetInterfaces() { throw null; } - public override System.Reflection.EventInfo GetEvent(System.String name,System.Reflection.BindingFlags bindingAttr) { throw null; } + public override System.Reflection.EventInfo GetEvent(System.String name, System.Reflection.BindingFlags bindingAttr) { throw null; } public override System.Reflection.EventInfo[] GetEvents() { throw null; } - protected override System.Reflection.PropertyInfo GetPropertyImpl(System.String name,System.Reflection.BindingFlags bindingAttr,System.Reflection.Binder binder, System.Type returnType, System.Type[] types, System.Reflection.ParameterModifier[] modifiers) { throw null; } + protected override System.Reflection.PropertyInfo GetPropertyImpl(System.String name, System.Reflection.BindingFlags bindingAttr, System.Reflection.Binder binder, System.Type returnType, System.Type[] types, System.Reflection.ParameterModifier[] modifiers) { throw null; } public override System.Reflection.PropertyInfo[] GetProperties(System.Reflection.BindingFlags bindingAttr) { throw null; } public override System.Reflection.EventInfo[] GetEvents(System.Reflection.BindingFlags bindingAttr) { throw null; } public override System.Type[] GetNestedTypes(System.Reflection.BindingFlags bindingAttr) { throw null; } public override System.Type GetNestedType(System.String name, System.Reflection.BindingFlags bindingAttr) { throw null; } - public override System.Reflection.MemberInfo[] GetMember(System.String name, System.Reflection.MemberTypes type, System.Reflection.BindingFlags bindingAttr) { throw null; } + public override System.Reflection.MemberInfo[] GetMember(System.String name, System.Reflection.MemberTypes type, System.Reflection.BindingFlags bindingAttr) { throw null; } public override System.Reflection.MemberInfo[] GetMembers(System.Reflection.BindingFlags bindingAttr) { throw null; } public override bool IsByRefLike { get { throw null; } } protected override System.Reflection.TypeAttributes GetAttributeFlagsImpl() { throw null; } @@ -6465,8 +6466,8 @@ public enum GCLatencyMode public static partial class GCSettings { public static bool IsServerGC { get { throw null; } } - public static System.Runtime.GCLargeObjectHeapCompactionMode LargeObjectHeapCompactionMode { get { throw null; }set { } } - public static System.Runtime.GCLatencyMode LatencyMode { get { throw null; }set { } } + public static System.Runtime.GCLargeObjectHeapCompactionMode LargeObjectHeapCompactionMode { get { throw null; } set { } } + public static System.Runtime.GCLatencyMode LatencyMode { get { throw null; } set { } } } public sealed partial class MemoryFailPoint : System.Runtime.ConstrainedExecution.CriticalFinalizerObject, System.IDisposable { @@ -6493,14 +6494,14 @@ public enum MethodCodeType IL = System.Reflection.MethodImplAttributes.IL, Native = System.Reflection.MethodImplAttributes.Native, OPTIL = System.Reflection.MethodImplAttributes.OPTIL, - Runtime = System.Reflection.MethodImplAttributes.Runtime + Runtime = System.Reflection.MethodImplAttributes.Runtime } [Flags] public enum CompilationRelaxations : int - { - NoStringInterning = 0x0008, // Start in 0x0008, we had other non public flags in this enum before, - // so we'll start here just in case somebody used them. This flag is only - // valid when set for Assemblies. + { + NoStringInterning = 0x0008, // Start in 0x0008, we had other non public flags in this enum before, + // so we'll start here just in case somebody used them. This flag is only + // valid when set for Assemblies. }; [System.AttributeUsageAttribute((System.AttributeTargets)(256))] public sealed partial class AccessedThroughPropertyAttribute : System.Attribute @@ -6550,14 +6551,14 @@ public partial class CompilationRelaxationsAttribute : System.Attribute { public CompilationRelaxationsAttribute(int relaxations) { } public int CompilationRelaxations { get { throw null; } } - public CompilationRelaxationsAttribute (System.Runtime.CompilerServices.CompilationRelaxations relaxations) { } + public CompilationRelaxationsAttribute(System.Runtime.CompilerServices.CompilationRelaxations relaxations) { } } [System.AttributeUsageAttribute((System.AttributeTargets)(32767), Inherited = true)] public sealed partial class CompilerGeneratedAttribute : System.Attribute { public CompilerGeneratedAttribute() { } } - public sealed partial class ConditionalWeakTable : System.Collections.Generic.IEnumerable> where TKey : class where TValue : class + public sealed partial class ConditionalWeakTable : System.Collections.Generic.IEnumerable> where TKey : class where TValue : class { public ConditionalWeakTable() { } public void Add(TKey key, TValue value) { } @@ -6692,7 +6693,7 @@ public RuntimeCompatibilityAttribute() { } } public static partial class RuntimeHelpers { - public static new bool Equals(object o1, object o2) { throw null; } + public static new bool Equals(object o1, object o2) { throw null; } public static int OffsetToStringData { get { throw null; } } public static void EnsureSufficientExecutionStack() { } public static int GetHashCode(object o) { throw null; } @@ -6770,7 +6771,7 @@ public sealed partial class DefaultDependencyAttribute : System.Attribute public DefaultDependencyAttribute(System.Runtime.CompilerServices.LoadHint loadHintArgument) { } public System.Runtime.CompilerServices.LoadHint LoadHint { get { throw null; } } } - [System.AttributeUsageAttribute((System.AttributeTargets)(1), AllowMultiple=true)] + [System.AttributeUsageAttribute((System.AttributeTargets)(1), AllowMultiple = true)] public sealed partial class DependencyAttribute : System.Attribute { public DependencyAttribute(string dependentAssemblyArgument, System.Runtime.CompilerServices.LoadHint loadHintArgument) { } @@ -6781,7 +6782,7 @@ public partial class DiscardableAttribute : System.Attribute { public DiscardableAttribute() { } } - public enum LoadHint + public enum LoadHint { Always = 1, Default = 0, @@ -6809,7 +6810,7 @@ internal RuntimeWrappedException() { } public object WrappedException { get { throw null; } } public override void GetObjectData(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) { } } - [System.AttributeUsageAttribute((System.AttributeTargets)(1), Inherited=false)] + [System.AttributeUsageAttribute((System.AttributeTargets)(1), Inherited = false)] public sealed partial class StringFreezingAttribute : System.Attribute { public StringFreezingAttribute() { } @@ -6830,7 +6831,7 @@ internal ExceptionDispatchInfo() { } public void Throw() { } public static void Throw(Exception source) { } } - [System.AttributeUsageAttribute((System.AttributeTargets)(64), AllowMultiple=false, Inherited=false)] + [System.AttributeUsageAttribute((System.AttributeTargets)(64), AllowMultiple = false, Inherited = false)] public sealed partial class HandleProcessCorruptedStateExceptionsAttribute : System.Attribute { public HandleProcessCorruptedStateExceptionsAttribute() { } @@ -6866,7 +6867,7 @@ public FieldOffsetAttribute(int offset) { } public partial struct GCHandle { public bool IsAllocated { get { throw null; } } - public object Target {get { throw null; } set { } } + public object Target { get { throw null; } set { } } public System.IntPtr AddrOfPinnedObject() { throw null; } public static System.Runtime.InteropServices.GCHandle Alloc(object value) { throw null; } public static System.Runtime.InteropServices.GCHandle Alloc(object value, System.Runtime.InteropServices.GCHandleType type) { throw null; } @@ -7118,7 +7119,7 @@ public CryptographicException(string format, string insert) { } namespace System.Security { - [System.AttributeUsageAttribute((System.AttributeTargets)(1), AllowMultiple=false, Inherited=false)] + [System.AttributeUsageAttribute((System.AttributeTargets)(1), AllowMultiple = false, Inherited = false)] public sealed partial class AllowPartiallyTrustedCallersAttribute : System.Attribute { public AllowPartiallyTrustedCallersAttribute() { } @@ -7129,7 +7130,7 @@ public enum PartialTrustVisibilityLevel NotVisibleByDefault = 1, VisibleToAllHosts = 0, } - [System.AttributeUsageAttribute((System.AttributeTargets)(5501), AllowMultiple=false, Inherited=false)] + [System.AttributeUsageAttribute((System.AttributeTargets)(5501), AllowMultiple = false, Inherited = false)] public sealed partial class SecurityCriticalAttribute : System.Attribute { public SecurityCriticalAttribute() { } @@ -7166,7 +7167,7 @@ public SecurityException(string message, System.Type type, string state) { } public override void GetObjectData(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) { } public override string ToString() { throw null; } } - [System.AttributeUsageAttribute((System.AttributeTargets)(1), AllowMultiple=false)] + [System.AttributeUsageAttribute((System.AttributeTargets)(1), AllowMultiple = false)] public sealed partial class SecurityRulesAttribute : System.Attribute { public SecurityRulesAttribute(System.Security.SecurityRuleSet ruleSet) { } @@ -7179,28 +7180,28 @@ public enum SecurityRuleSet : byte Level2 = (byte)2, None = (byte)0, } - [System.AttributeUsageAttribute((System.AttributeTargets)(5500), AllowMultiple=false, Inherited=false)] + [System.AttributeUsageAttribute((System.AttributeTargets)(5500), AllowMultiple = false, Inherited = false)] public sealed partial class SecuritySafeCriticalAttribute : System.Attribute { public SecuritySafeCriticalAttribute() { } } - [System.AttributeUsageAttribute((System.AttributeTargets)(1), AllowMultiple=false, Inherited=false)] + [System.AttributeUsageAttribute((System.AttributeTargets)(1), AllowMultiple = false, Inherited = false)] public sealed partial class SecurityTransparentAttribute : System.Attribute { public SecurityTransparentAttribute() { } } - [System.AttributeUsageAttribute((System.AttributeTargets)(5501), AllowMultiple=false, Inherited=false)] + [System.AttributeUsageAttribute((System.AttributeTargets)(5501), AllowMultiple = false, Inherited = false)] [System.ObsoleteAttribute("SecurityTreatAsSafe is only used for .NET 2.0 transparency compatibility. Please use the SecuritySafeCriticalAttribute instead.")] public sealed partial class SecurityTreatAsSafeAttribute : System.Attribute { public SecurityTreatAsSafeAttribute() { } } - [System.AttributeUsageAttribute((System.AttributeTargets)(5188), AllowMultiple=true, Inherited=false)] + [System.AttributeUsageAttribute((System.AttributeTargets)(5188), AllowMultiple = true, Inherited = false)] public sealed partial class SuppressUnmanagedCodeSecurityAttribute : System.Attribute { public SuppressUnmanagedCodeSecurityAttribute() { } } - [System.AttributeUsageAttribute((System.AttributeTargets)(2), AllowMultiple=true, Inherited=false)] + [System.AttributeUsageAttribute((System.AttributeTargets)(2), AllowMultiple = true, Inherited = false)] public sealed partial class UnverifiableCodeAttribute : System.Attribute { public UnverifiableCodeAttribute() { } From de72cac9cdfdf981fa4d999035552bf706d1034a Mon Sep 17 00:00:00 2001 From: ahsonkhan Date: Wed, 6 Dec 2017 18:24:04 -0800 Subject: [PATCH 9/9] Cleaning up leftover unused using directives and extra spaces --- src/System.Memory/tests/Base64/Base64DecoderUnitTests.cs | 1 - src/System.Memory/tests/Base64/Base64EncoderUnitTests.cs | 1 - src/System.Memory/tests/Binary/BinaryReaderUnitTests.cs | 1 - src/System.Memory/tests/Binary/BinaryWriterUnitTests.cs | 3 --- src/System.Memory/tests/Memory/CopyTo.cs | 1 - .../ParsersAndFormatters/Formatter/FormatterTestData.cs | 8 -------- .../ParsersAndFormatters/Formatter/TestData.Formatter.cs | 6 ------ .../ParsersAndFormatters/Formatter/ValidateFormatter.cs | 3 --- .../tests/ParsersAndFormatters/Parser/ParserTestData.cs | 7 ------- .../Parser/ParserTests.2gbOverflow.cs | 3 --- .../ParsersAndFormatters/Parser/ParserTests.Negative.cs | 4 ---- .../tests/ParsersAndFormatters/Parser/ParserTests.cs | 4 ---- .../Parser/TestData.Parser.Boolean.cs | 8 -------- .../ParsersAndFormatters/Parser/TestData.Parser.Date.cs | 8 -------- .../Parser/TestData.Parser.DecimalsAndFloats.cs | 2 -- .../ParsersAndFormatters/Parser/TestData.Parser.Guid.cs | 3 --- .../Parser/TestData.Parser.Integer.cs | 3 --- .../Parser/TestData.Parser.TimeSpan.cs | 6 ------ .../tests/ParsersAndFormatters/Parser/TestData.Parser.cs | 6 ------ .../tests/ParsersAndFormatters/Parser/ValidateParser.cs | 4 ---- .../tests/ParsersAndFormatters/PseudoDateTime.cs | 8 -------- .../tests/ParsersAndFormatters/StandardFormatTests.cs | 2 -- src/System.Memory/tests/ParsersAndFormatters/TestUtils.cs | 5 ----- src/System.Memory/tests/ReadOnlyMemory/CopyTo.cs | 1 - src/System.Memory/tests/ReadOnlySpan/LastIndexOf.byte.cs | 1 - src/System.Memory/tests/Span/LastIndexOf.byte.cs | 1 - 26 files changed, 100 deletions(-) diff --git a/src/System.Memory/tests/Base64/Base64DecoderUnitTests.cs b/src/System.Memory/tests/Base64/Base64DecoderUnitTests.cs index c7031c7da5f4..15a673306025 100644 --- a/src/System.Memory/tests/Base64/Base64DecoderUnitTests.cs +++ b/src/System.Memory/tests/Base64/Base64DecoderUnitTests.cs @@ -2,7 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using System.Buffers; using System.Text; using Xunit; diff --git a/src/System.Memory/tests/Base64/Base64EncoderUnitTests.cs b/src/System.Memory/tests/Base64/Base64EncoderUnitTests.cs index f43481a27a60..c3f5335106ea 100644 --- a/src/System.Memory/tests/Base64/Base64EncoderUnitTests.cs +++ b/src/System.Memory/tests/Base64/Base64EncoderUnitTests.cs @@ -2,7 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using System.Buffers; using System.Text; using Xunit; diff --git a/src/System.Memory/tests/Binary/BinaryReaderUnitTests.cs b/src/System.Memory/tests/Binary/BinaryReaderUnitTests.cs index cc078c1948df..7fc1502fbc28 100644 --- a/src/System.Memory/tests/Binary/BinaryReaderUnitTests.cs +++ b/src/System.Memory/tests/Binary/BinaryReaderUnitTests.cs @@ -7,7 +7,6 @@ using Xunit; using static System.Buffers.Binary.BinaryPrimitives; -using static System.TestHelpers; namespace System.Buffers.Binary.Tests { diff --git a/src/System.Memory/tests/Binary/BinaryWriterUnitTests.cs b/src/System.Memory/tests/Binary/BinaryWriterUnitTests.cs index 6d02d35eb11a..efd6d2be2f8f 100644 --- a/src/System.Memory/tests/Binary/BinaryWriterUnitTests.cs +++ b/src/System.Memory/tests/Binary/BinaryWriterUnitTests.cs @@ -2,12 +2,9 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; using Xunit; using static System.Buffers.Binary.BinaryPrimitives; -using static System.TestHelpers; namespace System.Buffers.Binary.Tests { diff --git a/src/System.Memory/tests/Memory/CopyTo.cs b/src/System.Memory/tests/Memory/CopyTo.cs index 8305710d3767..1cb36761e764 100644 --- a/src/System.Memory/tests/Memory/CopyTo.cs +++ b/src/System.Memory/tests/Memory/CopyTo.cs @@ -2,7 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using System.Runtime.CompilerServices; using Xunit; namespace System.MemoryTests diff --git a/src/System.Memory/tests/ParsersAndFormatters/Formatter/FormatterTestData.cs b/src/System.Memory/tests/ParsersAndFormatters/Formatter/FormatterTestData.cs index ac777162282c..fdab0b5d7000 100644 --- a/src/System.Memory/tests/ParsersAndFormatters/Formatter/FormatterTestData.cs +++ b/src/System.Memory/tests/ParsersAndFormatters/Formatter/FormatterTestData.cs @@ -2,14 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using System; -using System.Text; -using System.Numerics; -using System.Buffers.Text; -using System.Globalization; -using System.Collections.Generic; - -using Xunit; namespace System.Buffers.Text.Tests { diff --git a/src/System.Memory/tests/ParsersAndFormatters/Formatter/TestData.Formatter.cs b/src/System.Memory/tests/ParsersAndFormatters/Formatter/TestData.Formatter.cs index 36a36db89e11..632b12908f70 100644 --- a/src/System.Memory/tests/ParsersAndFormatters/Formatter/TestData.Formatter.cs +++ b/src/System.Memory/tests/ParsersAndFormatters/Formatter/TestData.Formatter.cs @@ -2,16 +2,10 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using System; -using System.Text; using System.Linq; -using System.Numerics; -using System.Buffers.Text; using System.Globalization; using System.Collections.Generic; -using Xunit; - namespace System.Buffers.Text.Tests { internal static partial class TestData diff --git a/src/System.Memory/tests/ParsersAndFormatters/Formatter/ValidateFormatter.cs b/src/System.Memory/tests/ParsersAndFormatters/Formatter/ValidateFormatter.cs index 236c0dc13f2c..a04d7ee833b9 100644 --- a/src/System.Memory/tests/ParsersAndFormatters/Formatter/ValidateFormatter.cs +++ b/src/System.Memory/tests/ParsersAndFormatters/Formatter/ValidateFormatter.cs @@ -4,9 +4,6 @@ using Xunit; -using System.Text; -using System.Linq; - namespace System.Buffers.Text.Tests { public static partial class FormatterTests diff --git a/src/System.Memory/tests/ParsersAndFormatters/Parser/ParserTestData.cs b/src/System.Memory/tests/ParsersAndFormatters/Parser/ParserTestData.cs index e6008305c9ed..ba80a7bfcead 100644 --- a/src/System.Memory/tests/ParsersAndFormatters/Parser/ParserTestData.cs +++ b/src/System.Memory/tests/ParsersAndFormatters/Parser/ParserTestData.cs @@ -2,14 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using System; using System.Text; -using System.Numerics; -using System.Buffers.Text; -using System.Globalization; -using System.Collections.Generic; - -using Xunit; namespace System.Buffers.Text.Tests { diff --git a/src/System.Memory/tests/ParsersAndFormatters/Parser/ParserTests.2gbOverflow.cs b/src/System.Memory/tests/ParsersAndFormatters/Parser/ParserTests.2gbOverflow.cs index 4cb6ca5e0905..6981d9ab8c06 100644 --- a/src/System.Memory/tests/ParsersAndFormatters/Parser/ParserTests.2gbOverflow.cs +++ b/src/System.Memory/tests/ParsersAndFormatters/Parser/ParserTests.2gbOverflow.cs @@ -3,9 +3,6 @@ // See the LICENSE file in the project root for more information. using System.Collections.Generic; -using System.Text; -using System.Linq; -using System.Runtime.InteropServices; using System.Runtime.CompilerServices; using AllocationHelper = System.SpanTests.AllocationHelper; diff --git a/src/System.Memory/tests/ParsersAndFormatters/Parser/ParserTests.Negative.cs b/src/System.Memory/tests/ParsersAndFormatters/Parser/ParserTests.Negative.cs index 79754d9bf8e0..e8b4c981e1c5 100644 --- a/src/System.Memory/tests/ParsersAndFormatters/Parser/ParserTests.Negative.cs +++ b/src/System.Memory/tests/ParsersAndFormatters/Parser/ParserTests.Negative.cs @@ -2,10 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using System.Collections.Generic; -using System.Text; -using System.Linq; - using Xunit; namespace System.Buffers.Text.Tests diff --git a/src/System.Memory/tests/ParsersAndFormatters/Parser/ParserTests.cs b/src/System.Memory/tests/ParsersAndFormatters/Parser/ParserTests.cs index c2ddc2ef1ab8..1da5faf7a1c0 100644 --- a/src/System.Memory/tests/ParsersAndFormatters/Parser/ParserTests.cs +++ b/src/System.Memory/tests/ParsersAndFormatters/Parser/ParserTests.cs @@ -2,10 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using System.Collections.Generic; -using System.Text; -using System.Linq; - using Xunit; namespace System.Buffers.Text.Tests diff --git a/src/System.Memory/tests/ParsersAndFormatters/Parser/TestData.Parser.Boolean.cs b/src/System.Memory/tests/ParsersAndFormatters/Parser/TestData.Parser.Boolean.cs index 289638ab70d2..44d2333bec9e 100644 --- a/src/System.Memory/tests/ParsersAndFormatters/Parser/TestData.Parser.Boolean.cs +++ b/src/System.Memory/tests/ParsersAndFormatters/Parser/TestData.Parser.Boolean.cs @@ -2,16 +2,8 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using System; -using System.Text; -using System.Linq; -using System.Numerics; -using System.Buffers.Text; -using System.Globalization; using System.Collections.Generic; -using Xunit; - namespace System.Buffers.Text.Tests { internal static partial class TestData diff --git a/src/System.Memory/tests/ParsersAndFormatters/Parser/TestData.Parser.Date.cs b/src/System.Memory/tests/ParsersAndFormatters/Parser/TestData.Parser.Date.cs index 36eb81f6f197..336952d20f71 100644 --- a/src/System.Memory/tests/ParsersAndFormatters/Parser/TestData.Parser.Date.cs +++ b/src/System.Memory/tests/ParsersAndFormatters/Parser/TestData.Parser.Date.cs @@ -2,16 +2,8 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using System; -using System.Text; -using System.Linq; -using System.Numerics; -using System.Buffers.Text; -using System.Globalization; using System.Collections.Generic; -using Xunit; - namespace System.Buffers.Text.Tests { internal static partial class TestData diff --git a/src/System.Memory/tests/ParsersAndFormatters/Parser/TestData.Parser.DecimalsAndFloats.cs b/src/System.Memory/tests/ParsersAndFormatters/Parser/TestData.Parser.DecimalsAndFloats.cs index 9050d90c052f..5e7b079251ea 100644 --- a/src/System.Memory/tests/ParsersAndFormatters/Parser/TestData.Parser.DecimalsAndFloats.cs +++ b/src/System.Memory/tests/ParsersAndFormatters/Parser/TestData.Parser.DecimalsAndFloats.cs @@ -2,8 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using System; -using System.Text; using System.Linq; using System.Globalization; using System.Collections.Generic; diff --git a/src/System.Memory/tests/ParsersAndFormatters/Parser/TestData.Parser.Guid.cs b/src/System.Memory/tests/ParsersAndFormatters/Parser/TestData.Parser.Guid.cs index b63a43111459..bd2216652e7d 100644 --- a/src/System.Memory/tests/ParsersAndFormatters/Parser/TestData.Parser.Guid.cs +++ b/src/System.Memory/tests/ParsersAndFormatters/Parser/TestData.Parser.Guid.cs @@ -2,9 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using System; -using System.Text; -using System.Linq; using System.Globalization; using System.Collections.Generic; diff --git a/src/System.Memory/tests/ParsersAndFormatters/Parser/TestData.Parser.Integer.cs b/src/System.Memory/tests/ParsersAndFormatters/Parser/TestData.Parser.Integer.cs index ad6840dddd68..8e12d876b3df 100644 --- a/src/System.Memory/tests/ParsersAndFormatters/Parser/TestData.Parser.Integer.cs +++ b/src/System.Memory/tests/ParsersAndFormatters/Parser/TestData.Parser.Integer.cs @@ -2,11 +2,8 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using System; -using System.Text; using System.Linq; using System.Numerics; -using System.Globalization; using System.Collections.Generic; namespace System.Buffers.Text.Tests diff --git a/src/System.Memory/tests/ParsersAndFormatters/Parser/TestData.Parser.TimeSpan.cs b/src/System.Memory/tests/ParsersAndFormatters/Parser/TestData.Parser.TimeSpan.cs index 07b5d015f1c7..74fb80974460 100644 --- a/src/System.Memory/tests/ParsersAndFormatters/Parser/TestData.Parser.TimeSpan.cs +++ b/src/System.Memory/tests/ParsersAndFormatters/Parser/TestData.Parser.TimeSpan.cs @@ -2,16 +2,10 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using System; using System.Text; using System.Linq; -using System.Numerics; -using System.Buffers.Text; -using System.Globalization; using System.Collections.Generic; -using Xunit; - namespace System.Buffers.Text.Tests { internal static partial class TestData diff --git a/src/System.Memory/tests/ParsersAndFormatters/Parser/TestData.Parser.cs b/src/System.Memory/tests/ParsersAndFormatters/Parser/TestData.Parser.cs index 2b96ca064378..b84c0aaf904b 100644 --- a/src/System.Memory/tests/ParsersAndFormatters/Parser/TestData.Parser.cs +++ b/src/System.Memory/tests/ParsersAndFormatters/Parser/TestData.Parser.cs @@ -2,16 +2,10 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using System; -using System.Text; using System.Linq; -using System.Numerics; -using System.Buffers.Text; using System.Globalization; using System.Collections.Generic; -using Xunit; - namespace System.Buffers.Text.Tests { internal static partial class TestData diff --git a/src/System.Memory/tests/ParsersAndFormatters/Parser/ValidateParser.cs b/src/System.Memory/tests/ParsersAndFormatters/Parser/ValidateParser.cs index 4007bd336b75..9e2d49b00990 100644 --- a/src/System.Memory/tests/ParsersAndFormatters/Parser/ValidateParser.cs +++ b/src/System.Memory/tests/ParsersAndFormatters/Parser/ValidateParser.cs @@ -2,11 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using Xunit; - -using System.Text; using System.Linq; -using System.Globalization; namespace System.Buffers.Text.Tests { diff --git a/src/System.Memory/tests/ParsersAndFormatters/PseudoDateTime.cs b/src/System.Memory/tests/ParsersAndFormatters/PseudoDateTime.cs index 930a86c2dddb..b6cb04b98923 100644 --- a/src/System.Memory/tests/ParsersAndFormatters/PseudoDateTime.cs +++ b/src/System.Memory/tests/ParsersAndFormatters/PseudoDateTime.cs @@ -2,14 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using System; -using System.Text; -using System.Numerics; -using System.Buffers.Text; -using System.Globalization; -using System.Collections.Generic; - -using Xunit; namespace System.Buffers.Text.Tests { diff --git a/src/System.Memory/tests/ParsersAndFormatters/StandardFormatTests.cs b/src/System.Memory/tests/ParsersAndFormatters/StandardFormatTests.cs index 8eb8d27500f6..4bdc5f918b59 100644 --- a/src/System.Memory/tests/ParsersAndFormatters/StandardFormatTests.cs +++ b/src/System.Memory/tests/ParsersAndFormatters/StandardFormatTests.cs @@ -3,8 +3,6 @@ // See the LICENSE file in the project root for more information. using System.Collections.Generic; -using System.Text; -using System.Linq; using Xunit; diff --git a/src/System.Memory/tests/ParsersAndFormatters/TestUtils.cs b/src/System.Memory/tests/ParsersAndFormatters/TestUtils.cs index 8d95c619fa7d..f02f6fefdf58 100644 --- a/src/System.Memory/tests/ParsersAndFormatters/TestUtils.cs +++ b/src/System.Memory/tests/ParsersAndFormatters/TestUtils.cs @@ -2,14 +2,9 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using System; using System.Text; using System.Numerics; -using System.Buffers.Text; using System.Globalization; -using System.Collections.Generic; - -using Xunit; namespace System.Buffers.Text.Tests { diff --git a/src/System.Memory/tests/ReadOnlyMemory/CopyTo.cs b/src/System.Memory/tests/ReadOnlyMemory/CopyTo.cs index 0229cecce95e..319840d52cdb 100644 --- a/src/System.Memory/tests/ReadOnlyMemory/CopyTo.cs +++ b/src/System.Memory/tests/ReadOnlyMemory/CopyTo.cs @@ -2,7 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using System.Runtime.CompilerServices; using Xunit; namespace System.MemoryTests diff --git a/src/System.Memory/tests/ReadOnlySpan/LastIndexOf.byte.cs b/src/System.Memory/tests/ReadOnlySpan/LastIndexOf.byte.cs index 466dfcff2c06..37cecc6c8f3c 100644 --- a/src/System.Memory/tests/ReadOnlySpan/LastIndexOf.byte.cs +++ b/src/System.Memory/tests/ReadOnlySpan/LastIndexOf.byte.cs @@ -3,7 +3,6 @@ // See the LICENSE file in the project root for more information. using System.Numerics; -using System.Text; using Xunit; namespace System.SpanTests diff --git a/src/System.Memory/tests/Span/LastIndexOf.byte.cs b/src/System.Memory/tests/Span/LastIndexOf.byte.cs index a741d8419ac3..93582c6ed027 100644 --- a/src/System.Memory/tests/Span/LastIndexOf.byte.cs +++ b/src/System.Memory/tests/Span/LastIndexOf.byte.cs @@ -3,7 +3,6 @@ // See the LICENSE file in the project root for more information. using System.Numerics; -using System.Text; using Xunit; namespace System.SpanTests