summaryrefslogtreecommitdiffstats
path: root/Lib/collections.py
diff options
context:
space:
mode:
authorAlexandre Vassalotti <alexandre@peadrop.com>2009-06-12 21:52:14 (GMT)
committerAlexandre Vassalotti <alexandre@peadrop.com>2009-06-12 21:52:14 (GMT)
commit450ae573bcf3b8b9e910dacf5dcf640cced44b97 (patch)
tree291a7e3d6112f8997b6bee501d5ad5c4b928e186 /Lib/collections.py
parentf0c9e46cdeff1ce6f55252083cfaec28406d189c (diff)
downloadcpython-450ae573bcf3b8b9e910dacf5dcf640cced44b97.zip
cpython-450ae573bcf3b8b9e910dacf5dcf640cced44b97.tar.gz
cpython-450ae573bcf3b8b9e910dacf5dcf640cced44b97.tar.bz2
Make pickling of OrderedDict instances more efficient.
Diffstat (limited to 'Lib/collections.py')
-rw-r--r--Lib/collections.py10
1 files changed, 6 insertions, 4 deletions
diff --git a/Lib/collections.py b/Lib/collections.py
index 1e807af..202b8b2 100644
--- a/Lib/collections.py
+++ b/Lib/collections.py
@@ -99,14 +99,16 @@ class OrderedDict(dict, MutableMapping):
def __reduce__(self):
'Return state information for pickling'
- items = [[k, self[k]] for k in self]
+ dictitems = self.iteritems()
tmp = self.__map, self.__root
del self.__map, self.__root
inst_dict = vars(self).copy()
self.__map, self.__root = tmp
- if inst_dict:
- return (self.__class__, (items,), inst_dict)
- return self.__class__, (items,)
+ # Set the state item to None when the dictionary is empty. This saves
+ # about 2 opcodes when the object is pickled.
+ if not inst_dict:
+ inst_dict = None
+ return (self.__class__, (), inst_dict, None, dictitems)
setdefault = MutableMapping.setdefault
update = MutableMapping.update