From c78ef92d787d7bab8acbec69e978037ec2b20d21 Mon Sep 17 00:00:00 2001 From: Damien George Date: Tue, 12 Dec 2017 15:22:03 +1100 Subject: py/objtype: Refactor object's handling of __new__ to not create 2 objs. Before this patch, if a user defined the __new__() function for a class then two instances of that class would be created: once before __new__ is called and once during the __new__ call (assuming the user creates some instance, eg using super().__new__, which is most of the time). The first one was then discarded. This refactor makes it so that a new instance is only created if the user __new__ function doesn't exist. --- py/objtype.h | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'py/objtype.h') diff --git a/py/objtype.h b/py/objtype.h index 52419f3cd..1f4313084 100644 --- a/py/objtype.h +++ b/py/objtype.h @@ -37,6 +37,11 @@ typedef struct _mp_obj_instance_t { // TODO maybe cache __getattr__ and __setattr__ for efficient lookup of them } mp_obj_instance_t; +#if MICROPY_CPYTHON_COMPAT +// this is needed for object.__new__ +mp_obj_instance_t *mp_obj_new_instance(const mp_obj_type_t *cls, const mp_obj_type_t **native_base); +#endif + // this needs to be exposed for MICROPY_OPT_CACHE_MAP_LOOKUP_IN_BYTECODE to work void mp_obj_instance_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest); -- cgit v1.2.3