Improve clear() method. Keeps key/value refcnts >= 1 until final dict.clear() so that decrefs to zero won't trigger arbitrary code . Also runs a bit faster.
This commit is contained in:
parent
93232660bb
commit
6b96ecb0ab
|
@ -107,8 +107,14 @@ class OrderedDict(dict, MutableMapping):
|
||||||
|
|
||||||
def clear(self):
|
def clear(self):
|
||||||
'od.clear() -> None. Remove all items from od.'
|
'od.clear() -> None. Remove all items from od.'
|
||||||
for k in dict.keys(self):
|
try:
|
||||||
del self[k]
|
for node in self.__map.itervalues():
|
||||||
|
del node[:]
|
||||||
|
self.__root[:] = [self.__root, self.__root, None]
|
||||||
|
self.__map.clear()
|
||||||
|
except AttributeError:
|
||||||
|
pass
|
||||||
|
dict.clear(self)
|
||||||
|
|
||||||
setdefault = MutableMapping.setdefault
|
setdefault = MutableMapping.setdefault
|
||||||
update = MutableMapping.update
|
update = MutableMapping.update
|
||||||
|
|
Loading…
Reference in New Issue