Match beginning of two strings

Alex Martelli aleax at
Tue Aug 5 00:27:43 CEST 2003

Richie Hindle wrote:
> output leads you to: you can use strlen rather than Python's len:

...IF somebody absolutely ensures you that the Python strings contain
no nulls.  I do not recall any such guarantee in the original thread,
therefore it does not seem to me that this optimization is warranted.

> Over ten times quicker than the original, for the sake of a couple of
> small tweaks driven by looking at the C output.  Although the C still
> looks very verbose at first glance, it's now substantially the same as
> Alex's cexa.c.

Impressive!  But IMHO a way must be found to use the actual lengths
of the Python strings, as cexa.c did, rather than assuming that the
Python strings contain no nulls.  Perhaps this can be done by direct
use of PyString_AsStringAndSize?


More information about the Python-list mailing list