Skip to content

Commit f1df86a

Browse files
committed
py/objint: Simplify LHS arg type checking in int binary op functions.
The LHS passed to mp_obj_int_binary_op() will always be an integer, either a small int or a big int, so the test for this type doesn't need to include an "other, unsupported type" case.
1 parent 5995a19 commit f1df86a

2 files changed

Lines changed: 4 additions & 7 deletions

File tree

py/objint_longlong.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,10 +124,9 @@ mp_obj_t mp_obj_int_binary_op(mp_binary_op_t op, mp_obj_t lhs_in, mp_obj_t rhs_i
124124

125125
if (MP_OBJ_IS_SMALL_INT(lhs_in)) {
126126
lhs_val = MP_OBJ_SMALL_INT_VALUE(lhs_in);
127-
} else if (MP_OBJ_IS_TYPE(lhs_in, &mp_type_int)) {
128-
lhs_val = ((mp_obj_int_t*)lhs_in)->val;
129127
} else {
130-
return MP_OBJ_NULL; // op not supported
128+
assert(MP_OBJ_IS_TYPE(lhs_in, &mp_type_int));
129+
lhs_val = ((mp_obj_int_t*)lhs_in)->val;
131130
}
132131

133132
if (MP_OBJ_IS_SMALL_INT(rhs_in)) {

py/objint_mpz.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -170,11 +170,9 @@ mp_obj_t mp_obj_int_binary_op(mp_binary_op_t op, mp_obj_t lhs_in, mp_obj_t rhs_i
170170
if (MP_OBJ_IS_SMALL_INT(lhs_in)) {
171171
mpz_init_fixed_from_int(&z_int, z_int_dig, MPZ_NUM_DIG_FOR_INT, MP_OBJ_SMALL_INT_VALUE(lhs_in));
172172
zlhs = &z_int;
173-
} else if (MP_OBJ_IS_TYPE(lhs_in, &mp_type_int)) {
174-
zlhs = &((mp_obj_int_t*)MP_OBJ_TO_PTR(lhs_in))->mpz;
175173
} else {
176-
// unsupported type
177-
return MP_OBJ_NULL;
174+
assert(MP_OBJ_IS_TYPE(lhs_in, &mp_type_int));
175+
zlhs = &((mp_obj_int_t*)MP_OBJ_TO_PTR(lhs_in))->mpz;
178176
}
179177

180178
// if rhs is small int, then lhs was not (otherwise mp_binary_op handles it)

0 commit comments

Comments
 (0)