Skip to content

Commit 666b68e

Browse files
authored
GH-106485: Create object's dict-values instead of creating __dict__, when we can. (GH-107843)
1 parent 66e4edd commit 666b68e

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

Objects/dictobject.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5762,10 +5762,8 @@ _PyObjectDict_SetItem(PyTypeObject *tp, PyObject **dictptr,
57625762
assert(dictptr != NULL);
57635763
dict = *dictptr;
57645764
if (dict == NULL) {
5765+
assert(!_PyType_HasFeature(tp, Py_TPFLAGS_MANAGED_DICT));
57655766
dictkeys_incref(cached);
5766-
if (_PyType_HasFeature(tp, Py_TPFLAGS_MANAGED_DICT)) {
5767-
OBJECT_STAT_INC(dict_materialized_on_request);
5768-
}
57695767
dict = new_dict_with_shared_keys(interp, cached);
57705768
if (dict == NULL)
57715769
return -1;

Objects/object.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1577,6 +1577,14 @@ _PyObject_GenericSetAttrWithDict(PyObject *obj, PyObject *name,
15771577
goto error_check;
15781578
}
15791579
dictptr = &dorv_ptr->dict;
1580+
if (*dictptr == NULL) {
1581+
if (_PyObject_InitInlineValues(obj, tp) < 0) {
1582+
goto done;
1583+
}
1584+
res = _PyObject_StoreInstanceAttribute(
1585+
obj, _PyDictOrValues_GetValues(*dorv_ptr), name, value);
1586+
goto error_check;
1587+
}
15801588
}
15811589
else {
15821590
dictptr = _PyObject_ComputedDictPointer(obj);

0 commit comments

Comments
 (0)