summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@haypocalc.com>2011-10-06 10:32:37 (GMT)
committerVictor Stinner <victor.stinner@haypocalc.com>2011-10-06 10:32:37 (GMT)
commitacf47b807f9a56dd802aa2e8c96f4c02f83ca831 (patch)
treece1429fc81775a90fa2b84eaa9692698729847e8
parent25a4b29c95fd5dddbfef985c7fd7b26417a4b87b (diff)
downloadcpython-acf47b807f9a56dd802aa2e8c96f4c02f83ca831.zip
cpython-acf47b807f9a56dd802aa2e8c96f4c02f83ca831.tar.gz
cpython-acf47b807f9a56dd802aa2e8c96f4c02f83ca831.tar.bz2
Fix my last change on PyUnicode_Join(): don't process separator if len==1
-rw-r--r--Objects/unicodeobject.c60
1 files changed, 32 insertions, 28 deletions
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c
index 3a0f468..72007d9 100644
--- a/Objects/unicodeobject.c
+++ b/Objects/unicodeobject.c
@@ -9145,37 +9145,41 @@ PyUnicode_Join(PyObject *separator, PyObject *seq)
/* 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;
+ /* 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);
}
- 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