Skip to content

Commit b57d177

Browse files
Store state in teeobject to speed up __setstate__
1 parent 1a86a5d commit b57d177

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
@@ -718,6 +718,7 @@ typedef struct {
718718
teedataobject *dataobj;
719719
int index; /* 0 <= index <= LINKCELLS */
720720
PyObject *weakreflist;
721+
itertools_state *state;
721722
} teeobject;
722723

723724
static PyObject *
@@ -995,6 +996,7 @@ tee_fromiterable(itertools_state *state, PyObject *iterable)
995996
to->dataobj = (teedataobject *)dataobj;
996997
to->index = 0;
997998
to->weakreflist = NULL;
999+
to->state = state;
9981000
PyObject_GC_Track(to);
9991001
done:
10001002
Py_DECREF(it);
@@ -1051,8 +1053,7 @@ tee_setstate(teeobject *to, PyObject *state)
10511053
PyErr_SetString(PyExc_TypeError, "state is not a tuple");
10521054
return NULL;
10531055
}
1054-
itertools_state *mod_st = get_module_state_by_cls(Py_TYPE(to));
1055-
PyTypeObject *tdo_type = mod_st->teedataobject_type;
1056+
PyTypeObject *tdo_type = to->state->teedataobject_type;
10561057
if (!PyArg_ParseTuple(state, "O!i", tdo_type, &tdo, &index)) {
10571058
return NULL;
10581059
}

0 commit comments

Comments
 (0)