From ca6d75f16d8fc465ddaa4dc90a6f87ab9667b12e Mon Sep 17 00:00:00 2001 From: Damien George Date: Sat, 30 Aug 2014 15:17:47 +0100 Subject: py: Small simplifications in tuple and list accessors. --- py/objzip.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) (limited to 'py/objzip.c') diff --git a/py/objzip.c b/py/objzip.c index 828d6bd03e..738131f920 100644 --- a/py/objzip.c +++ b/py/objzip.c @@ -31,11 +31,12 @@ #include "misc.h" #include "qstr.h" #include "obj.h" +#include "objtuple.h" #include "runtime.h" typedef struct _mp_obj_zip_t { mp_obj_base_t base; - int n_iters; + mp_uint_t n_iters; mp_obj_t iters[]; } mp_obj_zip_t; @@ -45,7 +46,7 @@ STATIC mp_obj_t zip_make_new(mp_obj_t type_in, mp_uint_t n_args, mp_uint_t n_kw, mp_obj_zip_t *o = m_new_obj_var(mp_obj_zip_t, mp_obj_t, n_args); o->base.type = &mp_type_zip; o->n_iters = n_args; - for (int i = 0; i < n_args; i++) { + for (mp_uint_t i = 0; i < n_args; i++) { o->iters[i] = mp_getiter(args[i]); } return o; @@ -54,22 +55,20 @@ STATIC mp_obj_t zip_make_new(mp_obj_t type_in, mp_uint_t n_args, mp_uint_t n_kw, STATIC mp_obj_t zip_iternext(mp_obj_t self_in) { assert(MP_OBJ_IS_TYPE(self_in, &mp_type_zip)); mp_obj_zip_t *self = self_in; - mp_obj_t *items; if (self->n_iters == 0) { return MP_OBJ_STOP_ITERATION; } - mp_obj_t o = mp_obj_new_tuple(self->n_iters, NULL); - mp_obj_tuple_get(o, NULL, &items); + mp_obj_tuple_t *tuple = mp_obj_new_tuple(self->n_iters, NULL); - for (int i = 0; i < self->n_iters; i++) { + for (mp_uint_t i = 0; i < self->n_iters; i++) { mp_obj_t next = mp_iternext(self->iters[i]); if (next == MP_OBJ_STOP_ITERATION) { - mp_obj_tuple_del(o); + mp_obj_tuple_del(tuple); return MP_OBJ_STOP_ITERATION; } - items[i] = next; + tuple->items[i] = next; } - return o; + return tuple; } const mp_obj_type_t mp_type_zip = { -- cgit v1.2.3