Mercurial > cpython-lru_cache-weakref
diff Python/formatter_unicode.c @ 79390:559a430e563c
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
| author | Victor Stinner <victor.stinner@gmail.com> |
|---|---|
| date | Tue, 02 Oct 2012 00:33:47 +0200 |
| parents | dc2909a62262 |
| children | 10e59553a8de |
line wrap: on
line diff
--- a/Python/formatter_unicode.c Mon Oct 01 15:34:31 2012 -0700 +++ b/Python/formatter_unicode.c Tue Oct 02 00:33:47 2012 +0200 @@ -757,7 +757,8 @@ 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); }
