CnC_Remastered_Collection icon indicating copy to clipboard operation
CnC_Remastered_Collection copied to clipboard

Removed unneeded conditional

Open hjerpbakk opened this issue 5 years ago • 5 comments

hjerpbakk avatar Jun 02 '20 17:06 hjerpbakk

That's not an unneeded conditional. It says if the damage value is zero the function returns zero.

Grinshpon avatar Jun 02 '20 21:06 Grinshpon

Grinshpon, the condition that follows immediately after checks for that again, so I'd say it's unnecessary.

Berzeger avatar Jun 02 '20 22:06 Berzeger

The original implementation could have been an optimisation, if the checks that follow were expensive to perform, allowing the function to return early before incurring that cost -- however this is probably irrelevant in 2020.

smbkr avatar Jun 03 '20 11:06 smbkr

This is not a performance improvement, but rather a removing of redundant code and brings this check to parity with https://github.com/electronicarts/CnC_Remastered_Collection/blob/d9e287e08b3e2fb3e46690d1029f90e3b17faf0f/TIBERIANDAWN/COMBAT.CPP#L75

hjerpbakk avatar Jun 03 '20 13:06 hjerpbakk

The original implementation could have been an optimisation, if the checks that follow were expensive to perform, allowing the function to return early before incurring that cost -- however this is probably irrelevant in 2020.

And even now one could get it back by simply swapping !damage to the front and early-out that way:

if ( !damage || Special.IsInert || warhead == WARHEAD_NONE ) return(0);

Sgt-Nukem avatar Jun 07 '20 10:06 Sgt-Nukem