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.
diff --git a/py/objstr.c b/py/objstr.c
index 7315f40..8839acb 100644
--- a/py/objstr.c
+++ b/py/objstr.c
@@ -2061,6 +2061,7 @@
typedef struct _mp_obj_str8_it_t {
mp_obj_base_t base;
+ mp_fun_1_t iternext;
mp_obj_t str;
mp_uint_t cur;
} mp_obj_str8_it_t;
@@ -2078,16 +2079,10 @@
}
}
-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_str8_it_t *o = m_new_obj(mp_obj_str8_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 o;
@@ -2106,16 +2101,10 @@
}
}
-STATIC const mp_obj_type_t mp_type_bytes_it = {
- { &mp_type_type },
- .name = MP_QSTR_iterator,
- .getiter = mp_identity,
- .iternext = bytes_it_iternext,
-};
-
mp_obj_t mp_obj_new_bytes_iterator(mp_obj_t str) {
mp_obj_str8_it_t *o = m_new_obj(mp_obj_str8_it_t);
- o->base.type = &mp_type_bytes_it;
+ o->base.type = &mp_type_polymorph_iter;
+ o->iternext = bytes_it_iternext;
o->str = str;
o->cur = 0;
return MP_OBJ_FROM_PTR(o);