mirror of
https://github.com/python/cpython.git
synced 2025-08-03 16:39:00 +00:00
Isue #5084: unpickling now interns the attribute names of pickled objects,
saving memory and avoiding growth in size of subsequent pickles. Proposal and original patch by Jake McGuire.
This commit is contained in:
parent
2b42c29a50
commit
7430989cda
4 changed files with 36 additions and 2 deletions
|
@ -4473,8 +4473,16 @@ load_build(Unpicklerobject *self)
|
|||
|
||||
i = 0;
|
||||
while (PyDict_Next(state, &i, &d_key, &d_value)) {
|
||||
if (PyObject_SetItem(dict, d_key, d_value) < 0)
|
||||
/* normally the keys for instance attributes are
|
||||
interned. we should try to do that here. */
|
||||
Py_INCREF(d_key);
|
||||
if (PyString_CheckExact(d_key))
|
||||
PyString_InternInPlace(&d_key);
|
||||
if (PyObject_SetItem(dict, d_key, d_value) < 0) {
|
||||
Py_DECREF(d_key);
|
||||
goto finally;
|
||||
}
|
||||
Py_DECREF(d_key);
|
||||
}
|
||||
Py_DECREF(dict);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue