diff options
author | Antoine Pitrou <solipsis@pitrou.net> | 2009-05-02 21:41:14 (GMT) |
---|---|---|
committer | Antoine Pitrou <solipsis@pitrou.net> | 2009-05-02 21:41:14 (GMT) |
commit | a9f48a0d4f0bad22275b5feb78f63a8a8f00a6f8 (patch) | |
tree | 2b8fe03afda19f7380363d50af4934b0b4893a1b /Modules | |
parent | 6fa98fb7ecee40329c5e8d74f583272ffedc97f9 (diff) | |
download | cpython-a9f48a0d4f0bad22275b5feb78f63a8a8f00a6f8.zip cpython-a9f48a0d4f0bad22275b5feb78f63a8a8f00a6f8.tar.gz cpython-a9f48a0d4f0bad22275b5feb78f63a8a8f00a6f8.tar.bz2 |
Merged revisions 72223 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r72223 | antoine.pitrou | 2009-05-02 23:13:23 +0200 (sam., 02 mai 2009) | 5 lines
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.
........
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/_pickle.c | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/Modules/_pickle.c b/Modules/_pickle.c index e9c4a76..754d132 100644 --- a/Modules/_pickle.c +++ b/Modules/_pickle.c @@ -4020,6 +4020,8 @@ load_build(UnpicklerObject *self) /* Set inst.__dict__ from the state dict (if any). */ if (state != Py_None) { PyObject *dict; + PyObject *d_key, *d_value; + Py_ssize_t i; if (!PyDict_Check(state)) { PyErr_SetString(UnpicklingError, "state is not a dictionary"); @@ -4029,7 +4031,19 @@ load_build(UnpicklerObject *self) if (dict == NULL) goto error; - PyDict_Update(dict, state); + i = 0; + while (PyDict_Next(state, &i, &d_key, &d_value)) { + /* normally the keys for instance attributes are + interned. we should try to do that here. */ + Py_INCREF(d_key); + if (PyUnicode_CheckExact(d_key)) + PyUnicode_InternInPlace(&d_key); + if (PyObject_SetItem(dict, d_key, d_value) < 0) { + Py_DECREF(d_key); + goto error; + } + Py_DECREF(d_key); + } Py_DECREF(dict); } |