From 57509709b4ecc31b04b765bd07cd5fe672667e43 Mon Sep 17 00:00:00 2001 From: James Miller Date: Thu, 9 May 2013 23:05:17 +1200 Subject: Make staged versions of the functions that use uninit --- src/libstd/priority_queue.rs | 47 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) (limited to 'src/libstd/priority_queue.rs') diff --git a/src/libstd/priority_queue.rs b/src/libstd/priority_queue.rs index 2ca13c43d34..b5dd9e456a1 100644 --- a/src/libstd/priority_queue.rs +++ b/src/libstd/priority_queue.rs @@ -132,6 +132,7 @@ pub impl PriorityQueue { // vector over the junk element. This reduces the constant factor // compared to using swaps, which involves twice as many moves. + #[cfg(not(stage0))] priv fn siftup(&mut self, start: uint, mut pos: uint) { unsafe { let new = *ptr::to_unsafe_ptr(&self.data[pos]); @@ -151,6 +152,28 @@ pub impl PriorityQueue { } } + #[cfg(stage0)] + priv fn siftup(&mut self, start: uint, mut pos: uint) { + unsafe { + let new = *ptr::to_unsafe_ptr(&self.data[pos]); + + while pos > start { + let parent = (pos - 1) >> 1; + if new > self.data[parent] { + let mut x = rusti::init(); + x <-> self.data[parent]; + rusti::move_val_init(&mut self.data[pos], x); + pos = parent; + loop + } + break + } + rusti::move_val_init(&mut self.data[pos], new); + } + } + + + #[cfg(not(stage0))] priv fn siftdown_range(&mut self, mut pos: uint, end: uint) { unsafe { let start = pos; @@ -174,6 +197,30 @@ pub impl PriorityQueue { } } + #[cfg(stage0)] + priv fn siftdown_range(&mut self, mut pos: uint, end: uint) { + unsafe { + let start = pos; + let new = *ptr::to_unsafe_ptr(&self.data[pos]); + + let mut child = 2 * pos + 1; + while child < end { + let right = child + 1; + if right < end && !(self.data[child] > self.data[right]) { + child = right; + } + let mut x = rusti::init(); + x <-> self.data[child]; + rusti::move_val_init(&mut self.data[pos], x); + pos = child; + child = 2 * pos + 1; + } + + rusti::move_val_init(&mut self.data[pos], new); + self.siftup(start, pos); + } + } + priv fn siftdown(&mut self, pos: uint) { let len = self.len(); self.siftdown_range(pos, len); -- cgit 1.4.1-3-g733a5