12
12
13
13
use core:: old_iter:: BaseIter ;
14
14
use core:: util:: { replace, swap} ;
15
-
16
- #[ abi = "rust-intrinsic" ]
17
- extern "rust-intrinsic" {
18
- fn move_val_init < T > ( dst : & mut T , src : T ) ;
19
- fn init < T > ( ) -> T ;
20
- #[ cfg( not( stage0) ) ]
21
- fn uninit < T > ( ) -> T ;
22
- }
15
+ use core:: unstable:: intrinsics:: { init, move_val_init} ;
23
16
24
17
pub struct PriorityQueue < T > {
25
18
priv data : ~[ T ] ,
@@ -141,33 +134,13 @@ pub impl <T:Ord> PriorityQueue<T> {
141
134
142
135
// The implementations of siftup and siftdown use unsafe blocks in
143
136
// order to move an element out of the vector (leaving behind a
144
- // junk element), shift along the others and move it back into the
137
+ // zeroed element), shift along the others and move it back into the
145
138
// vector over the junk element. This reduces the constant factor
146
139
// compared to using swaps, which involves twice as many moves.
147
140
148
- #[ cfg( not( stage0) ) ]
149
- priv fn siftup ( & mut self , start : uint , mut pos : uint ) {
150
- unsafe {
151
- let new = * ptr:: to_unsafe_ptr ( & self . data [ pos] ) ;
152
-
153
- while pos > start {
154
- let parent = ( pos - 1 ) >> 1 ;
155
- if new > self . data [ parent] {
156
- let x = replace ( & mut self . data [ parent] , uninit ( ) ) ;
157
- move_val_init ( & mut self . data [ pos] , x) ;
158
- pos = parent;
159
- loop
160
- }
161
- break
162
- }
163
- move_val_init ( & mut self . data [ pos] , new) ;
164
- }
165
- }
166
-
167
- #[ cfg( stage0) ]
168
141
priv fn siftup ( & mut self , start : uint , mut pos : uint ) {
169
142
unsafe {
170
- let new = * ptr :: to_unsafe_ptr ( & self . data [ pos] ) ;
143
+ let new = replace ( & mut self . data [ pos] , init ( ) ) ;
171
144
172
145
while pos > start {
173
146
let parent = ( pos - 1 ) >> 1 ;
@@ -183,35 +156,10 @@ pub impl <T:Ord> PriorityQueue<T> {
183
156
}
184
157
}
185
158
186
-
187
- #[ cfg( not( stage0) ) ]
188
- priv fn siftdown_range ( & mut self , mut pos : uint , end : uint ) {
189
- unsafe {
190
- let start = pos;
191
- let new = * ptr:: to_unsafe_ptr ( & self . data [ pos] ) ;
192
-
193
- let mut child = 2 * pos + 1 ;
194
- while child < end {
195
- let right = child + 1 ;
196
- if right < end && !( self . data [ child] > self . data [ right] ) {
197
- child = right;
198
- }
199
- let x = replace ( & mut self . data [ child] , uninit ( ) ) ;
200
- move_val_init ( & mut self . data [ pos] , x) ;
201
- pos = child;
202
- child = 2 * pos + 1 ;
203
- }
204
-
205
- move_val_init ( & mut self . data [ pos] , new) ;
206
- self . siftup ( start, pos) ;
207
- }
208
- }
209
-
210
- #[ cfg( stage0) ]
211
159
priv fn siftdown_range ( & mut self , mut pos : uint , end : uint ) {
212
160
unsafe {
213
161
let start = pos;
214
- let new = * ptr :: to_unsafe_ptr ( & self . data [ pos] ) ;
162
+ let new = replace ( & mut self . data [ pos] , init ( ) ) ;
215
163
216
164
let mut child = 2 * pos + 1 ;
217
165
while child < end {
0 commit comments