mirror of
https://github.com/python/cpython.git
synced 2025-08-22 17:55:18 +00: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:
parent
fd0d3e5d25
commit
621ef3d84f
3 changed files with 119 additions and 68 deletions
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue