[Python-checkins] cpython: Fix my last change on PyUnicode_Join(): don't process separator if len==1

victor.stinner python-checkins at python.org
Thu Oct 6 12:37:17 CEST 2011


http://hg.python.org/cpython/rev/3636a39fa557
changeset:   72721:3636a39fa557
user:        Victor Stinner <victor.stinner at haypocalc.com>
date:        Thu Oct 06 12:32:37 2011 +0200
summary:
  Fix my last change on PyUnicode_Join(): don't process separator if len==1

files:
  Objects/unicodeobject.c |  62 +++++++++++++++-------------
  1 files changed, 33 insertions(+), 29 deletions(-)


diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c
--- a/Objects/unicodeobject.c
+++ b/Objects/unicodeobject.c
@@ -9145,37 +9145,41 @@
 
     /* If singleton sequence with an exact Unicode, return that. */
     items = PySequence_Fast_ITEMS(fseq);
-    if (seqlen == 1 && PyUnicode_CheckExact(items[0])) {
-        res = items[0];
-        Py_INCREF(res);
-        Py_DECREF(fseq);
-        return res;
-    }
-
-    /* Set up sep and seplen */
-    if (separator == NULL) {
-        /* fall back to a blank space separator */
-        sep = PyUnicode_FromOrdinal(' ');
-        if (!sep)
-            goto onError;
-        maxchar = 32;
+    if (seqlen == 1) {
+        if (PyUnicode_CheckExact(items[0])) {
+            res = items[0];
+            Py_INCREF(res);
+            Py_DECREF(fseq);
+            return res;
+        }
+        sep = NULL;
     }
     else {
-        if (!PyUnicode_Check(separator)) {
-            PyErr_Format(PyExc_TypeError,
-                         "separator: expected str instance,"
-                         " %.80s found",
-                         Py_TYPE(separator)->tp_name);
-            goto onError;
-        }
-        if (PyUnicode_READY(separator))
-            goto onError;
-        sep = separator;
-        seplen = PyUnicode_GET_LENGTH(separator);
-        maxchar = PyUnicode_MAX_CHAR_VALUE(separator);
-        /* inc refcount to keep this code path symmetric with the
-           above case of a blank separator */
-        Py_INCREF(sep);
+        /* Set up sep and seplen */
+        if (separator == NULL) {
+            /* fall back to a blank space separator */
+            sep = PyUnicode_FromOrdinal(' ');
+            if (!sep)
+                goto onError;
+            maxchar = 32;
+        }
+        else {
+            if (!PyUnicode_Check(separator)) {
+                PyErr_Format(PyExc_TypeError,
+                             "separator: expected str instance,"
+                             " %.80s found",
+                             Py_TYPE(separator)->tp_name);
+                goto onError;
+            }
+            if (PyUnicode_READY(separator))
+                goto onError;
+            sep = separator;
+            seplen = PyUnicode_GET_LENGTH(separator);
+            maxchar = PyUnicode_MAX_CHAR_VALUE(separator);
+            /* inc refcount to keep this code path symmetric with the
+               above case of a blank separator */
+            Py_INCREF(sep);
+        }
     }
 
     /* There are at least two things to join, or else we have a subclass

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


More information about the Python-checkins mailing list