Commits

Victor Stinner committed 08b54c6

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

  • Participants
  • Parent commits 42fbb4f

Comments (0)

Files changed (1)

File Objects/unicodeobject.c

                 }
             }
             /* Copy all characters, preserving len */
-            if (temp != NULL) {
-                assert(pbuf == PyUnicode_DATA(temp));
+            if (pindex == 0 && len == PyUnicode_GET_LENGTH(temp)) {
+                r = _PyAccu_Accumulate(&acc, temp);
+            }
+            else {
                 v = PyUnicode_Substring(temp, pindex, pindex + len);
-            }
-            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);
+                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))