diff options
author | Tim Peters <tim.peters@gmail.com> | 2003-01-28 01:15:46 (GMT) |
---|---|---|
committer | Tim Peters <tim.peters@gmail.com> | 2003-01-28 01:15:46 (GMT) |
commit | 21c18f0bf5c3edc6ed226f71d36910292575fb92 (patch) | |
tree | e5d22c7250819f1290c6f65a555ff75aa2f3287a /Lib/pickle.py | |
parent | 22dc6f4f7a1007e7d61edbc1320286fc4bc03b81 (diff) | |
download | cpython-21c18f0bf5c3edc6ed226f71d36910292575fb92.zip cpython-21c18f0bf5c3edc6ed226f71d36910292575fb92.tar.gz cpython-21c18f0bf5c3edc6ed226f71d36910292575fb92.tar.bz2 |
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.
Diffstat (limited to 'Lib/pickle.py')
-rw-r--r-- | Lib/pickle.py | 32 |
1 files changed, 17 insertions, 15 deletions
diff --git a/Lib/pickle.py b/Lib/pickle.py index b4a7e28..f8ecad5 100644 --- a/Lib/pickle.py +++ b/Lib/pickle.py @@ -483,24 +483,26 @@ class Pickler: if self.bin: write(EMPTY_LIST) - else: - 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) + 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 - if not using_appends: + else: # proto 0 -- can't use EMPTY_LIST or APPENDS + write(MARK + LIST) + 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): |