Code that ought to run fast, but can't due to Python limitations.

Stefan Behnel stefan_ml at behnel.de
Sun Jul 5 12:04:43 CEST 2009


Paul Rubin wrote:
> Stefan Behnel writes:
>>> The series of tests is written that way because there is no case
>>> statement available.  It is essentially switching on a bunch of
>>> character constants and then doing some additional tests in each
>>> branch.
>> Although doing some of the tests first and then checking the input
>> conditionally might be faster here.
> 
> That is essentially what happens.  There are a bunch of tests of the
> form
>    if data=='<' and [some other stuff]: ...

That's what I meant. Some of the "other stuff" is redundant enough to do it
once at the beginning of the function (or even before entering the
function, by writing specialised methods), i.e. I'd (partially) reverse the
order of the "and" operands.

Stefan



More information about the Python-list mailing list