From 2b55b103e1dfb7c0afcc8042fd154be345fb3744 Mon Sep 17 00:00:00 2001 From: Alex-ABWorld Date: Sat, 13 Mar 2021 03:26:57 +0000 Subject: [PATCH] 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. --- src/coreclr/vm/comdelegate.cpp | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/src/coreclr/vm/comdelegate.cpp b/src/coreclr/vm/comdelegate.cpp index 17235f9..abee693 100644 --- a/src/coreclr/vm/comdelegate.cpp +++ b/src/coreclr/vm/comdelegate.cpp @@ -1022,9 +1022,8 @@ FCIMPL5(FC_BOOL_RET, COMDelegate::BindToMethodInfo, Object* refThisUNSAFE, Objec FCIMPLEND // This method is called (in the late bound case only) once a target method has been decided on. All the consistency checks -// (signature matching etc.) have been done at this point and the only major reason we could fail now is on security grounds -// (someone trying to create a delegate over a method that's not visible to them for instance). This method will initialize the -// delegate (wrapping it in a wrapper delegate if necessary). Upon return the delegate should be ready for invocation. +// (signature matching etc.) have been done at this point, this method will simply initialize the delegate, with any required +// wrapping. The delegate returned will be ready for invocation immediately. void COMDelegate::BindToMethod(DELEGATEREF *pRefThis, OBJECTREF *pRefFirstArg, MethodDesc *pTargetMethod, @@ -1043,19 +1042,16 @@ void COMDelegate::BindToMethod(DELEGATEREF *pRefThis, } CONTRACTL_END; - // We might have to wrap the delegate in a wrapper delegate depending on the the target method. The following local - // keeps track of the real (i.e. non-wrapper) delegate whether or not this is required. + // The delegate may be put into a wrapper delegate if our target method requires it. This local + // will always hold the real (un-wrapped) delegate. DELEGATEREF refRealDelegate = NULL; GCPROTECT_BEGIN(refRealDelegate); - // If we didn't wrap the real delegate in a wrapper delegate then the real delegate is the one passed in. - if (refRealDelegate == NULL) - { - if (NeedsWrapperDelegate(pTargetMethod)) - refRealDelegate = CreateWrapperDelegate(*pRefThis, pTargetMethod); - else - refRealDelegate = *pRefThis; - } + // If needed, convert the delegate into a wrapper and get the real delegate within that. + if (NeedsWrapperDelegate(pTargetMethod)) + refRealDelegate = CreateWrapperDelegate(*pRefThis, pTargetMethod); + else + refRealDelegate = *pRefThis; pTargetMethod->EnsureActive(); -- 2.7.4