mirror of https://github.com/python/cpython
bpo-29737: Optimize concatenating with empty tuple. (#524)
This commit is contained in:
parent
be487a65f1
commit
98e80c2bab
|
@ -446,6 +446,10 @@ tupleconcat(PyTupleObject *a, PyObject *bb)
|
||||||
Py_ssize_t i;
|
Py_ssize_t i;
|
||||||
PyObject **src, **dest;
|
PyObject **src, **dest;
|
||||||
PyTupleObject *np;
|
PyTupleObject *np;
|
||||||
|
if (Py_SIZE(a) == 0 && PyTuple_CheckExact(bb)) {
|
||||||
|
Py_INCREF(bb);
|
||||||
|
return bb;
|
||||||
|
}
|
||||||
if (!PyTuple_Check(bb)) {
|
if (!PyTuple_Check(bb)) {
|
||||||
PyErr_Format(PyExc_TypeError,
|
PyErr_Format(PyExc_TypeError,
|
||||||
"can only concatenate tuple (not \"%.200s\") to tuple",
|
"can only concatenate tuple (not \"%.200s\") to tuple",
|
||||||
|
@ -453,6 +457,10 @@ tupleconcat(PyTupleObject *a, PyObject *bb)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
#define b ((PyTupleObject *)bb)
|
#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))
|
if (Py_SIZE(a) > PY_SSIZE_T_MAX - Py_SIZE(b))
|
||||||
return PyErr_NoMemory();
|
return PyErr_NoMemory();
|
||||||
size = Py_SIZE(a) + Py_SIZE(b);
|
size = Py_SIZE(a) + Py_SIZE(b);
|
||||||
|
|
Loading…
Reference in New Issue