From eb4b5ac8afd797622e769e5742844224cfcb73b2 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Wed, 3 Apr 2013 02:02:33 +0200 Subject: Close #16757: Avoid calling the expensive _PyUnicode_FindMaxChar() function when possible --- Python/formatter_unicode.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'Python/formatter_unicode.c') diff --git a/Python/formatter_unicode.c b/Python/formatter_unicode.c index 79fa469697..009bc5fd03 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) -- cgit v1.2.1