summaryrefslogtreecommitdiffstatshomepage
path: root/py/objlist.c
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2016-01-03 16:27:55 +0000
committerDamien George <damien.p.george@gmail.com>2016-01-03 16:27:55 +0000
commit8212d97317b6e0c23c49a4ea34dbdb957f380789 (patch)
treeb03b0ac793306aa102828945aab270ccaac90ac8 /py/objlist.c
parent17f324b83655e68b064f0637f5190000ea0e1f12 (diff)
downloadmicropython-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/objlist.c')
-rw-r--r--py/objlist.c11
1 files changed, 3 insertions, 8 deletions
diff --git a/py/objlist.c b/py/objlist.c
index a4bec9e320..d0641f21c2 100644
--- a/py/objlist.c
+++ b/py/objlist.c
@@ -498,6 +498,7 @@ void mp_obj_list_store(mp_obj_t self_in, mp_obj_t index, mp_obj_t value) {
typedef struct _mp_obj_list_it_t {
mp_obj_base_t base;
+ mp_fun_1_t iternext;
mp_obj_t list;
mp_uint_t cur;
} mp_obj_list_it_t;
@@ -514,16 +515,10 @@ STATIC mp_obj_t list_it_iternext(mp_obj_t self_in) {
}
}
-STATIC const mp_obj_type_t mp_type_list_it = {
- { &mp_type_type },
- .name = MP_QSTR_iterator,
- .getiter = mp_identity,
- .iternext = list_it_iternext,
-};
-
mp_obj_t mp_obj_new_list_iterator(mp_obj_t list, mp_uint_t cur) {
mp_obj_list_it_t *o = m_new_obj(mp_obj_list_it_t);
- o->base.type = &mp_type_list_it;
+ o->base.type = &mp_type_polymorph_iter;
+ o->iternext = list_it_iternext;
o->list = list;
o->cur = cur;
return MP_OBJ_FROM_PTR(o);