From 2d3662708fb9ec5a153b8e27edac40036b91afd9 Mon Sep 17 00:00:00 2001 From: doko Date: Tue, 14 Jun 2016 07:27:58 +0200 Subject: - Modules/_collectionsmodule.c: Mark one more internal symbol as static. --- Modules/_collectionsmodule.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Modules/_collectionsmodule.c') diff --git a/Modules/_collectionsmodule.c b/Modules/_collectionsmodule.c index 3008879f98..3410dfec07 100644 --- a/Modules/_collectionsmodule.c +++ b/Modules/_collectionsmodule.c @@ -301,7 +301,7 @@ deque_append(dequeobject *deque, PyObject *item) PyDoc_STRVAR(append_doc, "Add an element to the right side of the deque."); -int +static int deque_appendleft_internal(dequeobject *deque, PyObject *item, Py_ssize_t maxlen) { if (deque->leftindex == 0) { -- cgit v1.2.1 From b10682a8d65eacac79b39a62ff45a15e0ac95f05 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Mon, 5 Sep 2016 17:53:15 -0700 Subject: Avoid inefficient way to call functions without argument Don't pass "()" format to PyObject_CallXXX() to call a function without argument: pass NULL as the format string instead. It avoids to have to parse a string to produce 0 argument. --- Modules/_collectionsmodule.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Modules/_collectionsmodule.c') diff --git a/Modules/_collectionsmodule.c b/Modules/_collectionsmodule.c index 3410dfec07..1675102681 100644 --- a/Modules/_collectionsmodule.c +++ b/Modules/_collectionsmodule.c @@ -2009,7 +2009,7 @@ defdict_reduce(defdictobject *dd) args = PyTuple_Pack(1, dd->default_factory); if (args == NULL) return NULL; - items = _PyObject_CallMethodId((PyObject *)dd, &PyId_items, "()"); + items = _PyObject_CallMethodId((PyObject *)dd, &PyId_items, NULL); if (items == NULL) { Py_DECREF(args); return NULL; -- cgit v1.2.1 From 0224fbd4dfd393e44cbde8d4dfc835fc78d6eb93 Mon Sep 17 00:00:00 2001 From: Raymond Hettinger Date: Sun, 11 Sep 2016 22:45:53 -0700 Subject: Revert part of 3471a3515827 that caused a performance regression --- Modules/_collectionsmodule.c | 52 +++++++++++++++++++++++++++++++++++++------- 1 file changed, 44 insertions(+), 8 deletions(-) (limited to 'Modules/_collectionsmodule.c') diff --git a/Modules/_collectionsmodule.c b/Modules/_collectionsmodule.c index 1675102681..9ed6f14bec 100644 --- a/Modules/_collectionsmodule.c +++ b/Modules/_collectionsmodule.c @@ -403,10 +403,28 @@ deque_extend(dequeobject *deque, PyObject *iterable) iternext = *Py_TYPE(it)->tp_iternext; while ((item = iternext(it)) != NULL) { - if (deque_append_internal(deque, item, maxlen) < 0) { - Py_DECREF(item); - Py_DECREF(it); - return NULL; + if (deque->rightindex == BLOCKLEN - 1) { + block *b = newblock(); + if (b == NULL) { + Py_DECREF(item); + Py_DECREF(it); + return NULL; + } + b->leftlink = deque->rightblock; + CHECK_END(deque->rightblock->rightlink); + deque->rightblock->rightlink = b; + deque->rightblock = b; + MARK_END(b->rightlink); + deque->rightindex = -1; + } + Py_SIZE(deque)++; + deque->rightindex++; + deque->rightblock->data[deque->rightindex] = item; + if (NEEDS_TRIM(deque, maxlen)) { + PyObject *olditem = deque_popleft(deque, NULL); + Py_DECREF(olditem); + } else { + deque->state++; } } return finalize_iterator(it); @@ -450,10 +468,28 @@ deque_extendleft(dequeobject *deque, PyObject *iterable) iternext = *Py_TYPE(it)->tp_iternext; while ((item = iternext(it)) != NULL) { - if (deque_appendleft_internal(deque, item, maxlen) < 0) { - Py_DECREF(item); - Py_DECREF(it); - return NULL; + if (deque->leftindex == 0) { + block *b = newblock(); + if (b == NULL) { + Py_DECREF(item); + Py_DECREF(it); + return NULL; + } + b->rightlink = deque->leftblock; + CHECK_END(deque->leftblock->leftlink); + deque->leftblock->leftlink = b; + deque->leftblock = b; + MARK_END(b->leftlink); + deque->leftindex = BLOCKLEN; + } + Py_SIZE(deque)++; + deque->leftindex--; + deque->leftblock->data[deque->leftindex] = item; + if (NEEDS_TRIM(deque, maxlen)) { + PyObject *olditem = deque_pop(deque, NULL); + Py_DECREF(olditem); + } else { + deque->state++; } } return finalize_iterator(it); -- cgit v1.2.1 From 93efefd659c461bf8e8468136f9cd9c4476f522b Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Sun, 6 Nov 2016 13:18:24 +0200 Subject: Issue #28123: _PyDict_GetItem_KnownHash() now can raise an exception as PyDict_GetItemWithError(). Patch by Xiang Zhang. --- Modules/_collectionsmodule.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'Modules/_collectionsmodule.c') diff --git a/Modules/_collectionsmodule.c b/Modules/_collectionsmodule.c index 9ed6f14bec..6608798247 100644 --- a/Modules/_collectionsmodule.c +++ b/Modules/_collectionsmodule.c @@ -2300,6 +2300,8 @@ _count_elements(PyObject *self, PyObject *args) oldval = _PyDict_GetItem_KnownHash(mapping, key, hash); if (oldval == NULL) { + if (PyErr_Occurred()) + goto done; if (_PyDict_SetItem_KnownHash(mapping, key, one, hash) < 0) goto done; } else { -- cgit v1.2.1