@@ -31,10 +31,6 @@ use libc::size_t;
31
31
32
32
#[ abi = "rust-intrinsic" ]
33
33
extern mod rusti {
34
- #[ cfg( stage0) ]
35
- fn move_val_init < T > ( & dst: T , -src : T ) ;
36
- #[ cfg( stage1) ]
37
- #[ cfg( stage2) ]
38
34
fn move_val_init < T > ( dst : & mut T , -src : T ) ;
39
35
fn needs_drop < T > ( ) -> bool ;
40
36
}
@@ -132,117 +128,6 @@ unsafe fn un_bitpack_tydesc_ptr(p: uint) -> (*TypeDesc, bool) {
132
128
( reinterpret_cast ( & ( p & !1 ) ) , p & 1 == 1 )
133
129
}
134
130
135
- // tjc: Can get rid of the duplication post-snapshot
136
- #[ cfg( stage0) ]
137
- // The duplication between the POD and non-POD functions is annoying.
138
- impl & Arena {
139
- // Functions for the POD part of the arena
140
- fn alloc_pod_grow ( n_bytes : uint , align : uint ) -> * u8 {
141
- // Allocate a new chunk.
142
- let chunk_size = at_vec:: capacity ( self . pod_head . data ) ;
143
- let new_min_chunk_size = uint:: max ( n_bytes, chunk_size) ;
144
- self . chunks = @Cons ( copy self . pod_head , self . chunks ) ;
145
- self . pod_head =
146
- chunk ( uint:: next_power_of_two ( new_min_chunk_size + 1 u) , true ) ;
147
-
148
- return self . alloc_pod_inner ( n_bytes, align) ;
149
- }
150
-
151
- #[ inline( always) ]
152
- fn alloc_pod_inner ( n_bytes : uint , align : uint ) -> * u8 {
153
- let head = & mut self . pod_head ;
154
-
155
- let start = round_up_to ( head. fill , align) ;
156
- let end = start + n_bytes;
157
- if end > at_vec:: capacity ( head. data ) {
158
- return self . alloc_pod_grow ( n_bytes, align) ;
159
- }
160
- head. fill = end;
161
-
162
- //debug!("idx = %u, size = %u, align = %u, fill = %u",
163
- // start, n_bytes, align, head.fill);
164
-
165
- unsafe {
166
- ptr:: offset ( vec:: raw:: to_ptr ( head. data ) , start)
167
- }
168
- }
169
-
170
- #[ inline( always) ]
171
- fn alloc_pod < T > ( op : fn ( ) -> T ) -> & self /T {
172
- unsafe {
173
- let tydesc = sys:: get_type_desc :: < T > ( ) ;
174
- let ptr = self . alloc_pod_inner ( ( * tydesc) . size , ( * tydesc) . align ) ;
175
- let ptr: * mut T = reinterpret_cast ( & ptr) ;
176
- rusti:: move_val_init ( * ptr, op ( ) ) ;
177
- return reinterpret_cast ( & ptr) ;
178
- }
179
- }
180
-
181
- // Functions for the non-POD part of the arena
182
- fn alloc_nonpod_grow ( n_bytes : uint , align : uint ) -> ( * u8 , * u8 ) {
183
- // Allocate a new chunk.
184
- let chunk_size = at_vec:: capacity ( self . head . data ) ;
185
- let new_min_chunk_size = uint:: max ( n_bytes, chunk_size) ;
186
- self . chunks = @Cons ( copy self . head , self . chunks ) ;
187
- self . head =
188
- chunk ( uint:: next_power_of_two ( new_min_chunk_size + 1 u) , false ) ;
189
-
190
- return self . alloc_nonpod_inner ( n_bytes, align) ;
191
- }
192
-
193
- #[ inline( always) ]
194
- fn alloc_nonpod_inner ( n_bytes : uint , align : uint ) -> ( * u8 , * u8 ) {
195
- let head = & mut self . head ;
196
-
197
- let tydesc_start = head. fill ;
198
- let after_tydesc = head. fill + sys:: size_of :: < * TypeDesc > ( ) ;
199
- let start = round_up_to ( after_tydesc, align) ;
200
- let end = start + n_bytes;
201
- if end > at_vec:: capacity ( head. data ) {
202
- return self . alloc_nonpod_grow ( n_bytes, align) ;
203
- }
204
- head. fill = round_up_to ( end, sys:: pref_align_of :: < * TypeDesc > ( ) ) ;
205
-
206
- //debug!("idx = %u, size = %u, align = %u, fill = %u",
207
- // start, n_bytes, align, head.fill);
208
-
209
- unsafe {
210
- let buf = vec:: raw:: to_ptr ( head. data ) ;
211
- return ( ptr:: offset ( buf, tydesc_start) , ptr:: offset ( buf, start) ) ;
212
- }
213
- }
214
-
215
- #[ inline( always) ]
216
- fn alloc_nonpod < T > ( op : fn ( ) -> T ) -> & self /T {
217
- unsafe {
218
- let tydesc = sys:: get_type_desc :: < T > ( ) ;
219
- let ( ty_ptr, ptr) =
220
- self . alloc_nonpod_inner ( ( * tydesc) . size , ( * tydesc) . align ) ;
221
- let ty_ptr: * mut uint = reinterpret_cast ( & ty_ptr) ;
222
- let ptr: * mut T = reinterpret_cast ( & ptr) ;
223
- // Write in our tydesc along with a bit indicating that it
224
- // has *not* been initialized yet.
225
- * ty_ptr = reinterpret_cast ( & tydesc) ;
226
- // Actually initialize it
227
- rusti:: move_val_init ( * ptr, op ( ) ) ;
228
- // Now that we are done, update the tydesc to indicate that
229
- // the object is there.
230
- * ty_ptr = bitpack_tydesc_ptr ( tydesc, true ) ;
231
-
232
- return reinterpret_cast ( & ptr) ;
233
- }
234
- }
235
-
236
- // The external interface
237
- #[ inline( always) ]
238
- fn alloc < T > ( op : fn ( ) -> T ) -> & self /T {
239
- if !rusti:: needs_drop :: < T > ( ) {
240
- self . alloc_pod ( op)
241
- } else { self . alloc_nonpod ( op) }
242
- }
243
- }
244
- #[ cfg( stage1) ]
245
- #[ cfg( stage2) ]
246
131
impl & Arena {
247
132
// Functions for the POD part of the arena
248
133
fn alloc_pod_grow ( n_bytes : uint , align : uint ) -> * u8 {
0 commit comments