mirror of
https://github.com/micropython/micropython.git
synced 2026-01-07 04:30:24 +01:00
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
This commit is contained in:
7
py/obj.h
7
py/obj.h
@@ -525,8 +525,11 @@ struct _mp_obj_type_t {
|
||||
// One of disjoint protocols (interfaces), like mp_stream_p_t, etc.
|
||||
const void *protocol;
|
||||
|
||||
// A tuple containing all the base types of this type.
|
||||
struct _mp_obj_tuple_t *bases_tuple;
|
||||
// A pointer to the parents of this type:
|
||||
// - 0 parents: pointer is NULL (object is implicitly the single parent)
|
||||
// - 1 parent: a pointer to the type of that parent
|
||||
// - 2 or more parents: pointer to a tuple object containing the parent types
|
||||
const void *parent;
|
||||
|
||||
// A dict mapping qstrs to objects local methods/constants/etc.
|
||||
struct _mp_obj_dict_t *locals_dict;
|
||||
|
||||
Reference in New Issue
Block a user