Commit d97da80d authored by Tim Peters's avatar Tim Peters

save_tuple(): So long as the charter is rewriting for clarity, the snaky

control flow had to be simplified.
parent ff57bff1
...@@ -458,17 +458,16 @@ class Pickler: ...@@ -458,17 +458,16 @@ class Pickler:
def save_tuple(self, object): def save_tuple(self, object):
write = self.write write = self.write
save = self.save
memo = self.memo
proto = self.proto proto = self.proto
if proto >= 1:
n = len(object) n = len(object)
if n <= 3: if n == 0 and proto:
if not object:
write(EMPTY_TUPLE) write(EMPTY_TUPLE)
return return
if proto >= 2:
save = self.save
memo = self.memo
if n <= 3 and proto >= 2:
for element in object: for element in object:
save(element) save(element)
# Subtle. Same as in the big comment below. # Subtle. Same as in the big comment below.
...@@ -486,7 +485,7 @@ class Pickler: ...@@ -486,7 +485,7 @@ class Pickler:
for element in object: for element in object:
save(element) save(element)
if object and id(object) in memo: if n and id(object) in memo:
# Subtle. d was not in memo when we entered save_tuple(), so # Subtle. d was not in memo when we entered save_tuple(), so
# the process of saving the tuple's elements must have saved # the process of saving the tuple's elements must have saved
# the tuple itself: the tuple is recursive. The proper action # the tuple itself: the tuple is recursive. The proper action
...@@ -498,7 +497,7 @@ class Pickler: ...@@ -498,7 +497,7 @@ class Pickler:
if proto: if proto:
write(POP_MARK + get) write(POP_MARK + get)
else: # proto 0 -- POP_MARK not available else: # proto 0 -- POP_MARK not available
write(POP * (len(object) + 1) + get) write(POP * (n+1) + get)
return return
# No recursion (including the empty-tuple case for protocol 0). # No recursion (including the empty-tuple case for protocol 0).
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment