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/objstrunicode.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/objstrunicode.c')
-rw-r--r-- | py/objstrunicode.c | 11 |
1 files changed, 3 insertions, 8 deletions
diff --git a/py/objstrunicode.c b/py/objstrunicode.c index fb3d520074..8099e20a0e 100644 --- a/py/objstrunicode.c +++ b/py/objstrunicode.c @@ -267,6 +267,7 @@ const mp_obj_type_t mp_type_str = { typedef struct _mp_obj_str_it_t { mp_obj_base_t base; + mp_fun_1_t iternext; mp_obj_t str; mp_uint_t cur; } mp_obj_str_it_t; @@ -285,16 +286,10 @@ STATIC mp_obj_t str_it_iternext(mp_obj_t self_in) { } } -STATIC const mp_obj_type_t mp_type_str_it = { - { &mp_type_type }, - .name = MP_QSTR_iterator, - .getiter = mp_identity, - .iternext = str_it_iternext, -}; - STATIC mp_obj_t mp_obj_new_str_iterator(mp_obj_t str) { mp_obj_str_it_t *o = m_new_obj(mp_obj_str_it_t); - o->base.type = &mp_type_str_it; + o->base.type = &mp_type_polymorph_iter; + o->iternext = str_it_iternext; o->str = str; o->cur = 0; return MP_OBJ_FROM_PTR(o); |