aboutsummaryrefslogtreecommitdiff
path: root/extmod
diff options
context:
space:
mode:
authorDamien George2015-04-01 14:10:50 +0000
committerDamien George2015-04-11 16:54:37 +0100
commitb1bbe966c408901ae64ea8c8b468694c47d05b1a (patch)
tree46025c34daf602aeb1e8def41d1e01f0750b6d13 /extmod
parentd07ccc5a394d0252ffbc227509ed2134465c215a (diff)
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.
Diffstat (limited to 'extmod')
-rw-r--r--extmod/moductypes.c21
1 files changed, 12 insertions, 9 deletions
diff --git a/extmod/moductypes.c b/extmod/moductypes.c
index 7e7128a26..f9f0ca79b 100644
--- a/extmod/moductypes.c
+++ b/extmod/moductypes.c
@@ -482,13 +482,17 @@ STATIC mp_obj_t uctypes_struct_attr_op(mp_obj_t self_in, qstr attr, mp_obj_t set
return MP_OBJ_NULL;
}
-STATIC void uctypes_struct_load_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) {
- mp_obj_t val = uctypes_struct_attr_op(self_in, attr, MP_OBJ_NULL);
- *dest = val;
-}
-
-STATIC bool uctypes_struct_store_attr(mp_obj_t self_in, qstr attr, mp_obj_t val) {
- return uctypes_struct_attr_op(self_in, attr, val) != MP_OBJ_NULL;
+STATIC void uctypes_struct_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) {
+ if (dest[0] == MP_OBJ_NULL) {
+ // load attribute
+ mp_obj_t val = uctypes_struct_attr_op(self_in, attr, MP_OBJ_NULL);
+ dest[0] = val;
+ } else {
+ // delete/store attribute
+ if (uctypes_struct_attr_op(self_in, attr, dest[1]) != MP_OBJ_NULL) {
+ dest[0] = MP_OBJ_NULL; // indicate success
+ }
+ }
}
STATIC mp_obj_t uctypes_struct_subscr(mp_obj_t self_in, mp_obj_t index_in, mp_obj_t value) {
@@ -589,8 +593,7 @@ STATIC const mp_obj_type_t uctypes_struct_type = {
.name = MP_QSTR_struct,
.print = uctypes_struct_print,
.make_new = uctypes_struct_make_new,
- .load_attr = uctypes_struct_load_attr,
- .store_attr = uctypes_struct_store_attr,
+ .attr = uctypes_struct_attr,
.subscr = uctypes_struct_subscr,
};