[Python-3000] PEP 3137 plan of attack

Marcin ‘Qrczak’ Kowalczyk qrczak at knm.org.pl
Tue Oct 9 02:02:26 CEST 2007


Dnia 09-10-2007, Wt o godzinie 01:29 +0200, Christian Heimes pisze:

> I'm not happy with:
> 
>     static const char *quote_prefix = "buffer(b'";
>     p = PyUnicode_AS_UNICODE(v);
>     for (i=0; i<strlen(quote_prefix); i++) {
>         *p++ = quote_prefix[i];
>     }

strlen in a loop is bad for performance.

I would do:

   static const Py_UNICODE quote_prefix[] = {
      'b', 'u', 'f', 'f', 'e', 'r', '(', 'b', '\''
   };

and memcpy.

-- 
   __("<         Marcin Kowalczyk
   \__/       qrczak at knm.org.pl
    ^^     http://qrnik.knm.org.pl/~qrczak/



More information about the Python-3000 mailing list