summaryrefslogtreecommitdiffstatshomepage
path: root/py/objzip.c
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2014-08-30 15:17:47 +0100
committerDamien George <damien.p.george@gmail.com>2014-08-30 15:17:47 +0100
commitca6d75f16d8fc465ddaa4dc90a6f87ab9667b12e (patch)
tree3392cc02838cecddcdc99d86fd808cb563f86d95 /py/objzip.c
parent4abff7500fb05430a2ce952a2430d4d0ba16047e (diff)
downloadmicropython-ca6d75f16d8fc465ddaa4dc90a6f87ab9667b12e.tar.gz
micropython-ca6d75f16d8fc465ddaa4dc90a6f87ab9667b12e.zip
py: Small simplifications in tuple and list accessors.
Diffstat (limited to 'py/objzip.c')
-rw-r--r--py/objzip.c17
1 files changed, 8 insertions, 9 deletions
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 = {