summaryrefslogtreecommitdiffstats
path: root/Lib/collections.py
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2010-09-12 18:13:46 (GMT)
committerRaymond Hettinger <python@rcn.com>2010-09-12 18:13:46 (GMT)
commitc5c29c0ac00f2480eab43ffcecd26ac7ed0c7dfd (patch)
tree83382c8ce10c5d31d3dc910003cd6b9498aac12b /Lib/collections.py
parentb084b48cec806dbc138c4efee338e422aefe538e (diff)
downloadcpython-c5c29c0ac00f2480eab43ffcecd26ac7ed0c7dfd.zip
cpython-c5c29c0ac00f2480eab43ffcecd26ac7ed0c7dfd.tar.gz
cpython-c5c29c0ac00f2480eab43ffcecd26ac7ed0c7dfd.tar.bz2
Use weakrefs for both forward and backward links.
Diffstat (limited to 'Lib/collections.py')
-rw-r--r--Lib/collections.py7
1 files changed, 4 insertions, 3 deletions
diff --git a/Lib/collections.py b/Lib/collections.py
index 1126fb1..e849296 100644
--- a/Lib/collections.py
+++ b/Lib/collections.py
@@ -31,7 +31,9 @@ class OrderedDict(dict, MutableMapping):
# The internal self.__map dictionary maps keys to links in a doubly linked list.
# The circular doubly linked list starts and ends with a sentinel element.
# The sentinel element never gets deleted (this simplifies the algorithm).
- # The back links are weakref proxies (to prevent circular references).
+ # The prev/next links are weakref proxies (to prevent circular references).
+ # Individual links are kept alive by the hard reference in self.__map.
+ # Those hard references disappear when a key is deleted from an OrderedDict.
def __init__(self, *args, **kwds):
'''Initialize an ordered dictionary. Signature is the same as for
@@ -60,8 +62,7 @@ class OrderedDict(dict, MutableMapping):
root = self.__root
last = root.prev
link.prev, link.next, link.key = last, root, key
- last.next = link
- root.prev = proxy(link)
+ last.next = root.prev = proxy(link)
dict.__setitem__(self, key, value)
def __delitem__(self, key, dict_delitem=dict.__delitem__):