Mercurial > public > mercurial-scm > hg-stable
diff mercurial/util.py @ 40897:0c638ff69f5c
util: add method to peek item in lrucachedict
I want a function that doesn't unnecessarily update the internal state of
the cache dict after fork().
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Wed, 31 Oct 2018 22:29:05 +0900 |
parents | 475921a3028c |
children | 7cda0cacbbf6 |
line wrap: on
line diff
--- a/mercurial/util.py Wed Oct 31 22:05:45 2018 +0900 +++ b/mercurial/util.py Wed Oct 31 22:29:05 2018 +0900 @@ -1337,6 +1337,20 @@ except KeyError: return default + def peek(self, k, default=_notset): + """Get the specified item without moving it to the head + + Unlike get(), this doesn't mutate the internal state. But be aware + that it doesn't mean peek() is thread safe. + """ + try: + node = self._cache[k] + return node.value + except KeyError: + if default is _notset: + raise + return default + def clear(self): n = self._head while n.key is not _notset: