~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/fifo_cache.py

  • Committer: John Arbash Meinel
  • Date: 2008-12-10 00:07:33 UTC
  • mto: This revision was merged to the branch mainline in revision 3888.
  • Revision ID: john@arbash-meinel.com-20081210000733-5h1j6enwe37ymnuj
Handle that Python2.4 doesn't have collections.deque.remove

Show diffs side-by-side

added added

removed removed

Lines of Context:
39
39
 
40
40
    def __delitem__(self, key):
41
41
        # Remove the key from an arbitrary location in the queue
42
 
        self._queue.remove(key)
 
42
        remove = getattr(self._queue, 'remove', None)
 
43
        # Python2.5's has deque.remove, but Python2.4 does not
 
44
        if remove is not None:
 
45
            remove(key)
 
46
        else:
 
47
            # TODO: It would probably be faster to pop()/popleft() until we get to the
 
48
            #       key, and then insert those back into the queue. We know
 
49
            #       the key should only be present in one position, and we
 
50
            #       wouldn't need to rebuild the whole queue.
 
51
            self._queue = deque([k for k in self._queue if k != key])
43
52
        self._remove(key)
44
53
 
45
54
    def add(self, key, value, cleanup=None):