Skip to content

Commit 5db0944

Browse files
Apply suggestions from code review
Co-authored-by: Victor Stinner <[email protected]>
1 parent 25acb4a commit 5db0944

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

Objects/typeobject.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11423,7 +11423,7 @@ static pytype_slotdef slotdefs[] = {
1142311423
};
1142411424

1142511425
/* Stores the number of times where slotdefs has elements with same name.
11426-
This counter precalculated by _PyType_InitSlotDefs when main
11426+
This counter precalculated by _PyType_InitSlotDefs() when the main
1142711427
interpreter starts. */
1142811428
static uint8_t slotdefs_name_counts[Py_ARRAY_LENGTH(slotdefs)];
1142911429

@@ -11595,9 +11595,14 @@ update_one_slot(PyTypeObject *type, pytype_slotdef *p, pytype_slotdef **next_p,
1159511595
}
1159611596
if (Py_IS_TYPE(descr, &PyWrapperDescr_Type) &&
1159711597
((PyWrapperDescrObject *)descr)->d_base->name_strobj == p->name_strobj) {
11598-
void **tptr = NULL;
11599-
if (slotdefs_name_counts[(p - slotdefs) / sizeof(pytype_slotdef)] == 1)
11598+
void **tptr;
11599+
size_t index = (p - slotdefs) / sizeof(slotdef[0]);
11600+
if (slotdefs_name_counts[index] == 1) {
1160011601
tptr = slotptr(type, p->offset);
11602+
}
11603+
else {
11604+
tptr = NULL;
11605+
}
1160111606

1160211607
if (tptr == NULL || tptr == ptr)
1160311608
generic = p->function;
@@ -11866,8 +11871,7 @@ _PyType_InitSlotDefs(PyInterpreterState *interp)
1186611871
while (PyDict_Next(cache, &pos, &key, &value)) {
1186711872
uint8_t *data = (uint8_t *)PyByteArray_AS_STRING(value);
1186811873
uint8_t n = data[0];
11869-
uint8_t i = 0;
11870-
for(; i < n; i++) {
11874+
for(uint8_t i = 0; i < n; i++) {
1187111875
uint8_t idx = data[i + 1];
1187211876
slotdefs_name_counts[idx] = n;
1187311877
}

0 commit comments

Comments
 (0)