8000 Factor-out two substantially identical code blocks. by rhettinger · Pull Request #8219 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

Factor-out two substantially identical code blocks. #8219

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 10, 2018
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Fold extend()
  • Loading branch information
rhettinger committed Jul 10, 2018
commit f36ebb71e31b6dd4cd45bb0375d2bf03d4ba94ef
28 changes: 5 additions & 23 deletions Modules/_collectionsmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ deque_append(dequeobject *deque, PyObject *item)

PyDoc_STRVAR(append_doc, "Add an element to the right side of the deque.");

static int
static inline int
deque_appendleft_internal(dequeobject *deque, PyObject *item, Py_ssize_t maxlen)
{
if (deque->leftindex == 0) {
Expand Down Expand Up @@ -403,28 +403,10 @@ deque_extend(dequeobject *deque, PyObject *iterable)

iternext = *Py_TYPE(it)->tp_iternext;
while ((item = iternext(it)) != 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++;
if (deque_append_internal(deque, item, maxlen) == -1) {
Py_DECREF(item);
Py_DECREF(it);
return NULL;
}
}
return finalize_iterator(it);
Expand Down
0