~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/lru_cache.py

  • Committer: John Arbash Meinel
  • Date: 2009-04-16 20:45:41 UTC
  • mto: This revision was merged to the branch mainline in revision 4323.
  • Revision ID: john@arbash-meinel.com-20090416204541-gg2qtfggaxwzudvz
Fairly significant savings... avoid looking at self._last_recently_used.
We can get the same information from node.next_key, which is a value we need anyway.
Somewhat surprisingly, this drops us from 7.6s => 7.1s on 2.8M lookups.

Show diffs side-by-side

added added

removed removed

Lines of Context:
88
88
            return node.value
89
89
        # Remove this node from the old location
90
90
        node_prev = node.prev
91
 
        if node is self._last_recently_used:
92
 
            self._last_recently_used = node_prev
93
91
        next_key = node.next_key
94
 
        node_prev.next_key = next_key
95
92
        if next_key is None:
96
 
            node_next = None
 
93
            # 'node' is the _last_recently_used, because it doesn't have a
 
94
            # 'next' item. So move the current lru to the previous node.
 
95
            self._last_recently_used = node_prev
97
96
        else:
98
97
            node_next = cache[next_key]
99
98
            node_next.prev = node_prev
 
99
        node_prev.next_key = next_key
100
100
        # Insert this node at the front of the list
101
101
        node.next_key = mru.key
102
102
        mru.prev = node