MCPcopy Create free account
hub / github.com/bytecodealliance/wasmtime / reverse_index

Method reverse_index

cranelift/codegen/src/ranges.rs:82–90  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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 {

Callers 2

reverse_targetMethod · 0.80
reverse_and_finalizeMethod · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected