From edb7d7e30df3a61c82720ec377c3e53e5a8dbd97 Mon Sep 17 00:00:00 2001 From: Johan Lorensson Date: Mon, 29 Aug 2022 10:26:03 +0200 Subject: [PATCH] Use System.Numerics.IEqualityOperators.op_Equality in SpanHelper.T.cs where possible. (#74567) * Use System.Numerics.IEqualityOperators.op_Equality in SpanHelper.T.cs. Workaround crash hit by https://github.com/dotnet/runtime/issues/74179 making sure we avoid hitting codepath emitting this null pointer checks. The full fix includes codegen fixes as well, but will be performed in separate PR. There are still locations in SpanHelper.T.cs that uses Equal virtual call on value types that could be managed pointers to value types, but that code has remained the same for the last 4 years to 15 months and have not hit this issue in the past. * Re-enable globalization tests disabled in #74433. --- .../tests/CompareInfo/CompareInfoTests.IndexOf.cs | 1 - .../System.Globalization/tests/Invariant/InvariantMode.cs | 2 -- .../System.Private.CoreLib/src/System/SpanHelpers.T.cs | 4 ++-- 3 files changed, 2 insertions(+), 5 deletions(-) diff --git a/src/libraries/System.Globalization/tests/CompareInfo/CompareInfoTests.IndexOf.cs b/src/libraries/System.Globalization/tests/CompareInfo/CompareInfoTests.IndexOf.cs index fa12fb9cec5..58d66e93be6 100644 --- a/src/libraries/System.Globalization/tests/CompareInfo/CompareInfoTests.IndexOf.cs +++ b/src/libraries/System.Globalization/tests/CompareInfo/CompareInfoTests.IndexOf.cs @@ -183,7 +183,6 @@ public static IEnumerable IndexOf_U_WithDiaeresis_TestData() [MemberData(nameof(IndexOf_TestData))] [MemberData(nameof(IndexOf_Aesc_Ligature_TestData))] [MemberData(nameof(IndexOf_U_WithDiaeresis_TestData))] - [ActiveIssue("https://github.com/dotnet/runtime/issues/74179", TestRuntimes.Mono)] public void IndexOf_String(CompareInfo compareInfo, string source, string value, int startIndex, int count, CompareOptions options, int expected, int expectedMatchLength) { if (value.Length == 1) diff --git a/src/libraries/System.Globalization/tests/Invariant/InvariantMode.cs b/src/libraries/System.Globalization/tests/Invariant/InvariantMode.cs index 8416d0e3f7b..361c39ec427 100644 --- a/src/libraries/System.Globalization/tests/Invariant/InvariantMode.cs +++ b/src/libraries/System.Globalization/tests/Invariant/InvariantMode.cs @@ -864,7 +864,6 @@ private static StringComparison GetStringComparison(CompareOptions options) [ConditionalTheory(nameof(PredefinedCulturesOnlyIsDisabled))] [MemberData(nameof(IndexOf_TestData))] - [ActiveIssue("https://github.com/dotnet/runtime/issues/74179", TestRuntimes.Mono)] public void TestIndexOf(string source, string value, int startIndex, int count, CompareOptions options, int result) { foreach (string cul in s_cultureNames) @@ -912,7 +911,6 @@ static void TestCore(CompareInfo compareInfo, string source, string value, int s [ConditionalTheory(nameof(PredefinedCulturesOnlyIsDisabled))] [MemberData(nameof(LastIndexOf_TestData))] - [ActiveIssue("https://github.com/dotnet/runtime/issues/74179", TestRuntimes.Mono)] public void TestLastIndexOf(string source, string value, int startIndex, int count, CompareOptions options, int result) { foreach (string cul in s_cultureNames) diff --git a/src/libraries/System.Private.CoreLib/src/System/SpanHelpers.T.cs b/src/libraries/System.Private.CoreLib/src/System/SpanHelpers.T.cs index b093cb11a29..877c2131187 100644 --- a/src/libraries/System.Private.CoreLib/src/System/SpanHelpers.T.cs +++ b/src/libraries/System.Private.CoreLib/src/System/SpanHelpers.T.cs @@ -1498,7 +1498,7 @@ internal static int IndexOfChar(ref char searchSpace, char value, int length) { length -= 1; - if (TNegator.NegateIfNeeded(Unsafe.Add(ref searchSpace, offset).Equals(value))) return (int)offset; + if (TNegator.NegateIfNeeded(Unsafe.Add(ref searchSpace, offset) == value)) return (int)offset; offset += 1; } @@ -2145,7 +2145,7 @@ internal static int IndexOfAnyValueType(ref T searchSpace, T value0, T value1 { length -= 1; - if (TNegator.NegateIfNeeded(Unsafe.Add(ref searchSpace, offset).Equals(value))) return (int)offset; + if (TNegator.NegateIfNeeded(Unsafe.Add(ref searchSpace, offset) == value)) return (int)offset; offset -= 1; } -- GitLab