~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/lru_cache.py

  • Committer: Martin Packman
  • Date: 2011-10-14 17:44:03 UTC
  • mto: This revision was merged to the branch mainline in revision 6235.
  • Revision ID: martin.packman@canonical.com-20111014174403-96aaqfz8al2vwh4w
Recompute size rather than storing on _LRUNode.size

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
class _LRUNode(object):
27
27
    """This maintains the linked-list which is the lru internals."""
28
28
 
29
 
    __slots__ = ('prev', 'next_key', 'key', 'value', 'cleanup', 'size')
 
29
    __slots__ = ('prev', 'next_key', 'key', 'value', 'cleanup')
30
30
 
31
31
    def __init__(self, key, value, cleanup=None):
32
32
        self.prev = None
34
34
        self.key = key
35
35
        self.value = value
36
36
        self.cleanup = cleanup
37
 
        # TODO: We could compute this 'on-the-fly' like we used to, and remove
38
 
        #       one pointer from this object, we just need to decide if it
39
 
        #       actually costs us much of anything in normal usage
40
 
        self.size = None
41
37
 
42
38
    def __repr__(self):
43
39
        if self.prev is None:
321
317
            node = _LRUNode(key, value, cleanup=cleanup)
322
318
            self._cache[key] = node
323
319
        else:
324
 
            self._value_size -= node.size
325
 
        node.size = value_len
 
320
            self._value_size -= self._compute_size(node.value)
326
321
        self._value_size += value_len
327
322
        self._record_access(node)
328
323
 
341
336
            self._remove_lru()
342
337
 
343
338
    def _remove_node(self, node):
344
 
        self._value_size -= node.size
 
339
        self._value_size -= self._compute_size(node.value)
345
340
        LRUCache._remove_node(self, node)
346
341
 
347
342
    def resize(self, max_size, after_cleanup_size=None):