8000 py: simplify __next__ method for generators. · comfuture/micropython@d9d6201 · GitHub
[go: up one dir, main page]

Skip to content

Commit d9d6201

Browse files
committed
py: simplify __next__ method for generators.
1 parent d99b052 commit d9d6201

File tree

4 files changed

+8
-17
lines changed

4 files changed

+8
-17
lines changed

py/builtin.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
#include "obj.h"
1212
#include "runtime0.h"
1313
#include "runtime.h"
14-
//#include "bc.h"
1514
#include "map.h"
1615
#include "builtin.h"
1716

@@ -293,8 +292,13 @@ mp_obj_t mp_builtin_min(int n_args, const mp_obj_t *args) {
293292
}
294293
}
295294

296-
static mp_obj_t mp_builtin_next(mp_obj_t o_in) {
297-
return mp_obj_gen_instance_next(o_in);
295+
static mp_obj_t mp_builtin_next(mp_obj_t o) {
296+
mp_obj_t ret = rt_iternext(o);
297+
if (ret == mp_const_stop_iteration) {
298+
nlr_jump(mp_obj_new_exception(qstr_from_str_static("StopIteration")));
299+
} else {
300+
return ret;
301+
}
298302
}
299303

300304
MP_DEFINE_CONST_FUN_OBJ_1(mp_builtin_next_obj, mp_builtin_next);

py/obj.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,8 +220,6 @@ void mp_obj_fun_bc_get(mp_obj_t self_in, int *n_args, uint *n_state, const byte
220220

221221
// generator
222222
extern const mp_obj_type_t gen_instance_type;
223-
mp_obj_t mp_obj_gen_instance_next(mp_obj_t self_in);
224-
MP_DECLARE_CONST_FUN_OBJ(mp_obj_gen_instance_next_obj);
225223

226224
// class
227225
extern const mp_obj_type_t class_type;

py/objgenerator.c

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -117,14 +117,3 @@ mp_obj_t mp_obj_new_gen_instance(mp_obj_t state, const byte *ip, mp_obj_t *sp) {
117117
o->sp = sp;
118118
return o;
119119
}
120-
121-
mp_obj_t mp_obj_gen_instance_next(mp_obj_t self_in) {
122-
mp_obj_t ret = rt_iternext(self_in);
123-
if (ret == mp_const_stop_iteration) {
124-
nlr_jump(mp_obj_new_exception(qstr_from_str_static("StopIteration")));
125-
} else {
126-
return ret;
127-
}
128-
}
129-
130-
MP_DEFINE_CONST_FUN_OBJ_1(mp_obj_gen_instance_next_obj, mp_obj_gen_instance_next);

py/runtime.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -772,7 +772,7 @@ mp_obj_t rt_load_attr(mp_obj_t base, qstr attr) {
772772
void rt_load_method(mp_obj_t base, qstr attr, mp_obj_t *dest) {
773773
DEBUG_OP_printf("load method %s\n", qstr_str(attr));
774774
if (MP_OBJ_IS_TYPE(base, &gen_instance_type) && attr == rt_q___next__) {
775-
dest[1] = (mp_obj_t)&mp_obj_gen_instance_next_obj;
775+
dest[1] = (mp_obj_t)&mp_builtin_next_obj;
776776
dest[0] = base;
777777
return;
778778
} else if (MP_OBJ_IS_TYPE(base, &instance_type)) {

0 commit comments

Comments
 (0)
0