py: Combine load_attr and store_attr type methods into one (attr).
This simplifies the API for objects and reduces code size (by around 400
bytes on Thumb2, and around 2k on x86). Performance impact was measured
with Pystone score, but change was barely noticeable.
diff --git a/py/objrange.c b/py/objrange.c
index ff62cc5..9f7e659 100644
--- a/py/objrange.c
+++ b/py/objrange.c
@@ -168,7 +168,11 @@
#if MICROPY_PY_BUILTINS_RANGE_ATTRS
-STATIC void range_load_attr(mp_obj_t o_in, qstr attr, mp_obj_t *dest) {
+STATIC void range_attr(mp_obj_t o_in, qstr attr, mp_obj_t *dest) {
+ if (dest[0] != MP_OBJ_NULL) {
+ // not load attribute
+ return;
+ }
mp_obj_range_t *o = o_in;
if (attr == MP_QSTR_start) {
dest[0] = mp_obj_new_int(o->start);
@@ -189,6 +193,6 @@
.subscr = range_subscr,
.getiter = range_getiter,
#if MICROPY_PY_BUILTINS_RANGE_ATTRS
- .load_attr = range_load_attr,
+ .attr = range_attr,
#endif
};