/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/lru_cache.py

  • Committer: John Arbash Meinel
  • Date: 2009-03-23 02:28:06 UTC
  • mto: This revision was merged to the branch mainline in revision 4197.
  • Revision ID: john@arbash-meinel.com-20090323022806-snn93cbemn82w1b0
Remove the asserts, and change some to AssertionError.

Show diffs side-by-side

added added

removed removed

Lines of Context:
89
89
            # Nothing to do, this node is already at the head of the queue
90
90
            return node.value
91
91
        elif node is self._last_recently_used:
92
 
            assert node.prev is not None
93
92
            self._last_recently_used = node.prev
94
93
        # Remove this node from the old location
95
94
        node_prev = node.prev
109
108
        return len(self._cache)
110
109
 
111
110
    def _walk_lru(self):
112
 
        """Walk the LRU list."""
 
111
        """Walk the LRU list, only meant to be used in tests."""
113
112
        node = self._most_recently_used
114
113
        if node is not None:
115
 
            assert node.prev is None
 
114
            if node.prev is not None:
 
115
                raise AssertionError('the _most_recently_used entry is not'
 
116
                                     ' supposed to have a previous entry'
 
117
                                     ' %s' % (node,))
116
118
        while node is not None:
117
119
            if node.next is None:
118
 
                assert node is self._last_recently_used
 
120
                if node is not self._last_recently_used:
 
121
                    raise AssertionError('only the last node should have'
 
122
                                         ' no next value: %s' % (node,))
119
123
            else:
120
 
                assert node.next.prev is node
 
124
                if node.next.prev is not node:
 
125
                    raise AssertionError('inconsistency found, node.next.prev'
 
126
                                         ' != node: %s' % (node,))
121
127
            if node.prev is None:
122
 
                assert node is self._most_recently_used
 
128
                if node is not self._most_recently_used:
 
129
                    raise AssertionError('only the _most_recently_used should'
 
130
                                         ' not have a previous node: %s'
 
131
                                         % (node,))
123
132
            else:
124
 
                assert node.prev.next is node
 
133
                if node.prev.next is not node:
 
134
                    raise AssertionError('inconsistency found, node.prev.next'
 
135
                                         ' != node: %s' % (node,))
125
136
            yield node
126
137
            node = node.next
127
138
 
196
207
        """Record that key was accessed."""
197
208
        # Move 'node' to the front of the queue
198
209
        if self._most_recently_used is None:
199
 
            assert len(self._cache) == 1
200
210
            self._most_recently_used = node
201
211
            self._last_recently_used = node
202
 
            assert node.next == None
203
 
            assert node.prev == None
204
212
            return
205
213
        elif node is self._most_recently_used:
206
214
            # Nothing to do, this node is already at the head of the queue
207
215
            return
208
216
        elif node is self._last_recently_used:
209
 
            assert self._last_recently_used is not None
210
217
            self._last_recently_used = node.prev
211
 
            assert self._last_recently_used is not None
212
218
        # We've taken care of the tail pointer, remove the node, and insert it
213
219
        # at the front
214
220
        # REMOVE
223
229
        node.prev = None
224
230
 
225
231
    def _remove_node(self, node):
226
 
        assert node is not None
227
232
        if node is self._last_recently_used:
228
233
            self._last_recently_used = node.prev
229
 
        node2 = self._cache.pop(node.key)
230
 
        assert node2 is node
231
 
        del node2
 
234
        self._cache.pop(node.key)
232
235
        # If we have removed all entries, remove the head pointer as well
233
236
        if self._last_recently_used is None:
234
 
            if len(self._cache) != 0:
235
 
                import pdb; pdb.set_trace()
236
 
            assert len(self._cache) == 0
237
 
            assert self._most_recently_used is node
238
237
            self._most_recently_used = None
239
238
        node.run_cleanup()
240
 
        # Shouldn't be necessary
241
 
        # node.next = None
242
 
        # node.prev = None
243
239
 
244
240
    def _remove_lru(self):
245
241
        """Remove one entry from the lru, and handle consequences.