diff options
author | Tim Peters <tim.peters@gmail.com> | 2003-01-28 01:00:38 (GMT) |
---|---|---|
committer | Tim Peters <tim.peters@gmail.com> | 2003-01-28 01:00:38 (GMT) |
commit | 518df0dae473922397fa1bc3315d3576df9469f7 (patch) | |
tree | 2f7f500559a5be9c5283fafaa75491544ab645d1 /Lib/pickle.py | |
parent | b32a8317d7a9c47bf9e6a863f0cc3112a252c66e (diff) | |
download | cpython-518df0dae473922397fa1bc3315d3576df9469f7.zip cpython-518df0dae473922397fa1bc3315d3576df9469f7.tar.gz cpython-518df0dae473922397fa1bc3315d3576df9469f7.tar.bz2 |
Several routines appeared to inline the guts of memoize(), possibly for
some notion of low-level efficiency. Undid that, but left one routine
alone: save_inst() claims it has a reason for not using memoize().
I don't understand that comment, so added an XXX comment there.
Diffstat (limited to 'Lib/pickle.py')
-rw-r--r-- | Lib/pickle.py | 21 |
1 files changed, 9 insertions, 12 deletions
diff --git a/Lib/pickle.py b/Lib/pickle.py index 58c4ba0..daae16e 100644 --- a/Lib/pickle.py +++ b/Lib/pickle.py @@ -215,10 +215,9 @@ class Pickler: # But there appears no advantage to any other scheme, and this # scheme allows the Unpickler memo to be implemented as a plain (but # growable) array, indexed by memo key. - d = id(obj) memo_len = len(self.memo) self.write(self.put(memo_len)) - self.memo[d] = memo_len, obj + self.memo[id(obj)] = memo_len, obj # Return a PUT (BINPUT, LONG_BINPUT) opcode string, with argument i. def put(self, i): @@ -325,9 +324,7 @@ class Pickler: "by %s must be a tuple" % reduce self.save_reduce(callable, arg_tup, state) - memo_len = len(memo) - self.write(self.put(memo_len)) - memo[d] = (memo_len, object) + self.memoize(object) def persistent_id(self, object): return None @@ -472,9 +469,8 @@ class Pickler: write(POP * (len(object) + 1) + self.get(memo[d][0])) return - memo_len = len(memo) - self.write(TUPLE + self.put(memo_len)) - memo[d] = (memo_len, object) + self.write(TUPLE) + self.memoize(object) dispatch[TupleType] = save_tuple @@ -566,6 +562,9 @@ class Pickler: # 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)) @@ -612,10 +611,8 @@ class Pickler: "Can't pickle %r: it's not the same object as %s.%s" % (object, module, name)) - memo_len = len(memo) - write(GLOBAL + module + '\n' + name + '\n' + - self.put(memo_len)) - memo[id(object)] = (memo_len, object) + write(GLOBAL + module + '\n' + name + '\n') + self.memoize(object) dispatch[ClassType] = save_global dispatch[FunctionType] = save_global dispatch[BuiltinFunctionType] = save_global |