summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2012-04-30 03:21:52 (GMT)
committerVictor Stinner <victor.stinner@gmail.com>2012-04-30 03:21:52 (GMT)
commitb80e46eca4a8d5b9284ca8575c1aa16532a0c05e (patch)
tree763a7360193bd51b39cae75e11d8b1fbcce61cbc /Objects
parentaff3cc659b8ddb0fc7f49077dda1922a67658acd (diff)
downloadcpython-b80e46eca4a8d5b9284ca8575c1aa16532a0c05e.zip
cpython-b80e46eca4a8d5b9284ca8575c1aa16532a0c05e.tar.gz
cpython-b80e46eca4a8d5b9284ca8575c1aa16532a0c05e.tar.bz2
Issue #14687: Avoid an useless duplicated string in PyUnicode_Format()
Diffstat (limited to 'Objects')
-rw-r--r--Objects/unicodeobject.c18
1 files changed, 7 insertions, 11 deletions
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c
index 8959a97..18bc07f 100644
--- a/Objects/unicodeobject.c
+++ b/Objects/unicodeobject.c
@@ -14051,20 +14051,16 @@ PyUnicode_Format(PyObject *format, PyObject *args)
}
}
/* Copy all characters, preserving len */
- if (temp != NULL) {
- assert(pbuf == PyUnicode_DATA(temp));
- v = PyUnicode_Substring(temp, pindex, pindex + len);
+ if (pindex == 0 && len == PyUnicode_GET_LENGTH(temp)) {
+ r = _PyAccu_Accumulate(&acc, temp);
}
else {
- const char *p = (const char *) pbuf;
- assert(pbuf != NULL);
- p += kind * pindex;
- v = PyUnicode_FromKindAndData(kind, p, len);
+ v = PyUnicode_Substring(temp, pindex, pindex + len);
+ if (v == NULL)
+ goto onError;
+ r = _PyAccu_Accumulate(&acc, v);
+ Py_DECREF(v);
}
- if (v == NULL)
- goto onError;
- r = _PyAccu_Accumulate(&acc, v);
- Py_DECREF(v);
if (r)
goto onError;
if (width > len && repeat_accumulate(&acc, blank, width - len))