diff options
author | Damien George <damien.p.george@gmail.com> | 2016-01-03 16:27:55 +0000 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2016-01-03 16:27:55 +0000 |
commit | 8212d97317b6e0c23c49a4ea34dbdb957f380789 (patch) | |
tree | b03b0ac793306aa102828945aab270ccaac90ac8 /py/objset.c | |
parent | 17f324b83655e68b064f0637f5190000ea0e1f12 (diff) | |
download | micropython-8212d97317b6e0c23c49a4ea34dbdb957f380789.tar.gz micropython-8212d97317b6e0c23c49a4ea34dbdb957f380789.zip |
py: Use polymorphic iterator type where possible to reduce code size.
Only types whose iterator instances still fit in 4 machine words have
been changed to use the polymorphic iterator.
Reduces Thumb2 arch code size by 264 bytes.
Diffstat (limited to 'py/objset.c')
-rw-r--r-- | py/objset.c | 12 |
1 files changed, 3 insertions, 9 deletions
diff --git a/py/objset.c b/py/objset.c index c09616e0ba..fbcf0cdae9 100644 --- a/py/objset.c +++ b/py/objset.c @@ -42,6 +42,7 @@ typedef struct _mp_obj_set_t { typedef struct _mp_obj_set_it_t { mp_obj_base_t base; + mp_fun_1_t iternext; mp_obj_set_t *set; mp_uint_t cur; } mp_obj_set_it_t; @@ -146,15 +147,7 @@ STATIC mp_obj_t set_make_new(mp_obj_t type_in, mp_uint_t n_args, mp_uint_t n_kw, } } -const mp_obj_type_t mp_type_set_it = { - { &mp_type_type }, - .name = MP_QSTR_iterator, - .getiter = mp_identity, - .iternext = set_it_iternext, -}; - STATIC mp_obj_t set_it_iternext(mp_obj_t self_in) { - assert(MP_OBJ_IS_TYPE(self_in, &mp_type_set_it)); mp_obj_set_it_t *self = MP_OBJ_TO_PTR(self_in); mp_uint_t max = self->set->set.alloc; mp_set_t *set = &self->set->set; @@ -171,7 +164,8 @@ STATIC mp_obj_t set_it_iternext(mp_obj_t self_in) { STATIC mp_obj_t set_getiter(mp_obj_t set_in) { mp_obj_set_it_t *o = m_new_obj(mp_obj_set_it_t); - o->base.type = &mp_type_set_it; + o->base.type = &mp_type_polymorph_iter; + o->iternext = set_it_iternext; o->set = (mp_obj_set_t *)MP_OBJ_TO_PTR(set_in); o->cur = 0; return MP_OBJ_FROM_PTR(o); |