optimization question

Andrew Koenig ark at research.att.com
Tue Aug 13 15:14:23 CEST 2002


Skip> In theory, I suppose that's true.  However, note that
Skip> performance of such a modified Python interpreter would probably
Skip> suffer, because any time the interpreter wanted to call a C
Skip> routine which expected a null-terminated string (e.g. strchr),
Skip> it would have to be copied first (or at least inspected using
Skip> the stored length), since any string's (and b's in particular)
Skip> internal representation wouldn't necessarily be null-terminated.
Skip> CPython's current implementation always null-terminates strings
Skip> to avoid copying.

Indeed.  The alternative technique -- replacing the character after the
substring with a zero character, calling the C routine, then putting the
original character back again, is too hair-raising to consider.

-- 
Andrew Koenig, ark at research.att.com, http://www.research.att.com/info/ark



More information about the Python-list mailing list