summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2017-03-06 21:39:35 (GMT)
committerGitHub <noreply@github.com>2017-03-06 21:39:35 (GMT)
commit98e80c2babac0003182c3482c6c5437ea111e795 (patch)
tree83b3ea071a272a8c8a52202111154548c72bdfa9 /Objects
parentbe487a65f18e1be5fde03e2977fff4be53cc2fbf (diff)
downloadcpython-98e80c2babac0003182c3482c6c5437ea111e795.zip
cpython-98e80c2babac0003182c3482c6c5437ea111e795.tar.gz
cpython-98e80c2babac0003182c3482c6c5437ea111e795.tar.bz2
bpo-29737: Optimize concatenating with empty tuple. (#524)
Diffstat (limited to 'Objects')
-rw-r--r--Objects/tupleobject.c8
1 files changed, 8 insertions, 0 deletions
diff --git a/Objects/tupleobject.c b/Objects/tupleobject.c
index 64db806..4c6bbe7 100644
--- a/Objects/tupleobject.c
+++ b/Objects/tupleobject.c
@@ -446,6 +446,10 @@ tupleconcat(PyTupleObject *a, PyObject *bb)
Py_ssize_t i;
PyObject **src, **dest;
PyTupleObject *np;
+ if (Py_SIZE(a) == 0 && PyTuple_CheckExact(bb)) {
+ Py_INCREF(bb);
+ return bb;
+ }
if (!PyTuple_Check(bb)) {
PyErr_Format(PyExc_TypeError,
"can only concatenate tuple (not \"%.200s\") to tuple",
@@ -453,6 +457,10 @@ tupleconcat(PyTupleObject *a, PyObject *bb)
return NULL;
}
#define b ((PyTupleObject *)bb)
+ if (Py_SIZE(b) == 0 && PyTuple_CheckExact(a)) {
+ Py_INCREF(a);
+ return (PyObject *)a;
+ }
if (Py_SIZE(a) > PY_SSIZE_T_MAX - Py_SIZE(b))
return PyErr_NoMemory();
size = Py_SIZE(a) + Py_SIZE(b);