Skip to content

Commit 17d0265

Browse files
Use slotdefs_name_counts to check name duplicates
1 parent 9f48eb3 commit 17d0265

2 files changed

Lines changed: 8 additions & 8 deletions

File tree

Include/cpython/descrobject.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,6 @@ struct wrapperbase {
1616
const char *doc;
1717
int flags;
1818
PyObject *name_strobj;
19-
20-
/* Stores the number of times where slotdefs has elements with this name.
21-
This counter precalculated by _PyType_InitSlotDefs when main
22-
interprepter starts.
23-
*/
24-
uint8_t name_count;
2519
};
2620

2721
/* Flags for above struct */

Objects/typeobject.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11002,6 +11002,10 @@ static pytype_slotdef slotdefs[] = {
1100211002
{NULL}
1100311003
};
1100411004

11005+
/* Stores the number of times where slotdefs has elements with same name.
11006+
This counter precalculated by _PyType_InitSlotDefs when main
11007+
interprepter starts. */
11008+
static uint8_t slotdefs_name_counts[Py_ARRAY_LENGTH(slotdefs)];
1100511009

1100611010
/* Given a type pointer and an offset gotten from a slotdef entry, return a
1100711011
pointer to the actual slot. This is not quite the same as simply adding
@@ -11148,7 +11152,7 @@ update_one_slot(PyTypeObject *type, pytype_slotdef *p)
1114811152
if (Py_IS_TYPE(descr, &PyWrapperDescr_Type) &&
1114911153
((PyWrapperDescrObject *)descr)->d_base->name_strobj == p->name_strobj) {
1115011154
void **tptr = NULL;
11151-
if (p->name_count == 1)
11155+
if (slotdefs_name_counts[(p - slotdefs) / sizeof(pytype_slotdef)] == 1)
1115211156
tptr = slotptr(type, p->offset);
1115311157

1115411158
if (tptr == NULL || tptr == ptr)
@@ -11357,6 +11361,8 @@ _PyType_InitSlotDefs(PyInterpreterState *interp)
1135711361
Py_CLEAR(bytearray);
1135811362
}
1135911363

11364+
memset(slotdefs_name_counts, 0, sizeof(slotdefs_name_counts));
11365+
1136011366
Py_ssize_t pos=0;
1136111367
PyObject *key=NULL;
1136211368
PyObject *value=NULL;
@@ -11366,7 +11372,7 @@ _PyType_InitSlotDefs(PyInterpreterState *interp)
1136611372
uint8_t i = 0;
1136711373
for(; i < n; i++) {
1136811374
uint8_t idx = data[i + 1];
11369-
slotdefs[idx].name_count = n;
11375+
slotdefs_name_counts[idx] = n;
1137011376
}
1137111377
}
1137211378

0 commit comments

Comments
 (0)