py: Add iter_buf to getiter type method.
Allows to iterate over the following without allocating on the heap: - tuple - list - string, bytes - bytearray, array - dict (not dict.keys, dict.values, dict.items) - set, frozenset Allows to call the following without heap memory: - all, any, min, max, sum TODO: still need to allocate stack memory in bytecode for iter_buf.
This commit is contained in:
@@ -61,13 +61,14 @@ STATIC mp_obj_t it_iternext(mp_obj_t self_in) {
|
||||
STATIC const mp_obj_type_t it_type = {
|
||||
{ &mp_type_type },
|
||||
.name = MP_QSTR_iterator,
|
||||
.getiter = mp_identity,
|
||||
.getiter = mp_identity_getiter,
|
||||
.iternext = it_iternext,
|
||||
};
|
||||
|
||||
// args are those returned from mp_load_method_maybe (ie either an attribute or a method)
|
||||
mp_obj_t mp_obj_new_getitem_iter(mp_obj_t *args) {
|
||||
mp_obj_getitem_iter_t *o = m_new_obj(mp_obj_getitem_iter_t);
|
||||
mp_obj_t mp_obj_new_getitem_iter(mp_obj_t *args, mp_obj_iter_buf_t *iter_buf) {
|
||||
assert(sizeof(mp_obj_getitem_iter_t) <= sizeof(mp_obj_iter_buf_t));
|
||||
mp_obj_getitem_iter_t *o = (mp_obj_getitem_iter_t*)iter_buf;
|
||||
o->base.type = &it_type;
|
||||
o->args[0] = args[0];
|
||||
o->args[1] = args[1];
|
||||
|
||||
Reference in New Issue
Block a user