py/objint: Remove unreachable code checking for int type in format func.
All callers of mp_obj_int_formatted() are expected to pass in a valid int object, and they do: - mp_obj_int_print() should always pass through an int object because it is the print special method for int instances. - mp_print_mp_int() checks that the argument is an int, and if not converts it to a small int. This patch saves around 20-50 bytes of code space.
This commit is contained in:
parent
c607b58efe
commit
9884a2c712
21
py/objint.c
21
py/objint.c
|
@ -222,27 +222,26 @@ size_t mp_int_format_size(size_t num_bits, int base, const char *prefix, char co
|
||||||
char *mp_obj_int_formatted(char **buf, size_t *buf_size, size_t *fmt_size, mp_const_obj_t self_in,
|
char *mp_obj_int_formatted(char **buf, size_t *buf_size, size_t *fmt_size, mp_const_obj_t self_in,
|
||||||
int base, const char *prefix, char base_char, char comma) {
|
int base, const char *prefix, char base_char, char comma) {
|
||||||
fmt_int_t num;
|
fmt_int_t num;
|
||||||
|
#if MICROPY_LONGINT_IMPL == MICROPY_LONGINT_IMPL_NONE
|
||||||
|
// Only have small ints; get the integer value to format.
|
||||||
|
num = MP_OBJ_SMALL_INT_VALUE(self_in);
|
||||||
|
#else
|
||||||
if (MP_OBJ_IS_SMALL_INT(self_in)) {
|
if (MP_OBJ_IS_SMALL_INT(self_in)) {
|
||||||
// A small int; get the integer value to format.
|
// A small int; get the integer value to format.
|
||||||
num = MP_OBJ_SMALL_INT_VALUE(self_in);
|
num = MP_OBJ_SMALL_INT_VALUE(self_in);
|
||||||
#if MICROPY_LONGINT_IMPL != MICROPY_LONGINT_IMPL_NONE
|
} else {
|
||||||
} else if (MP_OBJ_IS_TYPE(self_in, &mp_type_int)) {
|
assert(MP_OBJ_IS_TYPE(self_in, &mp_type_int));
|
||||||
// Not a small int.
|
// Not a small int.
|
||||||
#if MICROPY_LONGINT_IMPL == MICROPY_LONGINT_IMPL_LONGLONG
|
#if MICROPY_LONGINT_IMPL == MICROPY_LONGINT_IMPL_LONGLONG
|
||||||
const mp_obj_int_t *self = self_in;
|
const mp_obj_int_t *self = self_in;
|
||||||
// Get the value to format; mp_obj_get_int truncates to mp_int_t.
|
// Get the value to format; mp_obj_get_int truncates to mp_int_t.
|
||||||
num = self->val;
|
num = self->val;
|
||||||
#else
|
#else
|
||||||
// Delegate to the implementation for the long int.
|
// Delegate to the implementation for the long int.
|
||||||
return mp_obj_int_formatted_impl(buf, buf_size, fmt_size, self_in, base, prefix, base_char, comma);
|
return mp_obj_int_formatted_impl(buf, buf_size, fmt_size, self_in, base, prefix, base_char, comma);
|
||||||
#endif
|
#endif
|
||||||
#endif
|
|
||||||
} else {
|
|
||||||
// Not an int.
|
|
||||||
**buf = '\0';
|
|
||||||
*fmt_size = 0;
|
|
||||||
return *buf;
|
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
char sign = '\0';
|
char sign = '\0';
|
||||||
if (num < 0) {
|
if (num < 0) {
|
||||||
|
|
Loading…
Reference in New Issue