diff options
author | Victor Stinner <victor.stinner@gmail.com> | 2012-10-01 22:33:47 (GMT) |
---|---|---|
committer | Victor Stinner <victor.stinner@gmail.com> | 2012-10-01 22:33:47 (GMT) |
commit | 621ef3d84f842a10dc9cb2af5ab9555b1663b79e (patch) | |
tree | 8f7553021772f75f5abb239eeee36246aabf6319 /Python/formatter_unicode.c | |
parent | fd0d3e5d25cf9dcb751a329cf390388e0dbd8da2 (diff) | |
download | cpython-621ef3d84f842a10dc9cb2af5ab9555b1663b79e.zip cpython-621ef3d84f842a10dc9cb2af5ab9555b1663b79e.tar.gz cpython-621ef3d84f842a10dc9cb2af5ab9555b1663b79e.tar.bz2 |
Issue #15609: Optimize str%args for integer argument
- Use _PyLong_FormatWriter() instead of formatlong() when possible, to avoid
a temporary buffer
- Enable the fast path when width is smaller or equals to the length,
and when the precision is bigger or equals to the length
- Add unit tests!
- formatlong() uses PyUnicode_Resize() instead of _PyUnicode_FromASCII()
to resize the output string
Diffstat (limited to 'Python/formatter_unicode.c')
-rw-r--r-- | Python/formatter_unicode.c | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/Python/formatter_unicode.c b/Python/formatter_unicode.c index aa62502..0ce9862 100644 --- a/Python/formatter_unicode.c +++ b/Python/formatter_unicode.c @@ -757,7 +757,8 @@ format_string_internal(PyObject *value, const InternalFormatSpec *format, goto done; } - if (format->width == -1 && format->precision == -1) { + if ((format->width == -1 || format->width <= len) + && (format->precision == -1 || format->precision >= len)) { /* Fast path */ return _PyUnicodeWriter_WriteStr(writer, value); } |