summaryrefslogtreecommitdiffstats
path: root/Python/formatter_unicode.c
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2013-04-03 00:02:33 (GMT)
committerVictor Stinner <victor.stinner@gmail.com>2013-04-03 00:02:33 (GMT)
commiteb4b5ac8afd797622e769e5742844224cfcb73b2 (patch)
tree8285d7e7aa0382679624bbe5833967af1655c306 /Python/formatter_unicode.c
parentcfc4c13b04223705a43595579b46020c9e876ac4 (diff)
downloadcpython-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.c6
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)