summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2009-05-02 21:13:23 (GMT)
committerAntoine Pitrou <solipsis@pitrou.net>2009-05-02 21:13:23 (GMT)
commit7430989cdadfb5aacef6909a3e2c033a0209699b (patch)
tree7698e15757d641da2d648cde43438a0c6bf5ac02 /Modules
parent2b42c29a5040b39e481d976f4ec3d6aa425ab4cc (diff)
downloadcpython-7430989cdadfb5aacef6909a3e2c033a0209699b.zip
cpython-7430989cdadfb5aacef6909a3e2c033a0209699b.tar.gz
cpython-7430989cdadfb5aacef6909a3e2c033a0209699b.tar.bz2
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/cPickle.c10
1 files changed, 9 insertions, 1 deletions
diff --git a/Modules/cPickle.c b/Modules/cPickle.c
index 6c7ed99..a0e443e 100644
--- a/Modules/cPickle.c
+++ b/Modules/cPickle.c
@@ -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);
}