[Python-Dev] cpython: Optimize _PyUnicode_FastCopyCharacters() when maxchar(from) (original) (raw)

Antoine Pitrou solipsis at pitrou.net
Sat Jun 16 10:23:30 CEST 2012


On Sat, 16 Jun 2012 02:29:09 +0200 victor.stinner <python-checkins at python.org> wrote:

+ if (fromkind == tokind) { + if (!PyUnicodeISASCII(from) && PyUnicodeISASCII(to)) { + /* Writing Latin-1 characters into an ASCII string requires to + check that all written characters are pure ASCII */ +#ifndef PyDEBUG + if (checkmaxchar) { + PyUCS4 maxchar; + maxchar = ucs1libfindmaxchar(fromdata, + (char*)fromdata + howmany); + if (maxchar >= 128) + return -1; + } +#else + const PyUCS4 tomaxchar = PyUnicodeMAXCHARVALUE(to); + PyUCS4 ch; + Pyssizet i; + for (i=0; i < howmany; i++) { + ch = PyUnicodeREAD(fromkind, fromdata, fromstart + i); + assert(ch <= tomaxchar); + } +#endif

So you're returning -1 in release mode but you're crashing (assert()) in debug mode? Why that?

+#ifndef PyDEBUG + if (!checkmaxchar) { [...]

This means the optimizations are not exercised in debug mode? That sounds like a bad idea.

Regards

Antoine.



More information about the Python-Dev mailing list