[Python-Dev] String views (original) (raw)

Greg Ewing greg.ewing at canterbury.ac.nz
Thu Sep 1 05:56:11 CEST 2005


skip at pobox.com wrote:

If I then wanted to see what scheme's value compared to, the string's comparison method would have to recognize that it wasn't truly NUL-terminated, copy it, call strncmp() or whatever underlying routine is used for string comparisons.

Python string comparisons can't be using anything that relies on nul-termination, because Python strings can contain embedded nuls. Possibly it uses memcmp(), but that takes a length.

You have a point when it comes to passing strings to other C routines, though. For those that don't have a variant which takes a maximum length, the substring type might have to keep a cached nul-terminated copy created on demand. Then the copying overhead would only be incurred if you did happen to pass a substring to such a routine.

Greg



More information about the Python-Dev mailing list