summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorTim Peters <tim.peters@gmail.com>2003-01-28 03:51:36 (GMT)
committerTim Peters <tim.peters@gmail.com>2003-01-28 03:51:36 (GMT)
commit3b769835cac554a947327facc9458a23069d701c (patch)
tree4a3ca5e2cb5f67c2b4087d428a57d230d408d04e /Lib
parentd6c9e63af9b574389dc4e27c44642d522f1abfbf (diff)
downloadcpython-3b769835cac554a947327facc9458a23069d701c.zip
cpython-3b769835cac554a947327facc9458a23069d701c.tar.gz
cpython-3b769835cac554a947327facc9458a23069d701c.tar.bz2
save_inst(): Rewrote to have only one branch on self.bin. Also got rid
of my recent XXX comment, taking a (what appears to be vanishingly small) chance and calling self.memoize() instead.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/pickle.py25
1 files changed, 9 insertions, 16 deletions
diff --git a/Lib/pickle.py b/Lib/pickle.py
index ebc2b68..ca98ae3 100644
--- a/Lib/pickle.py
+++ b/Lib/pickle.py
@@ -551,7 +551,6 @@ class Pickler:
dispatch[PyStringMap] = save_dict
def save_inst(self, object):
- d = id(object)
cls = object.__class__
memo = self.memo
@@ -569,23 +568,15 @@ class Pickler:
if self.bin:
save(cls)
-
- for arg in args:
- save(arg)
-
- # This method does not use memoize() so that it can handle
- # the special case for non-binary mode.
- # XXX What did that comment mean? That is, what "special case for
- # XXX non-binary mode"? It sure *looks* like nothing special is
- # XXX happening in the INST case.
- memo_len = len(memo)
- if self.bin:
- write(OBJ + self.put(memo_len))
+ for arg in args:
+ save(arg)
+ write(OBJ)
else:
- write(INST + cls.__module__ + '\n' + cls.__name__ + '\n' +
- self.put(memo_len))
+ for arg in args:
+ save(arg)
+ write(INST + cls.__module__ + '\n' + cls.__name__ + '\n')
- memo[d] = (memo_len, object)
+ self.memoize(object)
try:
getstate = object.__getstate__
@@ -596,6 +587,7 @@ class Pickler:
_keep_alive(stuff, memo)
save(stuff)
write(BUILD)
+
dispatch[InstanceType] = save_inst
def save_global(self, object, name = None):
@@ -626,6 +618,7 @@ class Pickler:
write(GLOBAL + module + '\n' + name + '\n')
self.memoize(object)
+
dispatch[ClassType] = save_global
dispatch[FunctionType] = save_global
dispatch[BuiltinFunctionType] = save_global