aboutsummaryrefslogtreecommitdiff
path: root/py/objtype.c
diff options
context:
space:
mode:
authorPaul Sokolovsky <pfalcon@users.sourceforge.net>2017-10-21 11:06:32 +0300
committerPaul Sokolovsky <pfalcon@users.sourceforge.net>2017-10-21 11:06:32 +0300
commit9956fd0710c3866b9df37857c9aa62b8bb681403 (patch)
treed3b2a944aeb95396ee45403833c7bc4f46365cc6 /py/objtype.c
parentf2baa9ec245a66c4cd7d990e39a4af3f6fab1cb7 (diff)
py/objtype: Fit qstrs for special methods in byte type.
Update makeqstrdata.py to sort strings starting with "__" to the beginning of qstr list, so they get low qstr id's, guaranteedly fitting in 8 bits. Then use this property to further compact op_id => qstr mapping arrays.
Diffstat (limited to 'py/objtype.c')
-rw-r--r--py/objtype.c10
1 files changed, 7 insertions, 3 deletions
diff --git a/py/objtype.c b/py/objtype.c
index 45b119f45..e75407683 100644
--- a/py/objtype.c
+++ b/py/objtype.c
@@ -332,7 +332,9 @@ mp_obj_t mp_obj_instance_make_new(const mp_obj_type_t *self, size_t n_args, size
return MP_OBJ_FROM_PTR(o);
}
-const uint16_t mp_unary_op_method_name[MP_UNARY_OP_NUM_RUNTIME] = {
+// Qstrs for special methods are guaranteed to have a small value, so we use byte
+// type to represent them.
+const byte mp_unary_op_method_name[MP_UNARY_OP_NUM_RUNTIME] = {
[MP_UNARY_OP_BOOL] = MP_QSTR___bool__,
[MP_UNARY_OP_LEN] = MP_QSTR___len__,
[MP_UNARY_OP_HASH] = MP_QSTR___hash__,
@@ -406,9 +408,11 @@ STATIC mp_obj_t instance_unary_op(mp_unary_op_t op, mp_obj_t self_in) {
}
// Binary-op enum values not listed here will have the default value of 0 in the
-// table, corresponding to MP_QSTR_, and are therefore unsupported (a lookup will
+// table, corresponding to MP_QSTR_NULL, and are therefore unsupported (a lookup will
// fail). They can be added at the expense of code size for the qstr.
-const uint16_t mp_binary_op_method_name[MP_BINARY_OP_NUM_RUNTIME] = {
+// Qstrs for special methods are guaranteed to have a small value, so we use byte
+// type to represent them.
+const byte mp_binary_op_method_name[MP_BINARY_OP_NUM_RUNTIME] = {
[MP_BINARY_OP_LESS] = MP_QSTR___lt__,
[MP_BINARY_OP_MORE] = MP_QSTR___gt__,
[MP_BINARY_OP_EQUAL] = MP_QSTR___eq__,