]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
GH-106485: Create object's dict-values instead of creating __dict__, when we can...
authorMark Shannon <mark@hotpy.org>
Fri, 11 Aug 2023 19:05:56 +0000 (20:05 +0100)
committerGitHub <noreply@github.com>
Fri, 11 Aug 2023 19:05:56 +0000 (20:05 +0100)
Objects/dictobject.c
Objects/object.c

index 36375f50646fd415998e5123215235403a2b49f2..f9701f6b4b09ad27aba9465c1baf79abfcae2353 100644 (file)
@@ -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;
index d1154eb344fab1ab73410c6dab71009553cc0814..868623a9f7bffc2acabc444ac2d361c09ce5da16 100644 (file)
@@ -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);