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

Stefan Behnel stefan_ml at behnel.de
Sun Jul 5 06:06:49 EDT 2009


Paul Rubin wrote:
> Stefan Behnel writes:
>>>         # Keep a charbuffer to handle the escapeFlag
>>>         if self.contentModelFlag in\
>>>           (contentModelFlags["CDATA"], contentModelFlags["RCDATA"]):
>> Is the tuple
>> 	(contentModelFlags["CDATA"], contentModelFlags["RCDATA"])
>> constant? If that is the case, I'd cut it out into a class member ...
> 
> I think the main issue for that function comes after that if statement.
> There is a multi-way switch on a bunch of different possible character
> values.  I do agree with you that the first "if" can also be optimized.

You may notice that the creation of this exact tuple appears in almost all
if the conditionals of this method. So it is part of the bottleneck.

Stefan



More information about the Python-list mailing list