Mercurial > hg
diff mercurial/util.py @ 40880:7cda0cacbbf6
util: implement pop() on lrucachedict
This moves __delitem__() to pop() as the requirement is pretty much the same,
and reimplement __delitem__() by using pop().
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Sun, 04 Nov 2018 16:57:05 +0900 |
parents | 0c638ff69f5c |
children | 593f6359681d |
line wrap: on
line diff
--- a/mercurial/util.py Wed Oct 31 22:29:05 2018 +0900 +++ b/mercurial/util.py Sun Nov 04 16:57:05 2018 +0900 @@ -1320,7 +1320,16 @@ self.insert(k, v) def __delitem__(self, k): - node = self._cache.pop(k) + self.pop(k) + + def pop(self, k, default=_notset): + try: + node = self._cache.pop(k) + except KeyError: + if default is _notset: + raise + return default + value = node.value self.totalcost -= node.cost node.markempty() @@ -1329,6 +1338,8 @@ self._movetohead(node) self._head = node.next + return value + # Additional dict methods. def get(self, k, default=None):