From 67d96fef950d9c3f1a46e030f70e41b5ac3d570e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20Strehovsk=C3=BD?= Date: Wed, 25 May 2022 10:42:19 +0900 Subject: [PATCH] Speed up ValueType.Equals Inspired by #69723 `SpanHelpers` didn't exist when this part of NativeAOT was written (https://github.com/dotnet/corert/pull/5436#discussion_r170412863). --- .../System.Private.CoreLib/src/System/ValueType.cs | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/coreclr/nativeaot/System.Private.CoreLib/src/System/ValueType.cs b/src/coreclr/nativeaot/System.Private.CoreLib/src/System/ValueType.cs index 7a1920d1fc1cb8..1b8333324d439b 100644 --- a/src/coreclr/nativeaot/System.Private.CoreLib/src/System/ValueType.cs +++ b/src/coreclr/nativeaot/System.Private.CoreLib/src/System/ValueType.cs @@ -64,11 +64,7 @@ public override bool Equals([NotNullWhen(true)] object? obj) // Compare the memory int valueTypeSize = (int)this.GetEETypePtr().ValueTypeSize; - for (int i = 0; i < valueTypeSize; i++) - { - if (Unsafe.Add(ref thisRawData, i) != Unsafe.Add(ref thatRawData, i)) - return false; - } + return SpanHelpers.SequenceEqual(ref thisRawData, ref thatRawData, valueTypeSize); } else {