Mercurial > cpython-lru_cache-weakref
diff Objects/unicodeobject.c @ 76658:08b54c635586
Issue #14687: Avoid an useless duplicated string in PyUnicode_Format()
| author | Victor Stinner <victor.stinner@gmail.com> |
|---|---|
| date | Mon, 30 Apr 2012 05:21:52 +0200 |
| parents | 42fbb4f9b540 |
| children | 4b98ce6ef95e |
line wrap: on
line diff
--- a/Objects/unicodeobject.c Mon Apr 30 05:19:21 2012 +0200 +++ b/Objects/unicodeobject.c Mon Apr 30 05:21:52 2012 +0200 @@ -14051,20 +14051,16 @@ } } /* 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); - } - if (v == NULL) - goto onError; - r = _PyAccu_Accumulate(&acc, v); - Py_DECREF(v); + v = PyUnicode_Substring(temp, pindex, pindex + len); + 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))
