[Python-checkins] GH-106485: Create object's dict-values instead of creating __dict__, when we can. (GH-107843)
markshannon
webhook-mailer at python.org
Fri Aug 11 15:06:00 EDT 2023
https://github.com/python/cpython/commit/666b68e8f252e3c6238d6eed1fc82937a774316f
commit: 666b68e8f252e3c6238d6eed1fc82937a774316f
branch: main
author: Mark Shannon <mark at hotpy.org>
committer: markshannon <mark at hotpy.org>
date: 2023-08-11T20:05:56+01:00
summary:
GH-106485: Create object's dict-values instead of creating __dict__, when we can. (GH-107843)
files:
M Objects/dictobject.c
M Objects/object.c
diff --git a/Objects/dictobject.c b/Objects/dictobject.c
index 36375f50646fd..f9701f6b4b09a 100644
--- a/Objects/dictobject.c
+++ b/Objects/dictobject.c
@@ -5762,10 +5762,8 @@ _PyObjectDict_SetItem(PyTypeObject *tp, PyObject **dictptr,
assert(dictptr != NULL);
dict = *dictptr;
if (dict == NULL) {
+ assert(!_PyType_HasFeature(tp, Py_TPFLAGS_MANAGED_DICT));
dictkeys_incref(cached);
- if (_PyType_HasFeature(tp, Py_TPFLAGS_MANAGED_DICT)) {
- OBJECT_STAT_INC(dict_materialized_on_request);
- }
dict = new_dict_with_shared_keys(interp, cached);
if (dict == NULL)
return -1;
diff --git a/Objects/object.c b/Objects/object.c
index d1154eb344fab..868623a9f7bff 100644
--- a/Objects/object.c
+++ b/Objects/object.c
@@ -1577,6 +1577,14 @@ _PyObject_GenericSetAttrWithDict(PyObject *obj, PyObject *name,
goto error_check;
}
dictptr = &dorv_ptr->dict;
+ if (*dictptr == NULL) {
+ if (_PyObject_InitInlineValues(obj, tp) < 0) {
+ goto done;
+ }
+ res = _PyObject_StoreInstanceAttribute(
+ obj, _PyDictOrValues_GetValues(*dorv_ptr), name, value);
+ goto error_check;
+ }
}
else {
dictptr = _PyObject_ComputedDictPointer(obj);
More information about the Python-checkins
mailing list