From e4af71212550d950269f6991be187f41dcf64eee Mon Sep 17 00:00:00 2001 From: Damien George Date: Wed, 21 Dec 2016 11:46:27 +1100 Subject: [PATCH] py/objint: Rename mp_obj_int_as_float to mp_obj_int_as_float_impl. And also simplify it to remove the check for small int. This can be done because this function is only ever called if the argument is not a small int. --- py/obj.c | 8 ++++++-- py/obj.h | 3 --- py/objint.c | 6 ------ py/objint.h | 1 + py/objint_longlong.c | 11 ++++------- py/objint_mpz.c | 11 ++++------- 6 files changed, 15 insertions(+), 25 deletions(-) diff --git a/py/obj.c b/py/obj.c index 5601a73fe7..1d0c80ab90 100644 --- a/py/obj.c +++ b/py/obj.c @@ -271,8 +271,10 @@ mp_float_t mp_obj_get_float(mp_obj_t arg) { return 1; } else if (MP_OBJ_IS_SMALL_INT(arg)) { return MP_OBJ_SMALL_INT_VALUE(arg); + #if MICROPY_LONGINT_IMPL != MICROPY_LONGINT_IMPL_NONE } else if (MP_OBJ_IS_TYPE(arg, &mp_type_int)) { - return mp_obj_int_as_float(arg); + return mp_obj_int_as_float_impl(arg); + #endif } else if (mp_obj_is_float(arg)) { return mp_obj_float_get(arg); } else { @@ -296,9 +298,11 @@ void mp_obj_get_complex(mp_obj_t arg, mp_float_t *real, mp_float_t *imag) { } else if (MP_OBJ_IS_SMALL_INT(arg)) { *real = MP_OBJ_SMALL_INT_VALUE(arg); *imag = 0; + #if MICROPY_LONGINT_IMPL != MICROPY_LONGINT_IMPL_NONE } else if (MP_OBJ_IS_TYPE(arg, &mp_type_int)) { - *real = mp_obj_int_as_float(arg); + *real = mp_obj_int_as_float_impl(arg); *imag = 0; + #endif } else if (mp_obj_is_float(arg)) { *real = mp_obj_float_get(arg); *imag = 0; diff --git a/py/obj.h b/py/obj.h index 61db65a9a2..6106bbe19a 100644 --- a/py/obj.h +++ b/py/obj.h @@ -680,9 +680,6 @@ void mp_obj_cell_set(mp_obj_t self_in, mp_obj_t obj); mp_int_t mp_obj_int_get_truncated(mp_const_obj_t self_in); // Will raise exception if value doesn't fit into mp_int_t mp_int_t mp_obj_int_get_checked(mp_const_obj_t self_in); -#if MICROPY_PY_BUILTINS_FLOAT -mp_float_t mp_obj_int_as_float(mp_obj_t self_in); -#endif // exception #define mp_obj_is_native_exception_instance(o) (mp_obj_get_type(o)->make_new == mp_obj_exception_make_new) diff --git a/py/objint.c b/py/objint.c index 3af509b535..1c73141bd9 100644 --- a/py/objint.c +++ b/py/objint.c @@ -354,12 +354,6 @@ mp_int_t mp_obj_int_get_checked(mp_const_obj_t self_in) { return MP_OBJ_SMALL_INT_VALUE(self_in); } -#if MICROPY_PY_BUILTINS_FLOAT -mp_float_t mp_obj_int_as_float(mp_obj_t self_in) { - return MP_OBJ_SMALL_INT_VALUE(self_in); -} -#endif - #endif // MICROPY_LONGINT_IMPL == MICROPY_LONGINT_IMPL_NONE // This dispatcher function is expected to be independent of the implementation of long int diff --git a/py/objint.h b/py/objint.h index 6e627f1bd7..f418c329e9 100644 --- a/py/objint.h +++ b/py/objint.h @@ -48,6 +48,7 @@ typedef enum { } mp_fp_as_int_class_t; mp_fp_as_int_class_t mp_classify_fp_as_int(mp_float_t val); +mp_float_t mp_obj_int_as_float_impl(mp_obj_t self_in); #endif // MICROPY_PY_BUILTINS_FLOAT size_t mp_int_format_size(size_t num_bits, int base, const char *prefix, char comma); diff --git a/py/objint_longlong.c b/py/objint_longlong.c index b051cfbe64..f5b5d9c939 100644 --- a/py/objint_longlong.c +++ b/py/objint_longlong.c @@ -295,13 +295,10 @@ mp_int_t mp_obj_int_get_checked(mp_const_obj_t self_in) { } #if MICROPY_PY_BUILTINS_FLOAT -mp_float_t mp_obj_int_as_float(mp_obj_t self_in) { - if (MP_OBJ_IS_SMALL_INT(self_in)) { - return MP_OBJ_SMALL_INT_VALUE(self_in); - } else { - mp_obj_int_t *self = self_in; - return self->val; - } +mp_float_t mp_obj_int_as_float_impl(mp_obj_t self_in) { + assert(MP_OBJ_IS_TYPE(self_in, &mp_type_int)); + mp_obj_int_t *self = self_in; + return self->val; } #endif diff --git a/py/objint_mpz.c b/py/objint_mpz.c index 0a1d68598d..eadf64fce7 100644 --- a/py/objint_mpz.c +++ b/py/objint_mpz.c @@ -403,13 +403,10 @@ mp_int_t mp_obj_int_get_checked(mp_const_obj_t self_in) { } #if MICROPY_PY_BUILTINS_FLOAT -mp_float_t mp_obj_int_as_float(mp_obj_t self_in) { - if (MP_OBJ_IS_SMALL_INT(self_in)) { - return MP_OBJ_SMALL_INT_VALUE(self_in); - } else { - mp_obj_int_t *self = MP_OBJ_TO_PTR(self_in); - return mpz_as_float(&self->mpz); - } +mp_float_t mp_obj_int_as_float_impl(mp_obj_t self_in) { + assert(MP_OBJ_IS_TYPE(self_in, &mp_type_int)); + mp_obj_int_t *self = MP_OBJ_TO_PTR(self_in); + return mpz_as_float(&self->mpz); } #endif