From 21c18f0bf5c3edc6ed226f71d36910292575fb92 Mon Sep 17 00:00:00 2001 From: Tim Peters Date: Tue, 28 Jan 2003 01:15:46 +0000 Subject: [PATCH] save_list(): Rewrote, to untangle the proto 0 from the proto 1 cases. The code is much easier to follow now, and I bet it's faster too. --- Lib/pickle.py | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/Lib/pickle.py b/Lib/pickle.py index b4a7e280d8b..f8ecad592cf 100644 --- a/Lib/pickle.py +++ b/Lib/pickle.py @@ -483,24 +483,26 @@ class Pickler: if self.bin: write(EMPTY_LIST) - else: + self.memoize(object) + n = len(object) + if n > 1: + write(MARK) + for element in object: + save(element) + write(APPENDS) + elif n: + assert n == 1 + save(object[0]) + write(APPEND) + # else the list is empty, and we're already done + + else: # proto 0 -- can't use EMPTY_LIST or APPENDS write(MARK + LIST) - - self.memoize(object) - - using_appends = (self.bin and (len(object) > 1)) - - if using_appends: - write(MARK) - - for element in object: - save(element) - - if not using_appends: + self.memoize(object) + for element in object: + save(element) write(APPEND) - if using_appends: - write(APPENDS) dispatch[ListType] = save_list def save_dict(self, object):