[issue14744] Use _PyUnicodeWriter API in str.format() internals

Serhiy Storchaka report at bugs.python.org
Tue May 8 12:38:53 CEST 2012

Serhiy Storchaka <storchaka at gmail.com> added the comment:

> "x={}".format(123) uses a temporary buffer for "123".

This, apparently, is inevitable. I doubt that it is able to considerably
optimize, not worsened str(int) (which is optimal for current
algorithm). Note that the more complex formatting (with width) will
still require the temporary buffer.

Be very careful not to cause regress.

>  Using
> _PyUnicodeWriter even to format 123 would avoid a malloc() and a copy of
> the characters.

Fill the ascii buffer and then copying can be cheaper than using
_PyUnicodeWriter with general non-ascii string.


Python tracker <report at bugs.python.org>

More information about the Python-bugs-list mailing list