Reverse this list of ranges, so that the first range is at the last index and the last range is at the first index. ```ignore use cranelift_codegen::ranges::Ranges; let mut ranges = Ranges::default(); ranges.push_end(4); ranges.push_end(6); ranges.reverse_index(); assert_eq!(ranges.get(0), 4..6); assert_eq!(ranges.get(1), 0..4); ```
(&mut self)
| 80 | /// assert_eq!(ranges.get(1), 0..4); |
| 81 | /// ``` |
| 82 | pub fn reverse_index(&mut self) { |
| 83 | // We can't easily change the order of the endpoints in |
| 84 | // self.ranges: they need to be in ascending order or our |
| 85 | // compressed representation gets complicated. So instead we |
| 86 | // change our interpretation of indexes using map_index below, |
| 87 | // controlled by a simple flag. As a bonus, reversing the list |
| 88 | // is constant-time! |
| 89 | self.reverse = !self.reverse; |
| 90 | } |
| 91 | |
| 92 | fn map_index(&self, index: usize) -> usize { |
| 93 | if self.reverse { |
no outgoing calls
no test coverage detected