comparison mercurial/util.py @ 40879: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
comparison
equal deleted inserted replaced
40878:2525faf4ecdb 40879:0c638ff69f5c
1333 1333
1334 def get(self, k, default=None): 1334 def get(self, k, default=None):
1335 try: 1335 try:
1336 return self.__getitem__(k) 1336 return self.__getitem__(k)
1337 except KeyError: 1337 except KeyError:
1338 return default
1339
1340 def peek(self, k, default=_notset):
1341 """Get the specified item without moving it to the head
1342
1343 Unlike get(), this doesn't mutate the internal state. But be aware
1344 that it doesn't mean peek() is thread safe.
1345 """
1346 try:
1347 node = self._cache[k]
1348 return node.value
1349 except KeyError:
1350 if default is _notset:
1351 raise
1338 return default 1352 return default
1339 1353
1340 def clear(self): 1354 def clear(self):
1341 n = self._head 1355 n = self._head
1342 while n.key is not _notset: 1356 while n.key is not _notset: