diff options
author | Antoine Pitrou <solipsis@pitrou.net> | 2009-05-02 21:13:23 +0000 |
---|---|---|
committer | Antoine Pitrou <solipsis@pitrou.net> | 2009-05-02 21:13:23 +0000 |
commit | 7430989cdadfb5aacef6909a3e2c033a0209699b (patch) | |
tree | 7698e15757d641da2d648cde43438a0c6bf5ac02 /Lib/pickle.py | |
parent | 2b42c29a5040b39e481d976f4ec3d6aa425ab4cc (diff) | |
download | cpython-git-7430989cdadfb5aacef6909a3e2c033a0209699b.tar.gz |
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.py | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/Lib/pickle.py b/Lib/pickle.py index abed1ca4fa..8c5d51fc15 100644 --- a/Lib/pickle.py +++ b/Lib/pickle.py @@ -1221,7 +1221,15 @@ class Unpickler: state, slotstate = state if state: try: - inst.__dict__.update(state) + d = inst.__dict__ + try: + for k, v in state.iteritems(): + 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) + except RuntimeError: # XXX In restricted execution, the instance's __dict__ # is not accessible. Use the old way of unpickling |