Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Reduce the memory consumption of instances of classes which define
``__slots__`` and also have a ``__dict__``. Space for the attributes stored
in slots is no longer reserved in the inline values of every instance.
5 changes: 5 additions & 0 deletions Objects/dictobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -7286,6 +7286,11 @@ _PyDict_NewKeysForClass(PyHeapTypeObject *cls)
PyObject *key = PyTuple_GET_ITEM(attrs, i);
Py_hash_t hash;
if (PyUnicode_CheckExact(key) && (hash = unicode_get_hash(key)) != -1) {
/* An attribute stored in a slot never uses the dict. */
PyObject *descr = _PyType_Lookup((PyTypeObject *)cls, key);
if (descr != NULL && Py_IS_TYPE(descr, &PyMemberDescr_Type)) {
continue;
}
if (insert_split_key(keys, key, hash) == DKIX_EMPTY) {
break;
}
Expand Down
Loading