Skip to content

Commit 3f52262

Browse files
committed
py: Allow tail call optimisation in mp_call_function_n_kw.
This saves 4 words of stack space per Python call.
1 parent 65ec332 commit 3f52262

File tree

2 files changed

+2
-5
lines changed

2 files changed

+2
-5
lines changed

py/objtype.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -516,7 +516,7 @@ STATIC mp_obj_t instance_call(mp_obj_t self_in, uint n_args, uint n_kw, const mp
516516
mp_obj_t member[2] = {MP_OBJ_NULL};
517517
mp_obj_class_lookup(self, self->base.type, MP_QSTR___call__, offsetof(mp_obj_type_t, call), member);
518518
if (member[0] == MP_OBJ_NULL) {
519-
return MP_OBJ_NULL;
519+
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError, "'%s' object is not callable", mp_obj_get_type_str(self_in)));
520520
}
521521
if (member[0] == MP_OBJ_SENTINEL) {
522522
return mp_call_function_n_kw(self->subobj[0], n_args, n_kw, args);

py/runtime.c

+1-4
Original file line numberDiff line numberDiff line change
@@ -526,10 +526,7 @@ mp_obj_t mp_call_function_n_kw(mp_obj_t fun_in, uint n_args, uint n_kw, const mp
526526

527527
// do the call
528528
if (type->call != NULL) {
529-
mp_obj_t res = type->call(fun_in, n_args, n_kw, args);
530-
if (res != NULL) {
531-
return res;
532-
}
529+
return type->call(fun_in, n_args, n_kw, args);
533530
}
534531

535532
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError, "'%s' object is not callable", mp_obj_get_type_str(fun_in)));

0 commit comments

Comments
 (0)