diff options
| author | Victor Stinner <victor.stinner@gmail.com> | 2012-10-02 00:33:47 +0200 |
|---|---|---|
| committer | Victor Stinner <victor.stinner@gmail.com> | 2012-10-02 00:33:47 +0200 |
| commit | 9b7dd8a6114201295c5dce3a6cd3d48550a88056 (patch) | |
| tree | adafefd8fa760691f69936c6f77f5bc20570bd19 /Python | |
| parent | 1b1b69e8ae410a99109c76f87f646603445ed2a9 (diff) | |
| download | cpython-9b7dd8a6114201295c5dce3a6cd3d48550a88056.tar.gz | |
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')
| -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 aa62502dbe..0ce9862a20 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); } |
