Skip to content

Commit 67d96fe

Browse files
Speed up ValueType.Equals
Inspired by #69723 `SpanHelpers` didn't exist when this part of NativeAOT was written (dotnet/corert#5436 (comment)).
1 parent cc7138d commit 67d96fe

1 file changed

Lines changed: 1 addition & 5 deletions

File tree

  • src/coreclr/nativeaot/System.Private.CoreLib/src/System

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,7 @@ public override bool Equals([NotNullWhen(true)] object? obj)
6464

6565
// Compare the memory
6666
int valueTypeSize = (int)this.GetEETypePtr().ValueTypeSize;
67-
for (int i = 0; i < valueTypeSize; i++)
68-
{
69-
if (Unsafe.Add(ref thisRawData, i) != Unsafe.Add(ref thatRawData, i))
70-
return false;
71-
}
67+
return SpanHelpers.SequenceEqual(ref thisRawData, ref thatRawData, valueTypeSize);
7268
}
7369
else
7470
{

0 commit comments

Comments
 (0)