[Python-checkins] cpython: Add fast paths to deque_init() for the common cases

raymond.hettinger python-checkins at python.org
Thu Oct 1 08:15:08 CEST 2015


https://hg.python.org/cpython/rev/5352badd200e
changeset: 98444:5352badd200e
user: Raymond Hettinger <python at rcn.com>
date: Wed Sep 30 23:15:02 2015 -0700
summary:
 Add fast paths to deque_init() for the common cases
files:
 Modules/_collectionsmodule.c | 13 ++++++++++---
 1 files changed, 10 insertions(+), 3 deletions(-)
diff --git a/Modules/_collectionsmodule.c b/Modules/_collectionsmodule.c
--- a/Modules/_collectionsmodule.c
+++ b/Modules/_collectionsmodule.c
@@ -1456,8 +1456,14 @@
 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->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)
-- 
Repository URL: https://hg.python.org/cpython


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /