# HG changeset patch # User Gregory Szorc # Date 1536259047 25200 # Node ID 5d75a3c16193a81ef74d11ca6b8b7cb7d40a4e97 # Parent b31b01f93b11a1f4b488c069da67bcb4fbb8dcfc util: make capacity a public attribute on lrucachedict So others can query it. Useful for operations that may want to verify the cache has capacity for N items before it performs an operation that may cause cache eviction. Differential Revision: https://phab.mercurial-scm.org/D4499 diff -r b31b01f93b11 -r 5d75a3c16193 mercurial/util.py --- a/mercurial/util.py Thu Sep 06 11:33:40 2018 -0700 +++ b/mercurial/util.py Thu Sep 06 11:37:27 2018 -0700 @@ -1241,7 +1241,7 @@ head.prev = head head.next = head self._size = 1 - self._capacity = max + self.capacity = max def __len__(self): return len(self._cache) @@ -1269,7 +1269,7 @@ self._movetohead(node) return - if self._size < self._capacity: + if self._size < self.capacity: node = self._addcapacity() else: # Grab the last/oldest item. @@ -1312,7 +1312,7 @@ self._cache.clear() def copy(self): - result = lrucachedict(self._capacity) + result = lrucachedict(self.capacity) # We copy entries by iterating in oldest-to-newest order so the copy # has the correct ordering. diff -r b31b01f93b11 -r 5d75a3c16193 tests/test-lrucachedict.py --- a/tests/test-lrucachedict.py Thu Sep 06 11:33:40 2018 -0700 +++ b/tests/test-lrucachedict.py Thu Sep 06 11:37:27 2018 -0700 @@ -11,6 +11,7 @@ class testlrucachedict(unittest.TestCase): def testsimple(self): d = util.lrucachedict(4) + self.assertEqual(d.capacity, 4) d['a'] = 'va' d['b'] = 'vb' d['c'] = 'vc'