]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Issue #14687: Avoid an useless duplicated string in PyUnicode_Format()
authorVictor Stinner <victor.stinner@gmail.com>
Mon, 30 Apr 2012 03:21:52 +0000 (05:21 +0200)
committerVictor Stinner <victor.stinner@gmail.com>
Mon, 30 Apr 2012 03:21:52 +0000 (05:21 +0200)
Objects/unicodeobject.c

index 8959a97cf43e3145484a33c8928b76ec37c28faf..18bc07f908d2b6a3737df78336513722ec8f3492 100644 (file)
@@ -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))