summaryrefslogtreecommitdiffstats
path: root/Modules/_collectionsmodule.c
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2015-09-13 23:27:01 (GMT)
committerRaymond Hettinger <python@rcn.com>2015-09-13 23:27:01 (GMT)
commite4f3467df17873db60dd1e8daf61e0c629abb130 (patch)
treee3a59badb3203febbfd604f045f9cbe919277e98 /Modules/_collectionsmodule.c
parentba5747b8bd985a43198cf17b6561a33b05062956 (diff)
downloadcpython-e4f3467df17873db60dd1e8daf61e0c629abb130.zip
cpython-e4f3467df17873db60dd1e8daf61e0c629abb130.tar.gz
cpython-e4f3467df17873db60dd1e8daf61e0c629abb130.tar.bz2
Add an exact type match fast path for deque_copy().
Diffstat (limited to 'Modules/_collectionsmodule.c')
-rw-r--r--Modules/_collectionsmodule.c16
1 files changed, 16 insertions, 0 deletions
diff --git a/Modules/_collectionsmodule.c b/Modules/_collectionsmodule.c
index 17233e4..49a46a1 100644
--- a/Modules/_collectionsmodule.c
+++ b/Modules/_collectionsmodule.c
@@ -1205,6 +1205,22 @@ deque_traverse(dequeobject *deque, visitproc visit, void *arg)
static PyObject *
deque_copy(PyObject *deque)
{
+ if (Py_TYPE(deque) == &deque_type) {
+ dequeobject *new_deque;
+ PyObject *rv;
+
+ new_deque = (dequeobject *)deque_new(&deque_type, (PyObject *)NULL, (PyObject *)NULL);
+ if (new_deque == NULL)
+ return NULL;
+ new_deque->maxlen = ((dequeobject *)deque)->maxlen;
+ rv = deque_extend(new_deque, deque);
+ if (rv != NULL) {
+ Py_DECREF(rv);
+ return (PyObject *)new_deque;
+ }
+ Py_DECREF(new_deque);
+ return NULL;
+ }
if (((dequeobject *)deque)->maxlen == -1)
return PyObject_CallFunction((PyObject *)(Py_TYPE(deque)), "O", deque, NULL);
else