diff options
author | Damien George <damien.p.george@gmail.com> | 2017-04-06 12:09:01 +1000 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2017-04-12 13:22:21 +1000 |
commit | 816413e4b20ccd463321558458bb63c310712bca (patch) | |
tree | d5c367a053af11fd76c1801023b67ae7d2a082a0 /py/objdict.c | |
parent | fc710169b7fd8738b285c141f1850b262b26c622 (diff) | |
download | micropython-816413e4b20ccd463321558458bb63c310712bca.tar.gz micropython-816413e4b20ccd463321558458bb63c310712bca.zip |
py: Optimise types for common case where type has a single parent type.
The common cases for inheritance are 0 or 1 parent types, for both built-in
types (eg built-in exceptions) as well as user defined types. So it makes
sense to optimise the case of 1 parent type by storing just the type and
not a tuple of 1 value (that value being the single parent type).
This patch makes such an optimisation. Even though there is a bit more
code to handle the two cases (either a single type or a tuple with 2 or
more values) it helps reduce overall code size because it eliminates the
need to create a static tuple to hold single parents (eg for the built-in
exceptions). It also helps reduce RAM usage for user defined types that
only derive from a single parent.
Changes in code size (in bytes) due to this patch:
bare-arm: -16
minimal (x86): -176
unix (x86-64): -320
unix nanbox: -384
stmhal: -64
cc3200: -32
esp8266: -108
Diffstat (limited to 'py/objdict.c')
-rw-r--r-- | py/objdict.c | 4 |
1 files changed, 1 insertions, 3 deletions
diff --git a/py/objdict.c b/py/objdict.c index f6929d23fd..12ba61b2e9 100644 --- a/py/objdict.c +++ b/py/objdict.c @@ -577,8 +577,6 @@ const mp_obj_type_t mp_type_dict = { }; #if MICROPY_PY_COLLECTIONS_ORDEREDDICT -STATIC const mp_rom_obj_tuple_t ordereddict_base_tuple = {{&mp_type_tuple}, 1, {MP_ROM_PTR(&mp_type_dict)}}; - const mp_obj_type_t mp_type_ordereddict = { { &mp_type_type }, .name = MP_QSTR_OrderedDict, @@ -588,7 +586,7 @@ const mp_obj_type_t mp_type_ordereddict = { .binary_op = dict_binary_op, .subscr = dict_subscr, .getiter = dict_getiter, - .bases_tuple = (mp_obj_tuple_t*)(mp_rom_obj_tuple_t*)&ordereddict_base_tuple, + .parent = &mp_type_dict, .locals_dict = (mp_obj_dict_t*)&dict_locals_dict, }; #endif |