aboutsummaryrefslogtreecommitdiff
path: root/py/objstrunicode.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/objstrunicode.c
parent17f324b83655e68b064f0637f5190000ea0e1f12 (diff)
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.c11
1 files changed, 3 insertions, 8 deletions
diff --git a/py/objstrunicode.c b/py/objstrunicode.c
index fb3d52007..8099e20a0 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);