mirror of
https://github.com/AdaCore/cpython.git
synced 2026-02-12 12:57:15 -08:00
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
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user