diff options
| author | James Miller <bladeon@gmail.com> | 2013-05-09 23:05:17 +1200 |
|---|---|---|
| committer | James Miller <bladeon@gmail.com> | 2013-05-09 23:05:17 +1200 |
| commit | 57509709b4ecc31b04b765bd07cd5fe672667e43 (patch) | |
| tree | 06fe9f2223bc168a5b862630f02b502d8d77a0f7 /src/libstd | |
| parent | f5ab112e6b083ab20fdcf9e2fff7dde4a85940b0 (diff) | |
| download | rust-57509709b4ecc31b04b765bd07cd5fe672667e43.tar.gz rust-57509709b4ecc31b04b765bd07cd5fe672667e43.zip | |
Make staged versions of the functions that use uninit
Diffstat (limited to 'src/libstd')
| -rw-r--r-- | src/libstd/priority_queue.rs | 47 | ||||
| -rw-r--r-- | src/libstd/rc.rs | 33 |
2 files changed, 80 insertions, 0 deletions
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 <T:Ord> PriorityQueue<T> { // 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 <T:Ord> PriorityQueue<T> { } } + #[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 <T:Ord> PriorityQueue<T> { } } + #[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); diff --git a/src/libstd/rc.rs b/src/libstd/rc.rs index 3095bdd16d0..da90716316b 100644 --- a/src/libstd/rc.rs +++ b/src/libstd/rc.rs @@ -46,6 +46,7 @@ pub impl<T: Owned> Rc<T> { } #[unsafe_destructor] +#[cfg(not(stage0))] impl<T: Owned> Drop for Rc<T> { fn finalize(&self) { unsafe { @@ -59,6 +60,22 @@ impl<T: Owned> Drop for Rc<T> { } } +#[unsafe_destructor] +#[cfg(stage0)] +impl<T: Owned> Drop for Rc<T> { + fn finalize(&self) { + unsafe { + (*self.ptr).count -= 1; + if (*self.ptr).count == 0 { + let mut x = intrinsics::init(); + x <-> *self.ptr; + free(self.ptr as *c_void) + } + } + } +} + + impl<T: Owned> Clone for Rc<T> { #[inline] fn clone(&self) -> Rc<T> { @@ -154,6 +171,7 @@ pub impl<T: Owned> RcMut<T> { } #[unsafe_destructor] +#[cfg(not(stage0))] impl<T: Owned> Drop for RcMut<T> { fn finalize(&self) { unsafe { @@ -167,6 +185,21 @@ impl<T: Owned> Drop for RcMut<T> { } } +#[unsafe_destructor] +#[cfg(stage0)] +impl<T: Owned> Drop for RcMut<T> { + fn finalize(&self) { + unsafe { + (*self.ptr).count -= 1; + if (*self.ptr).count == 0 { + let mut x = rusti::init(); + x <-> *self.ptr; + free(self.ptr as *c_void) + } + } + } +} + impl<T: Owned> Clone for RcMut<T> { #[inline] fn clone(&self) -> RcMut<T> { |
