[Python-checkins] cpython: More logicial order. Move space saving step to just before it is used.

raymond.hettinger python-checkins at python.org
Fri Mar 4 12:55:11 EST 2016


https://hg.python.org/cpython/rev/c1c8d2e27267
changeset: 100413:c1c8d2e27267
user: Raymond Hettinger <python at rcn.com>
date: Fri Mar 04 09:55:07 2016 -0800
summary:
 More logicial order. Move space saving step to just before it is used.
files:
 Modules/_collectionsmodule.c | 28 ++++++++++++------------
 1 files changed, 14 insertions(+), 14 deletions(-)
diff --git a/Modules/_collectionsmodule.c b/Modules/_collectionsmodule.c
--- a/Modules/_collectionsmodule.c
+++ b/Modules/_collectionsmodule.c
@@ -386,6 +386,13 @@
 return result;
 }
 
+ it = PyObject_GetIter(iterable);
+ if (it == NULL)
+ return NULL;
+
+ if (maxlen == 0)
+ return consume_iterator(it);
+
 /* Space saving heuristic. Start filling from the left */
 if (Py_SIZE(deque) == 0) {
 assert(deque->leftblock == deque->rightblock);
@@ -394,13 +401,6 @@
 deque->rightindex = 0;
 }
 
- it = PyObject_GetIter(iterable);
- if (it == NULL)
- return NULL;
-
- if (maxlen == 0)
- return consume_iterator(it);
-
 iternext = *Py_TYPE(it)->tp_iternext;
 while ((item = iternext(it)) != NULL) {
 if (deque_append_internal(deque, item, maxlen) < 0) {
@@ -433,6 +433,13 @@
 return result;
 }
 
+ it = PyObject_GetIter(iterable);
+ if (it == NULL)
+ return NULL;
+
+ if (maxlen == 0)
+ return consume_iterator(it);
+
 /* Space saving heuristic. Start filling from the right */
 if (Py_SIZE(deque) == 0) {
 assert(deque->leftblock == deque->rightblock);
@@ -441,13 +448,6 @@
 deque->rightindex = BLOCKLEN - 2;
 }
 
- it = PyObject_GetIter(iterable);
- if (it == NULL)
- return NULL;
-
- if (maxlen == 0)
- return consume_iterator(it);
-
 iternext = *Py_TYPE(it)->tp_iternext;
 while ((item = iternext(it)) != NULL) {
 if (deque_appendleft_internal(deque, item, maxlen) < 0) {
-- 
Repository URL: https://hg.python.org/cpython


More information about the Python-checkins mailing list

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