Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/util.py @ 39580:5d75a3c16193
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
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Thu, 06 Sep 2018 11:37:27 -0700 |
parents | b31b01f93b11 |
children | 2dcc68c7d25b |
comparison
equal
deleted
inserted
replaced
39579:b31b01f93b11 | 39580:5d75a3c16193 |
---|---|
1239 | 1239 |
1240 self._head = head = _lrucachenode() | 1240 self._head = head = _lrucachenode() |
1241 head.prev = head | 1241 head.prev = head |
1242 head.next = head | 1242 head.next = head |
1243 self._size = 1 | 1243 self._size = 1 |
1244 self._capacity = max | 1244 self.capacity = max |
1245 | 1245 |
1246 def __len__(self): | 1246 def __len__(self): |
1247 return len(self._cache) | 1247 return len(self._cache) |
1248 | 1248 |
1249 def __contains__(self, k): | 1249 def __contains__(self, k): |
1267 if node is not None: | 1267 if node is not None: |
1268 node.value = v | 1268 node.value = v |
1269 self._movetohead(node) | 1269 self._movetohead(node) |
1270 return | 1270 return |
1271 | 1271 |
1272 if self._size < self._capacity: | 1272 if self._size < self.capacity: |
1273 node = self._addcapacity() | 1273 node = self._addcapacity() |
1274 else: | 1274 else: |
1275 # Grab the last/oldest item. | 1275 # Grab the last/oldest item. |
1276 node = self._head.prev | 1276 node = self._head.prev |
1277 | 1277 |
1310 n = n.next | 1310 n = n.next |
1311 | 1311 |
1312 self._cache.clear() | 1312 self._cache.clear() |
1313 | 1313 |
1314 def copy(self): | 1314 def copy(self): |
1315 result = lrucachedict(self._capacity) | 1315 result = lrucachedict(self.capacity) |
1316 | 1316 |
1317 # We copy entries by iterating in oldest-to-newest order so the copy | 1317 # We copy entries by iterating in oldest-to-newest order so the copy |
1318 # has the correct ordering. | 1318 # has the correct ordering. |
1319 | 1319 |
1320 # Find the first non-empty entry. | 1320 # Find the first non-empty entry. |