Greg Ewing wrote:
> Walter Dörwald wrote:
>> Greg Ewing wrote:
>>> It would be less efficient in the cases where you don't
>>> need to check for NULL and/or clear the reference
>>> afterwards.
>>
>> Both should be optimized away by the compiler.
> 
> How? I don't see how the compiler can know either of
> those things.

The "checking for NULL" scenario looks somewhat like this:

PyObject *foo = NULL;
foo = get_foo();
if (foo)
    do something useful
else
    return;

if (foo)
    foo = NULL;

The compiler should be able to detect that the second foo check is 
redundant, if "do something useful" doesn't use foo.

And the "clearing the reference" scenario should look ike this:

{
     PyObject *foo = get_foo();
     do something useful
     foo = NULL;
}

The compiler should be able to detect that foo isn't used any more after 
the last assignment, so the assignment can be optimized away.

Servus,
    Walter
_______________________________________________
Python-3000 mailing list
Python-3000@python.org
http://mail.python.org/mailman/listinfo/python-3000
Unsubscribe: 
http://mail.python.org/mailman/options/python-3000/archive%40mail-archive.com

Reply via email to