[Python-checkins] cpython: Issue #14687: Avoid an useless duplicated string in PyUnicode_Format()

victor.stinner python-checkins at python.org
Mon Apr 30 05:25:20 CEST 2012


http://hg.python.org/cpython/rev/08b54c635586
changeset:   76658:08b54c635586
user:        Victor Stinner <victor.stinner at gmail.com>
date:        Mon Apr 30 05:21:52 2012 +0200
summary:
  Issue #14687: Avoid an useless duplicated string in PyUnicode_Format()

files:
  Objects/unicodeobject.c |  22 +++++++++-------------
  1 files changed, 9 insertions(+), 13 deletions(-)


diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c
--- a/Objects/unicodeobject.c
+++ b/Objects/unicodeobject.c
@@ -14051,20 +14051,16 @@
                 }
             }
             /* 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))

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list