diff options
author | Victor Stinner <victor.stinner@gmail.com> | 2013-04-03 00:02:33 (GMT) |
---|---|---|
committer | Victor Stinner <victor.stinner@gmail.com> | 2013-04-03 00:02:33 (GMT) |
commit | eb4b5ac8afd797622e769e5742844224cfcb73b2 (patch) | |
tree | 8285d7e7aa0382679624bbe5833967af1655c306 /Python/formatter_unicode.c | |
parent | cfc4c13b04223705a43595579b46020c9e876ac4 (diff) | |
download | cpython-eb4b5ac8afd797622e769e5742844224cfcb73b2.zip cpython-eb4b5ac8afd797622e769e5742844224cfcb73b2.tar.gz cpython-eb4b5ac8afd797622e769e5742844224cfcb73b2.tar.bz2 |
Close #16757: Avoid calling the expensive _PyUnicode_FindMaxChar() function
when possible
Diffstat (limited to 'Python/formatter_unicode.c')
-rw-r--r-- | Python/formatter_unicode.c | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/Python/formatter_unicode.c b/Python/formatter_unicode.c index 79fa469..009bc5f 100644 --- a/Python/formatter_unicode.c +++ b/Python/formatter_unicode.c @@ -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) |