Skip to content

Commit 1459c16

Browse files
Revert "Prebuild mro_dict for find_name_in_mro"
This reverts commit 56d13fc.
1 parent b6fafa9 commit 1459c16

1 file changed

Lines changed: 4 additions & 55 deletions

File tree

Objects/typeobject.c

Lines changed: 4 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -5636,26 +5636,6 @@ find_name_in_mro(PyTypeObject *type, PyObject *name, int *error)
56365636
return res;
56375637
}
56385638

5639-
static PyObject *
5640-
find_name_in_mro_new(PyObject *mro_dict, PyObject *name, int *error)
5641-
{
5642-
ASSERT_TYPE_LOCK_HELD();
5643-
5644-
Py_hash_t hash = _PyObject_HashFast(name);
5645-
if (hash == -1) {
5646-
*error = -1;
5647-
return NULL;
5648-
}
5649-
5650-
PyObject *res = NULL;
5651-
if (_PyDict_GetItemRef_KnownHash((PyDictObject *)mro_dict, name, hash, &res) < 0) {
5652-
*error = -1;
5653-
} else {
5654-
*error = 0;
5655-
}
5656-
return res;
5657-
}
5658-
56595639
/* Check if the "readied" PyUnicode name
56605640
is a double-underscore special name. */
56615641
static int
@@ -11065,7 +11045,7 @@ slotptr(PyTypeObject *type, int ioffset)
1106511045
* because that's convenient for fixup_slot_dispatchers(). This function never
1106611046
* sets an exception: if an internal error happens (unlikely), it's ignored. */
1106711047
static pytype_slotdef *
11068-
update_one_slot(PyTypeObject *type, pytype_slotdef *p, PyObject *mro_dict)
11048+
update_one_slot(PyTypeObject *type, pytype_slotdef *p)
1106911049
{
1107011050
ASSERT_TYPE_LOCK_HELD();
1107111051

@@ -11096,11 +11076,7 @@ update_one_slot(PyTypeObject *type, pytype_slotdef *p, PyObject *mro_dict)
1109611076
assert(!PyErr_Occurred());
1109711077
do {
1109811078
/* Use faster uncached lookup as we won't get any cache hits during type setup. */
11099-
if (mro_dict == NULL) {
11100-
descr = find_name_in_mro(type, p->name_strobj, &error);
11101-
} else {
11102-
descr = find_name_in_mro_new(mro_dict, p->name_strobj, &error);
11103-
}
11079+
descr = find_name_in_mro(type, p->name_strobj, &error);
1110411080
if (descr == NULL) {
1110511081
if (error == -1) {
1110611082
/* It is unlikely but not impossible that there has been an exception
@@ -11194,7 +11170,7 @@ update_slots_callback(PyTypeObject *type, void *data)
1119411170

1119511171
pytype_slotdef **pp = (pytype_slotdef **)data;
1119611172
for (; *pp; pp++) {
11197-
update_one_slot(type, *pp, NULL);
11173+
update_one_slot(type, *pp);
1119811174
}
1119911175
return 0;
1120011176
}
@@ -11247,38 +11223,11 @@ fixup_slot_dispatchers(PyTypeObject *type)
1124711223
// where we'd like to assert that the type is locked.
1124811224
BEGIN_TYPE_LOCK();
1124911225

11250-
PyObject *mro = lookup_tp_mro(type);
11251-
assert(mro);
11252-
11253-
PyObject *mro_dict = NULL;
11254-
Py_ssize_t n = PyTuple_GET_SIZE(mro);
11255-
for (Py_ssize_t i = 0; i < n; i++) {
11256-
PyObject *base = PyTuple_GET_ITEM(mro, n-i-1);
11257-
PyObject *dict = lookup_tp_dict(_PyType_CAST(base));
11258-
assert(dict && PyDict_Check(dict));
11259-
11260-
if (i == 0) {
11261-
mro_dict = PyDict_Copy(dict);
11262-
if (!mro_dict) {
11263-
PyErr_Clear();
11264-
break;
11265-
}
11266-
} else {
11267-
if (PyDict_Merge(mro_dict, dict, 1) < 0) {
11268-
Py_CLEAR(mro_dict);
11269-
PyErr_Clear();
11270-
break;
11271-
}
11272-
}
11273-
}
11274-
1127511226
assert(!PyErr_Occurred());
1127611227
for (pytype_slotdef *p = slotdefs; p->name; ) {
11277-
p = update_one_slot(type, p, mro_dict);
11228+
p = update_one_slot(type, p);
1127811229
}
1127911230

11280-
Py_XDECREF(mro_dict);
11281-
1128211231
END_TYPE_LOCK();
1128311232
}
1128411233

0 commit comments

Comments
 (0)