Comment by jovial_cavalier
Comment by jovial_cavalier 15 hours ago
So if a function dereferences a pointer, it doesn't make sense to check that it's not null inside the function?
Unless there's an actual performance implication, this is all purely a matter of taste. This is the kind of broadly true, narrowly false stuff that causes people to destroy codebases. "I can't write it this way, because I have to push ifs up and fors down!!!" It's a totally fake requirement, and it imposes a fake constraint on the design.
If there is a performance implication of moving the if into the callers or not, you can do it with an inline function.
Just like that, we effectively moved the if statement into 37 callers, where the compiler may be smart enough to hoist it out of a for loop when it sees that the pointer is never changed in the loop body, or to eliminate it entirely when it sees that the pointer cannot be null.