]> granicus.if.org Git - python/commitdiff
save_inst(): Rewrote to have only one branch on self.bin. Also got rid
authorTim Peters <tim.peters@gmail.com>
Tue, 28 Jan 2003 03:51:36 +0000 (03:51 +0000)
committerTim Peters <tim.peters@gmail.com>
Tue, 28 Jan 2003 03:51:36 +0000 (03:51 +0000)
of my recent XXX comment, taking a (what appears to be vanishingly small)
chance and calling self.memoize() instead.

Lib/pickle.py

index ebc2b68a9a1278a56ff7927855e8674dcbe17306..ca98ae3ea70db92b64d51b4a867aa79b28b5a39e 100644 (file)
@@ -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