diff options
author | Raymond Hettinger <python@rcn.com> | 2015-10-01 06:15:02 (GMT) |
---|---|---|
committer | Raymond Hettinger <python@rcn.com> | 2015-10-01 06:15:02 (GMT) |
commit | 0d30940dd256da65c91c3bb2d1e135f90eb8c223 (patch) | |
tree | ed401b075826349117f7df55b378ade27e8d3450 /Modules/_collectionsmodule.c | |
parent | a53a818c3c67c927bcf8ee118fd29e21045dd9ab (diff) | |
download | cpython-0d30940dd256da65c91c3bb2d1e135f90eb8c223.zip cpython-0d30940dd256da65c91c3bb2d1e135f90eb8c223.tar.gz cpython-0d30940dd256da65c91c3bb2d1e135f90eb8c223.tar.bz2 |
Add fast paths to deque_init() for the common cases
Diffstat (limited to 'Modules/_collectionsmodule.c')
-rw-r--r-- | Modules/_collectionsmodule.c | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/Modules/_collectionsmodule.c b/Modules/_collectionsmodule.c index d9df574..0c64713 100644 --- a/Modules/_collectionsmodule.c +++ b/Modules/_collectionsmodule.c @@ -1456,8 +1456,14 @@ deque_init(dequeobject *deque, PyObject *args, PyObject *kwdargs) Py_ssize_t maxlen = -1; char *kwlist[] = {"iterable", "maxlen", 0}; - if (!PyArg_ParseTupleAndKeywords(args, kwdargs, "|OO:deque", kwlist, &iterable, &maxlenobj)) - return -1; + if (kwdargs == NULL) { + if (!PyArg_UnpackTuple(args, "deque()", 0, 2, &iterable, &maxlenobj)) + return -1; + } else { + if (!PyArg_ParseTupleAndKeywords(args, kwdargs, "|OO:deque", kwlist, + &iterable, &maxlenobj)) + return -1; + } if (maxlenobj != NULL && maxlenobj != Py_None) { maxlen = PyLong_AsSsize_t(maxlenobj); if (maxlen == -1 && PyErr_Occurred()) @@ -1468,7 +1474,8 @@ deque_init(dequeobject *deque, PyObject *args, PyObject *kwdargs) } } deque->maxlen = maxlen; - deque_clear(deque); + if (Py_SIZE(deque) > 0) + deque_clear(deque); if (iterable != NULL) { PyObject *rv = deque_extend(deque, iterable); if (rv == NULL) |