Steven D'Aprano <st...@remove-this-cybersource.com.au> writes: > Yes, I'm aware of that, but that's not what John's code is doing -- he's > doing a series of if expr ... elif expr tests. I don't think a case > statement can do much to optimize that.
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. It could be that using ord(c) as an index into a list of functions might be faster than a dict lookup on c to get a function. I think John is hoping to avoid a function call and instead get an indexed jump within the Python bytecode for the big function. -- http://mail.python.org/mailman/listinfo/python-list