summaryrefslogtreecommitdiffstats
path: root/Lib/pickle.py
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2009-05-02 21:41:14 (GMT)
committerAntoine Pitrou <solipsis@pitrou.net>2009-05-02 21:41:14 (GMT)
commita9f48a0d4f0bad22275b5feb78f63a8a8f00a6f8 (patch)
tree2b8fe03afda19f7380363d50af4934b0b4893a1b /Lib/pickle.py
parent6fa98fb7ecee40329c5e8d74f583272ffedc97f9 (diff)
downloadcpython-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 'Lib/pickle.py')
-rw-r--r--Lib/pickle.py10
1 files changed, 9 insertions, 1 deletions
diff --git a/Lib/pickle.py b/Lib/pickle.py
index 409d4b2..b94b305 100644
--- a/Lib/pickle.py
+++ b/Lib/pickle.py
@@ -1195,7 +1195,15 @@ class _Unpickler:
if isinstance(state, tuple) and len(state) == 2:
state, slotstate = state
if state:
- inst.__dict__.update(state)
+ d = inst.__dict__
+ intern = sys.intern
+ try:
+ for k, v in state.items():
+ d[intern(k)] = v
+ # keys in state don't have to be strings
+ # don't blow up, but don't go out of our way
+ except TypeError:
+ d.update(state)
if slotstate:
for k, v in slotstate.items():
setattr(inst, k, v)