[Zope-Coders] x.startswith() vs. x[ ..]

Fred L. Drake, Jr. fdrake@acm.org
Mon, 3 Dec 2001 11:47:34 -0500


Chris Withers writes:
 > Hmmm... I wonder if HTMLParser.py could benefit from use of these?

  Definately, but it's up to Evan to determine that we can do that.  I
think that would be acceptable on the Zope-3x-branch.  At least a
little could be saved by re-defining _contains_at() to be:

----------------------------------------------------------------------
def _contains_at(s, sub, pos):
    return s.startswith(sub, pos)
----------------------------------------------------------------------

  This has the advantage of not touching a lot of code, but still
avoids creating a temporary string object.  I've not measured the
performance change this may make, but it still passes the regression
tests.
  Changing the calls to _contains_at() to use startwith() directly
would be a more significant improvement since we get rid of the calls
to a Python function entirely, but make it harder to maintain
compatibility with Python 1.5.2.  This should not be a real problem on
the branch.
  Be aware that any changes to HTMLParser would only help the time
required to *compile* a Page Template; there would be no change to the
time taken to render the template.


  -Fred

-- 
Fred L. Drake, Jr.  <fdrake at acm.org>
PythonLabs at Zope Corporation