Skip to content

Commit b69bfbd

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

File tree

1 file changed

+21
-14
lines changed

1 file changed

+21
-14
lines changed

py/objtype.c

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1265,23 +1265,30 @@ mp_obj_t mp_obj_new_type(qstr name, mp_obj_t bases_tuple, mp_obj_t locals_dict)
12651265
#if MICROPY_PY_METACLASSES_LITE || 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_METACLASSES_LITE || !(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_METACLASSES_LITE)
1275-
break;
1276-
#endif
1277-
}
1278-
#if MICROPY_PY_METACLASSES_LITE
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_METACLASSES_LITE
1270+
// metaclasses-lite 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 ENABLE_SPECIAL_ACCESSORS
1280+
if ((o->flags & MP_TYPE_FLAG_HAS_SPECIAL_ACCESSORS) // elidable when the early-termination check is enabled
1281+
&& check_for_special_accessors(elem->key, elem->value)) {
1282+
o->flags |= MP_TYPE_FLAG_HAS_SPECIAL_ACCESSORS;
12811283
}
1284+
#endif
1285+
1286+
#if MICROPY_PY_METACLASSES_LITE
1287+
setname_tail = setname_maybe_bind_append(setname_tail, elem->key, elem->value);
1288+
#endif
12821289
}
12831290
}
1284-
#endif
1291+
#endif // MICROPY_PY_METACLASSES_LITE || ENABLE_SPECIAL_ACCESSORS
12851292

12861293
const mp_obj_type_t *native_base;
12871294
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