From e2c1226da4ed1498c0373c6a262f0b782600e2fe Mon Sep 17 00:00:00 2001 From: Damien George Date: Thu, 23 Jan 2020 13:03:00 +1100 Subject: [PATCH] py/objexcept: Optimise mp_obj_new_exception[_arg1/_args] functions. This reduces code size by 10-70 bytes on all ports (except cc3200 which has no change). --- py/objexcept.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/py/objexcept.c b/py/objexcept.c index 869a80bbe7..33ad74ee71 100644 --- a/py/objexcept.c +++ b/py/objexcept.c @@ -304,17 +304,19 @@ MP_DEFINE_EXCEPTION(Exception, BaseException) */ mp_obj_t mp_obj_new_exception(const mp_obj_type_t *exc_type) { - return mp_obj_new_exception_args(exc_type, 0, NULL); + assert(exc_type->make_new == mp_obj_exception_make_new); + return mp_obj_exception_make_new(exc_type, 0, 0, NULL); } // "Optimized" version for common(?) case of having 1 exception arg mp_obj_t mp_obj_new_exception_arg1(const mp_obj_type_t *exc_type, mp_obj_t arg) { - return mp_obj_new_exception_args(exc_type, 1, &arg); + assert(exc_type->make_new == mp_obj_exception_make_new); + return mp_obj_exception_make_new(exc_type, 1, 0, &arg); } mp_obj_t mp_obj_new_exception_args(const mp_obj_type_t *exc_type, size_t n_args, const mp_obj_t *args) { assert(exc_type->make_new == mp_obj_exception_make_new); - return exc_type->make_new(exc_type, n_args, 0, args); + return mp_obj_exception_make_new(exc_type, n_args, 0, args); } mp_obj_t mp_obj_new_exception_msg(const mp_obj_type_t *exc_type, const char *msg) {