Skip to content

Commit 6c82cfc

Browse files
committed
py/objtype: Change type of enum-to-qstr table to uint16_t to save space.
Qstr values fit in 16-bits (and this fact is used elsewhere in the code) so no need to use more than that for the large lookup tables. The compiler will anyway give a warning if the qstr values don't fit in 16 bits. Saves around 80 bytes of code space for Thumb2 archs.
1 parent 9e0cdb2 commit 6c82cfc

2 files changed

Lines changed: 5 additions & 5 deletions

File tree

py/objtype.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ mp_obj_t mp_obj_instance_make_new(const mp_obj_type_t *self, size_t n_args, size
334334
return MP_OBJ_FROM_PTR(o);
335335
}
336336

337-
const qstr mp_unary_op_method_name[] = {
337+
const uint16_t mp_unary_op_method_name[] = {
338338
[MP_UNARY_OP_BOOL] = MP_QSTR___bool__,
339339
[MP_UNARY_OP_LEN] = MP_QSTR___len__,
340340
[MP_UNARY_OP_HASH] = MP_QSTR___hash__,
@@ -408,7 +408,7 @@ STATIC mp_obj_t instance_unary_op(mp_unary_op_t op, mp_obj_t self_in) {
408408
}
409409
}
410410

411-
const qstr mp_binary_op_method_name[] = {
411+
const uint16_t mp_binary_op_method_name[] = {
412412
/*
413413
MP_BINARY_OP_OR,
414414
MP_BINARY_OP_XOR,

py/runtime.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,9 @@ typedef struct _mp_arg_t {
5757
mp_arg_val_t defval;
5858
} mp_arg_t;
5959

60-
// defined in objtype.c
61-
extern const qstr mp_unary_op_method_name[];
62-
extern const qstr mp_binary_op_method_name[];
60+
// Tables mapping operator enums to qstrs, defined in objtype.c
61+
extern const uint16_t mp_unary_op_method_name[];
62+
extern const uint16_t mp_binary_op_method_name[];
6363

6464
void mp_init(void);
6565
void mp_deinit(void);

0 commit comments

Comments
 (0)