mirror of
https://github.com/python/cpython.git
synced 2025-10-06 23:21:06 +00:00
Close #16757: Avoid calling the expensive _PyUnicode_FindMaxChar() function
when possible
This commit is contained in:
parent
cfc4c13b04
commit
eb4b5ac8af
2 changed files with 15 additions and 8 deletions
|
@ -771,9 +771,13 @@ format_string_internal(PyObject *value, const InternalFormatSpec *format,
|
|||
|
||||
calc_padding(len, format->width, format->align, &lpad, &rpad, &total);
|
||||
|
||||
maxchar = _PyUnicode_FindMaxChar(value, 0, len);
|
||||
maxchar = writer->maxchar;
|
||||
if (lpad != 0 || rpad != 0)
|
||||
maxchar = Py_MAX(maxchar, format->fill_char);
|
||||
if (PyUnicode_MAX_CHAR_VALUE(value) > maxchar) {
|
||||
Py_UCS4 valmaxchar = _PyUnicode_FindMaxChar(value, 0, len);
|
||||
maxchar = Py_MAX(maxchar, valmaxchar);
|
||||
}
|
||||
|
||||
/* allocate the resulting string */
|
||||
if (_PyUnicodeWriter_Prepare(writer, total, maxchar) == -1)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue