Skip to content

Commit 2b55b10

Browse files
Remove Redundant "If" Check (#49324)
Remove a redundant "NULL" check on a clearly NULL value, and corrected comments to correctly represent the current state of the function. There are no longer any security checks, and as such the mentions of it are also redundant and have been removed.
1 parent 98527b9 commit 2b55b10

File tree

1 file changed

+9
-13
lines changed

1 file changed

+9
-13
lines changed

src/coreclr/vm/comdelegate.cpp

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1022,9 +1022,8 @@ FCIMPL5(FC_BOOL_RET, COMDelegate::BindToMethodInfo, Object* refThisUNSAFE, Objec
10221022
FCIMPLEND
10231023

10241024
// This method is called (in the late bound case only) once a target method has been decided on. All the consistency checks
1025-
// (signature matching etc.) have been done at this point and the only major reason we could fail now is on security grounds
1026-
// (someone trying to create a delegate over a method that's not visible to them for instance). This method will initialize the
1027-
// delegate (wrapping it in a wrapper delegate if necessary). Upon return the delegate should be ready for invocation.
1025+
// (signature matching etc.) have been done at this point, this method will simply initialize the delegate, with any required
1026+
// wrapping. The delegate returned will be ready for invocation immediately.
10281027
void COMDelegate::BindToMethod(DELEGATEREF *pRefThis,
10291028
OBJECTREF *pRefFirstArg,
10301029
MethodDesc *pTargetMethod,
@@ -1043,19 +1042,16 @@ void COMDelegate::BindToMethod(DELEGATEREF *pRefThis,
10431042
}
10441043
CONTRACTL_END;
10451044

1046-
// We might have to wrap the delegate in a wrapper delegate depending on the the target method. The following local
1047-
// keeps track of the real (i.e. non-wrapper) delegate whether or not this is required.
1045+
// The delegate may be put into a wrapper delegate if our target method requires it. This local
1046+
// will always hold the real (un-wrapped) delegate.
10481047
DELEGATEREF refRealDelegate = NULL;
10491048
GCPROTECT_BEGIN(refRealDelegate);
10501049

1051-
// If we didn't wrap the real delegate in a wrapper delegate then the real delegate is the one passed in.
1052-
if (refRealDelegate == NULL)
1053-
{
1054-
if (NeedsWrapperDelegate(pTargetMethod))
1055-
refRealDelegate = CreateWrapperDelegate(*pRefThis, pTargetMethod);
1056-
else
1057-
refRealDelegate = *pRefThis;
1058-
}
1050+
// If needed, convert the delegate into a wrapper and get the real delegate within that.
1051+
if (NeedsWrapperDelegate(pTargetMethod))
1052+
refRealDelegate = CreateWrapperDelegate(*pRefThis, pTargetMethod);
1053+
else
1054+
refRealDelegate = *pRefThis;
10591055

10601056
pTargetMethod->EnsureActive();
10611057

0 commit comments

Comments
 (0)