From 621ef3d84f842a10dc9cb2af5ab9555b1663b79e Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Tue, 2 Oct 2012 00:33:47 +0200 Subject: 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 --- Python/formatter_unicode.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'Python') 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); } -- cgit v1.2.1