I don't believe that all those
programmers were unaware of the fact
that delete 0; is safe.
Well, they were. That's pretty much it. It's a fact that delete
or free
on null
is perfectly safe. If they weren't unaware of it, then they wouldn't have wasted time checking for it.
So, I wonder that isn't it worth
assuming that null check before
delete/free would provide a
performance optimization by saving a
function call ?
You're making an assumption ... ... because what, you don't want to believe that those guys are wrong? Sorry, buddy- they were wrong, and that's that. You've got no evidence or rational reasons to believe that doing a null
check has such a benefit.
Or that whoever wrote that code thought so. After all, even if you could eliminate a function call this way, the cost of the function call here is miniscule, if it's not inlined, which it may well be, and it costs more for the programmer time to write the check, which is already written for you. I'd rather be over-zealous about correctness than prematurely optimize like this- are you genuinely doing anyone a favour by suggesting that it may be an optimization?