Skip to content

Commit 7f130ef

Browse files
committed
py/objtype: Rework special accessor check's early-termination.
Signed-off-by: Anson Mansfield <amansfield@mantaro.com>
1 parent 0126fad commit 7f130ef

File tree

1 file changed

+19
-14
lines changed

1 file changed

+19
-14
lines changed

py/objtype.c

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1265,23 +1265,28 @@ mp_obj_t mp_obj_new_type(qstr name, mp_obj_t bases_tuple, mp_obj_t locals_dict)
12651265
#if ENABLE_SPECIAL_ACCESSORS
12661266
// Check if the class has any special accessor methods,
12671267
// and accumulate bound __set_name__ methods that need to be called
1268-
if (MICROPY_PY_DESCRIPTORS || !(o->flags & MP_TYPE_FLAG_HAS_SPECIAL_ACCESSORS)) {
1269-
for (size_t i = 0; i < locals_ptr->map.alloc; i++) {
1270-
if (mp_map_slot_is_filled(&locals_ptr->map, i)) {
1271-
const mp_map_elem_t *elem = &locals_ptr->map.table[i];
1272-
if (check_for_special_accessors(elem->key, elem->value)) {
1273-
o->flags |= MP_TYPE_FLAG_HAS_SPECIAL_ACCESSORS;
1274-
#if !(MICROPY_PY_DESCRIPTORS)
1275-
break;
1276-
#endif
1277-
}
1278-
#if MICROPY_PY_DESCRIPTORS
1279-
setname_tail = setname_maybe_bind_append(setname_tail, elem->key, elem->value);
1280-
#endif
1268+
for (size_t i = 0; i < locals_ptr->map.alloc; i++) {
1269+
#if !MICROPY_PY_DESCRIPTORS
1270+
// __set_name__ needs to scan the entire locals map, can't early-terminate
1271+
if (o->flags & MP_TYPE_FLAG_HAS_SPECIAL_ACCESSORS) {
1272+
break;
1273+
}
1274+
#endif
1275+
1276+
if (mp_map_slot_is_filled(&locals_ptr->map, i)) {
1277+
const mp_map_elem_t *elem = &locals_ptr->map.table[i];
1278+
1279+
if (!(o->flags & MP_TYPE_FLAG_HAS_SPECIAL_ACCESSORS) // elidable when the early-termination check is enabled
1280+
&& check_for_special_accessors(elem->key, elem->value)) {
1281+
o->flags |= MP_TYPE_FLAG_HAS_SPECIAL_ACCESSORS;
12811282
}
1283+
1284+
#if MICROPY_PY_DESCRIPTORS
1285+
setname_tail = setname_maybe_bind_append(setname_tail, elem->key, elem->value);
1286+
#endif
12821287
}
12831288
}
1284-
#endif
1289+
#endif // ENABLE_SPECIAL_ACCESSORS
12851290

12861291
const mp_obj_type_t *native_base;
12871292
size_t num_native_bases = instance_count_native_bases(o, &native_base);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy