Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit a8cdb48

Browse files
jamesqojkotas
authored andcommitted
Better performance for MulticastDelegate.Equals (#6113)
Better performance for MulticastDelegate.Equals
1 parent ad40ed6 commit a8cdb48

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

src/mscorlib/src/System/MulticastDelegate.cs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ namespace System
77
using System;
88
using System.Reflection;
99
using System.Runtime;
10+
using System.Runtime.CompilerServices;
1011
using System.Runtime.Serialization;
1112
using System.Diagnostics.Contracts;
1213
using System.Reflection.Emit;
@@ -103,11 +104,18 @@ public override void GetObjectData(SerializationInfo info, StreamingContext cont
103104
[System.Security.SecuritySafeCritical] // auto-generated
104105
public override sealed bool Equals(Object obj)
105106
{
106-
if (obj == null || !InternalEqualTypes(this, obj))
107-
return false;
108-
MulticastDelegate d = obj as MulticastDelegate;
109-
if (d == null)
107+
if (obj == null)
110108
return false;
109+
if (object.ReferenceEquals(this, obj))
110+
return true;
111+
if (!InternalEqualTypes(this, obj))
112+
return false;
113+
114+
// Since this is a MulticastDelegate and we know
115+
// the types are the same, obj should also be a
116+
// MulticastDelegate
117+
Contract.Assert(obj is MulticastDelegate, "Shouldn't have failed here since we already checked the types are the same!");
118+
var d = JitHelpers.UnsafeCast<MulticastDelegate>(obj);
111119

112120
if (_invocationCount != (IntPtr)0)
113121
{

0 commit comments

Comments
 (0)