]> granicus.if.org Git - python/commit
Issue #16147: Rewrite PyUnicode_FromFormatV() to use _PyUnicodeWriter API
authorVictor Stinner <victor.stinner@gmail.com>
Sat, 6 Oct 2012 21:03:36 +0000 (23:03 +0200)
committerVictor Stinner <victor.stinner@gmail.com>
Sat, 6 Oct 2012 21:03:36 +0000 (23:03 +0200)
commite215d960be3c5e1457920c452dc8f94ebf42b159
tree6a48506e8fbe03543c0c258aab982c6a6af8558d
parent2a09b6e84955779dbc878c5a0679c41d84f5d021
Issue #16147: Rewrite PyUnicode_FromFormatV() to use _PyUnicodeWriter API

 * Simplify the code: replace 4 steps with one unique step using the
   _PyUnicodeWriter API. PyUnicode_Format() has the same design. It avoids to
   store intermediate results which require to allocate an array of pointers on
   the heap.
 * Use the _PyUnicodeWriter API for speed (and its convinient API):
   overallocate the buffer to reduce the number of "realloc()"
 * Implement "width" and "precision" in Python, don't rely on sprintf(). It
   avoids to need of a temporary buffer allocated on the heap: only use a small
   buffer allocated in the stack.
 * Add _PyUnicodeWriter_WriteCstr() function
 * Split PyUnicode_FromFormatV() into two functions: add
   unicode_fromformat_arg().
 * Inline parse_format_flags(): the format of an argument is now only parsed
   once, it's no more needed to have a subfunction.
 * Optimize PyUnicode_FromFormatV() for characters between two "%" arguments:
   search the next "%" and copy the substring in one chunk, instead of copying
   character per character.
Include/unicodeobject.h
Lib/test/test_unicode.py
Objects/unicodeobject.c