Speed up ValueType.Equals (#69768)
authorMichal Strehovský <MichalStrehovsky@users.noreply.github.com>
Wed, 25 May 2022 03:58:08 +0000 (12:58 +0900)
committerGitHub <noreply@github.com>
Wed, 25 May 2022 03:58:08 +0000 (12:58 +0900)
Inspired by #69723

`SpanHelpers` didn't exist when this part of NativeAOT was written (https://github.com/dotnet/corert/pull/5436#discussion_r170412863).

src/coreclr/nativeaot/System.Private.CoreLib/src/System/ValueType.cs

index 7a1920d..1b83333 100644 (file)
@@ -64,11 +64,7 @@ namespace System
 
                 // 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
             {