Skip to content

Commit 1a86a5d

Browse files
Store state in accumulateobject to speed up __reduce__
1 parent c4981ff commit 1a86a5d

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

Modules/itertoolsmodule.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3490,6 +3490,7 @@ typedef struct {
34903490
PyObject *it;
34913491
PyObject *binop;
34923492
PyObject *initial;
3493+
itertools_state *state;
34933494
} accumulateobject;
34943495

34953496
/*[clinic input]
@@ -3528,6 +3529,7 @@ itertools_accumulate_impl(PyTypeObject *type, PyObject *iterable,
35283529
lz->total = NULL;
35293530
lz->it = it;
35303531
lz->initial = Py_XNewRef(initial);
3532+
lz->state = find_state_by_type(type);
35313533
return (PyObject *)lz;
35323534
}
35333535

@@ -3590,8 +3592,7 @@ accumulate_next(accumulateobject *lz)
35903592
static PyObject *
35913593
accumulate_reduce(accumulateobject *lz, PyObject *Py_UNUSED(ignored))
35923594
{
3593-
PyTypeObject *tp = Py_TYPE(lz);
3594-
itertools_state *state = find_state_by_type(tp);
3595+
itertools_state *state = lz->state;
35953596

35963597
if (lz->initial != Py_None) {
35973598
PyObject *it;

0 commit comments

Comments
 (0)