@@ -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