Skip to content

Commit 943174b

Browse files
committed
Remove the loop in PyType_GetSlot; we already know the position
1 parent 2b077e3 commit 943174b

File tree

1 file changed

+8
-14
lines changed

1 file changed

+8
-14
lines changed

Objects/typeobject.c

+8-14
Original file line numberDiff line numberDiff line change
@@ -3145,21 +3145,15 @@ PyType_GetSlot(PyTypeObject *type, int slot)
31453145
return NULL;
31463146
}
31473147

3148-
for (int i = 1; i < slots_len; i++) {
3149-
if (i != slot) {
3150-
continue;
3151-
}
3152-
parent_slot = *(void**)((char*)type + pyslot_offsets[i].slot_offset);
3153-
if (parent_slot == NULL) {
3154-
return NULL;
3155-
}
3156-
/* Return slot directly if there have no sub slot. */
3157-
if (pyslot_offsets[i].subslot_offset == -1) {
3158-
return parent_slot;
3159-
}
3160-
return *(void**)((char*)parent_slot + pyslot_offsets[i].subslot_offset);
3148+
parent_slot = *(void**)((char*)type + pyslot_offsets[slot].slot_offset);
3149+
if (parent_slot == NULL) {
3150+
return NULL;
31613151
}
3162-
return NULL;
3152+
/* Return slot directly if we have no sub slot. */
3153+
if (pyslot_offsets[slot].subslot_offset == -1) {
3154+
return parent_slot;
3155+
}
3156+
return *(void**)((char*)parent_slot + pyslot_offsets[slot].subslot_offset);
31633157
}
31643158

31653159
PyObject *

0 commit comments

Comments
 (0)