[issue4896] Faster why variable manipulation in ceval.c

Skip Montanaro report at bugs.python.org
Fri Jan 9 15:31:53 CET 2009


New submission from Skip Montanaro <skip at pobox.com>:

The why_code enum in ceval.c has values which form a bit set.  Comparison of
the why variable against multiple values is going to be faster using bitwise
operations instead of logical ones.  For example, instead of

    why == WHY_RETURN || why == WHY_CONTINUE

the equivalent bitwise expression is

    why & (WHY_RETURN | WHY_CONTINUE)

which has fewer operations (one vs three treating the rhs of & as a
constant).  This is already done in one place.  The attached patch converts
all other expressions of the first form.

Also, there are some further manipulations of why in the loop after the
fast_block_end.  The loop can only be entered if why != WHY_NOT.  In the
loop when it is set to WHY_NOT, the loop breaks.  There is thus no reason to
test its value in the while expression.  Further, instead of just breaking
from the loop and then checking the why != WHY_NOT again, just jump past
that check by adding a why_not_here label.

The attached patch implements these changes (against the py3k branch).  All
tests pass on my Mac except test_cmd_line (which has been failing for
awhile).

Skip

----------
files: unnamed
messages: 79470
nosy: skip.montanaro
severity: normal
status: open
title: Faster why variable manipulation in ceval.c
Added file: http://bugs.python.org/file12667/unnamed

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue4896>
_______________________________________
-------------- next part --------------
A non-text attachment was scrubbed...
Name: unnamed
Type: application/octet-stream
Size: 2431 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/python-bugs-list/attachments/20090109/72c62241/attachment.obj>


More information about the Python-bugs-list mailing list