This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author serhiy.storchaka
Recipients rhettinger, serhiy.storchaka
Date 2015-07-07.08:38:25
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1436258306.82.0.639469494764.issue24582@psf.upfronthosting.co.za>
In-reply-to
Content
For now multiple set functions call helpers that returns one of three possible values (0, 1, and -1 for error) and then analyze return code in the loop.

    while (...) {
        rv = some_set_operation();
        if (rv < 0) {
            // clean up
            return NULL;
        }
        if (rv) {
            other_set_operation();
        }
        // if (rv == 0) do nothing
    }

If rv is 0 or 1, it is tested two times. If rv is -1 (unlikely), it is tested only once.

It is possible to rewrite testing in other way:

    while (...) {
        rv = some_set_operation();
        if (rv != 0) { // 1 or -1
            if (rv < 0) {
                // clean up
                return NULL;
            }
            other_set_operation();
        }
    }

Now if rv is 0 (common case), it is tested only once, and likely the test jump will be merged with unconditional loop jump.

I have no benchmarking results, but I suppose that such rewritting will generate better machine code.
History
Date User Action Args
2015-07-07 08:38:26serhiy.storchakasetrecipients: + serhiy.storchaka, rhettinger
2015-07-07 08:38:26serhiy.storchakasetmessageid: <1436258306.82.0.639469494764.issue24582@psf.upfronthosting.co.za>
2015-07-07 08:38:26serhiy.storchakalinkissue24582 messages
2015-07-07 08:38:26serhiy.storchakacreate