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.
This commit is contained in:
Tim Peters 2003-01-28 03:51:36 +00:00
parent d6c9e63af9
commit 3b769835ca

View file

@ -551,7 +551,6 @@ class Pickler:
dispatch[PyStringMap] = save_dict dispatch[PyStringMap] = save_dict
def save_inst(self, object): def save_inst(self, object):
d = id(object)
cls = object.__class__ cls = object.__class__
memo = self.memo memo = self.memo
@ -569,23 +568,15 @@ class Pickler:
if self.bin: if self.bin:
save(cls) save(cls)
for arg in args:
for arg in args: save(arg)
save(arg) write(OBJ)
# 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))
else: else:
write(INST + cls.__module__ + '\n' + cls.__name__ + '\n' + for arg in args:
self.put(memo_len)) save(arg)
write(INST + cls.__module__ + '\n' + cls.__name__ + '\n')
memo[d] = (memo_len, object) self.memoize(object)
try: try:
getstate = object.__getstate__ getstate = object.__getstate__
@ -596,6 +587,7 @@ class Pickler:
_keep_alive(stuff, memo) _keep_alive(stuff, memo)
save(stuff) save(stuff)
write(BUILD) write(BUILD)
dispatch[InstanceType] = save_inst dispatch[InstanceType] = save_inst
def save_global(self, object, name = None): def save_global(self, object, name = None):
@ -626,6 +618,7 @@ class Pickler:
write(GLOBAL + module + '\n' + name + '\n') write(GLOBAL + module + '\n' + name + '\n')
self.memoize(object) self.memoize(object)
dispatch[ClassType] = save_global dispatch[ClassType] = save_global
dispatch[FunctionType] = save_global dispatch[FunctionType] = save_global
dispatch[BuiltinFunctionType] = save_global dispatch[BuiltinFunctionType] = save_global