mirror of
https://github.com/micropython/micropython.git
synced 2026-01-07 12:40:15 +01:00
py: Small simplifications in tuple and list accessors.
This commit is contained in:
17
py/objzip.c
17
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 = {
|
||||
|
||||
Reference in New Issue
Block a user