[Python-Dev] are NULL checks in Objects/abstract.c reallyneeded?
Thu, 13 Mar 2003 14:50:36 -0600
Raymond> Can we get most of the same benefit by using an assert() rather
Raymond> than NULL-->SystemError?
Jeremy> No. assert() causes the program to fail. SystemError() raises
Jeremy> an exception and lets the program keep going. Those are vastly
Jeremy> different effects.
It's not clear to me that you'd see any benefit anyway. The checking code
currently looks like this:
if (o == NULL)
If you changed it to use assert you'd have
assert(o != NULL);
which expands to
((o != NULL) ? 0 : __assert(...));
In the common case you still test for either o==NULL or o!=NULL. Unless one
test is terrifically faster than the other (and you executed it a helluva
lot) you wouldn't gain anything except the loss of the possibility (however
slim) that you might be able to recover.
Still, for people who's only desire is speed and are willing to sacrifice
checks to get it, perhaps we should have a --without-null-checks configure
flag. ;-) I bet if you were ruthless in eliminating checks (especially in
ceval.c) you would see an easily measurable speedup.