Commit b80e46ec authored by Victor Stinner's avatar Victor Stinner

Issue #14687: Avoid an useless duplicated string in PyUnicode_Format()

parent aff3cc65
...@@ -14051,20 +14051,16 @@ PyUnicode_Format(PyObject *format, PyObject *args) ...@@ -14051,20 +14051,16 @@ PyUnicode_Format(PyObject *format, PyObject *args)
} }
} }
/* Copy all characters, preserving len */ /* Copy all characters, preserving len */
if (temp != NULL) { if (pindex == 0 && len == PyUnicode_GET_LENGTH(temp)) {
assert(pbuf == PyUnicode_DATA(temp)); r = _PyAccu_Accumulate(&acc, temp);
v = PyUnicode_Substring(temp, pindex, pindex + len);
} }
else { else {
const char *p = (const char *) pbuf; v = PyUnicode_Substring(temp, pindex, pindex + len);
assert(pbuf != NULL); if (v == NULL)
p += kind * pindex; goto onError;
v = PyUnicode_FromKindAndData(kind, p, len); r = _PyAccu_Accumulate(&acc, v);
Py_DECREF(v);
} }
if (v == NULL)
goto onError;
r = _PyAccu_Accumulate(&acc, v);
Py_DECREF(v);
if (r) if (r)
goto onError; goto onError;
if (width > len && repeat_accumulate(&acc, blank, width - len)) if (width > len && repeat_accumulate(&acc, blank, width - len))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment