summaryrefslogtreecommitdiff
path: root/py/objtype.c
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2017-04-19 09:45:59 +1000
committerDamien George <damien.p.george@gmail.com>2017-04-22 23:39:20 +1000
commitdd11af209d226b7d18d5148b239662e30ed60bad (patch)
tree8343a2ce54172f2f3304ca5dba49f352f37b5c17 /py/objtype.c
parent5335942b599d85263d3c18eb99ff5ebd04a8bc98 (diff)
py: Add LOAD_SUPER_METHOD bytecode to allow heap-free super meth calls.
This patch allows the following code to run without allocating on the heap: super().foo(...) Before this patch such a call would allocate a super object on the heap and then load the foo method and call it right away. The super object is only needed to perform the lookup of the method and not needed after that. This patch makes an optimisation to allocate the super object on the C stack and discard it right after use. Changes in code size due to this patch are: bare-arm: +128 minimal: +232 unix x64: +416 unix nanbox: +364 stmhal: +184 esp8266: +340 cc3200: +128
Diffstat (limited to 'py/objtype.c')
-rw-r--r--py/objtype.c5
1 files changed, 5 insertions, 0 deletions
diff --git a/py/objtype.c b/py/objtype.c
index de1ee8c42..2a119e40f 100644
--- a/py/objtype.c
+++ b/py/objtype.c
@@ -1070,6 +1070,11 @@ const mp_obj_type_t mp_type_super = {
.attr = super_attr,
};
+void mp_load_super_method(qstr attr, mp_obj_t *dest) {
+ mp_obj_super_t super = {{&mp_type_super}, dest[1], dest[2]};
+ mp_load_method(MP_OBJ_FROM_PTR(&super), attr, dest);
+}
+
/******************************************************************************/
// subclassing and built-ins specific to types