py: Revert mp_load_attr() to its previous state (not supporting default val).
Based on the discussion in #433. mp_load_attr() is critical-path function,
so any extra check will slowdown any script. As supporting default val
required only for getattr() builtin, move correspending implementation
there (still as a separate function due to concerns of maintainability
of such almost-duplicated code instances).
diff --git a/py/runtime.c b/py/runtime.c
index f9361a8..1ab971d 100644
--- a/py/runtime.c
+++ b/py/runtime.c
@@ -672,14 +672,12 @@
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "too many values to unpack (expected %d)", num));
}
-mp_obj_t mp_load_attr_default(mp_obj_t base, qstr attr, mp_obj_t defval) {
+mp_obj_t mp_load_attr(mp_obj_t base, qstr attr) {
DEBUG_OP_printf("load attr %p.%s\n", base, qstr_str(attr));
+ // use load_method
mp_obj_t dest[2];
- // use load_method, raising or not raising exception
- ((defval == MP_OBJ_NULL) ? mp_load_method : mp_load_method_maybe)(base, attr, dest);
- if (dest[0] == MP_OBJ_NULL) {
- return defval;
- } else if (dest[1] == MP_OBJ_NULL) {
+ mp_load_method(base, attr, dest);
+ if (dest[1] == MP_OBJ_NULL) {
// load_method returned just a normal attribute
return dest[0];
} else {
@@ -688,10 +686,6 @@
}
}
-mp_obj_t mp_load_attr(mp_obj_t base, qstr attr) {
- return mp_load_attr_default(base, attr, MP_OBJ_NULL);
-}
-
// no attribute found, returns: dest[0] == MP_OBJ_NULL, dest[1] == MP_OBJ_NULL
// normal attribute found, returns: dest[0] == <attribute>, dest[1] == MP_OBJ_NULL
// method attribute found, returns: dest[0] == <method>, dest[1] == <self>