@@ -48,7 +48,7 @@ use std::intrinsics;
48
48
struct Chunk {
49
49
data : Rc < RefCell < Vec < u8 > > > ,
50
50
fill : Cell < uint > ,
51
- is_pod : Cell < bool > ,
51
+ is_copy : Cell < bool > ,
52
52
}
53
53
impl Chunk {
54
54
fn capacity ( & self ) -> uint {
@@ -86,7 +86,7 @@ pub struct Arena {
86
86
// microoptimization, to avoid needing to case on the list to
87
87
// access the head.
88
88
priv head : Chunk ,
89
- priv pod_head : Chunk ,
89
+ priv copy_head : Chunk ,
90
90
priv chunks : RefCell < @List < Chunk > > ,
91
91
}
92
92
@@ -98,17 +98,17 @@ impl Arena {
98
98
pub fn new_with_size ( initial_size : uint ) -> Arena {
99
99
Arena {
100
100
head : chunk ( initial_size, false ) ,
101
- pod_head : chunk ( initial_size, true ) ,
101
+ copy_head : chunk ( initial_size, true ) ,
102
102
chunks : RefCell :: new ( @Nil ) ,
103
103
}
104
104
}
105
105
}
106
106
107
- fn chunk ( size : uint , is_pod : bool ) -> Chunk {
107
+ fn chunk ( size : uint , is_copy : bool ) -> Chunk {
108
108
Chunk {
109
109
data : Rc :: new ( RefCell :: new ( Vec :: with_capacity ( size) ) ) ,
110
110
fill : Cell :: new ( 0 u) ,
111
- is_pod : Cell :: new ( is_pod ) ,
111
+ is_copy : Cell :: new ( is_copy ) ,
112
112
}
113
113
}
114
114
@@ -118,7 +118,7 @@ impl Drop for Arena {
118
118
unsafe {
119
119
destroy_chunk ( & self . head ) ;
120
120
for chunk in self . chunks . get ( ) . iter ( ) {
121
- if !chunk. is_pod . get ( ) {
121
+ if !chunk. is_copy . get ( ) {
122
122
destroy_chunk ( chunk) ;
123
123
}
124
124
}
@@ -173,61 +173,61 @@ fn un_bitpack_tydesc_ptr(p: uint) -> (*TyDesc, bool) {
173
173
174
174
impl Arena {
175
175
fn chunk_size ( & self ) -> uint {
176
- self . pod_head . capacity ( )
176
+ self . copy_head . capacity ( )
177
177
}
178
178
// Functions for the POD part of the arena
179
- fn alloc_pod_grow ( & mut self , n_bytes : uint , align : uint ) -> * u8 {
179
+ fn alloc_copy_grow ( & mut self , n_bytes : uint , align : uint ) -> * u8 {
180
180
// Allocate a new chunk.
181
181
let new_min_chunk_size = cmp:: max ( n_bytes, self . chunk_size ( ) ) ;
182
- self . chunks . set ( @Cons ( self . pod_head . clone ( ) , self . chunks . get ( ) ) ) ;
183
- self . pod_head =
182
+ self . chunks . set ( @Cons ( self . copy_head . clone ( ) , self . chunks . get ( ) ) ) ;
183
+ self . copy_head =
184
184
chunk ( num:: next_power_of_two ( new_min_chunk_size + 1 u) , true ) ;
185
185
186
- return self . alloc_pod_inner ( n_bytes, align) ;
186
+ return self . alloc_copy_inner ( n_bytes, align) ;
187
187
}
188
188
189
189
#[ inline]
190
- fn alloc_pod_inner ( & mut self , n_bytes : uint , align : uint ) -> * u8 {
190
+ fn alloc_copy_inner ( & mut self , n_bytes : uint , align : uint ) -> * u8 {
191
191
unsafe {
192
192
let this = transmute_mut_region ( self ) ;
193
- let start = round_up ( this. pod_head . fill . get ( ) , align) ;
193
+ let start = round_up ( this. copy_head . fill . get ( ) , align) ;
194
194
let end = start + n_bytes;
195
195
if end > self . chunk_size ( ) {
196
- return this. alloc_pod_grow ( n_bytes, align) ;
196
+ return this. alloc_copy_grow ( n_bytes, align) ;
197
197
}
198
- this. pod_head . fill . set ( end) ;
198
+ this. copy_head . fill . set ( end) ;
199
199
200
200
//debug!("idx = {}, size = {}, align = {}, fill = {}",
201
201
// start, n_bytes, align, head.fill.get());
202
202
203
- this. pod_head . as_ptr ( ) . offset ( start as int )
203
+ this. copy_head . as_ptr ( ) . offset ( start as int )
204
204
}
205
205
}
206
206
207
207
#[ inline]
208
- fn alloc_pod < ' a , T > ( & ' a mut self , op: || -> T ) -> & ' a T {
208
+ fn alloc_copy < ' a , T > ( & ' a mut self , op: || -> T ) -> & ' a T {
209
209
unsafe {
210
- let ptr = self . alloc_pod_inner ( mem:: size_of :: < T > ( ) , mem:: min_align_of :: < T > ( ) ) ;
210
+ let ptr = self . alloc_copy_inner ( mem:: size_of :: < T > ( ) , mem:: min_align_of :: < T > ( ) ) ;
211
211
let ptr: * mut T = transmute ( ptr) ;
212
212
mem:: move_val_init ( & mut ( * ptr) , op ( ) ) ;
213
213
return transmute ( ptr) ;
214
214
}
215
215
}
216
216
217
217
// Functions for the non-POD part of the arena
218
- fn alloc_nonpod_grow ( & mut self , n_bytes : uint , align : uint )
218
+ fn alloc_noncopy_grow ( & mut self , n_bytes : uint , align : uint )
219
219
-> ( * u8 , * u8 ) {
220
220
// Allocate a new chunk.
221
221
let new_min_chunk_size = cmp:: max ( n_bytes, self . chunk_size ( ) ) ;
222
222
self . chunks . set ( @Cons ( self . head . clone ( ) , self . chunks . get ( ) ) ) ;
223
223
self . head =
224
224
chunk ( num:: next_power_of_two ( new_min_chunk_size + 1 u) , false ) ;
225
225
226
- return self . alloc_nonpod_inner ( n_bytes, align) ;
226
+ return self . alloc_noncopy_inner ( n_bytes, align) ;
227
227
}
228
228
229
229
#[ inline]
230
- fn alloc_nonpod_inner ( & mut self , n_bytes : uint , align : uint )
230
+ fn alloc_noncopy_inner ( & mut self , n_bytes : uint , align : uint )
231
231
-> ( * u8 , * u8 ) {
232
232
unsafe {
233
233
let start;
@@ -245,7 +245,7 @@ impl Arena {
245
245
}
246
246
247
247
if end > self . head . capacity ( ) {
248
- return self . alloc_nonpod_grow ( n_bytes, align) ;
248
+ return self . alloc_noncopy_grow ( n_bytes, align) ;
249
249
}
250
250
251
251
let head = transmute_mut_region ( & mut self . head ) ;
@@ -260,11 +260,11 @@ impl Arena {
260
260
}
261
261
262
262
#[ inline]
263
- fn alloc_nonpod < ' a , T > ( & ' a mut self , op: || -> T ) -> & ' a T {
263
+ fn alloc_noncopy < ' a , T > ( & ' a mut self , op: || -> T ) -> & ' a T {
264
264
unsafe {
265
265
let tydesc = get_tydesc :: < T > ( ) ;
266
266
let ( ty_ptr, ptr) =
267
- self . alloc_nonpod_inner ( mem:: size_of :: < T > ( ) , mem:: min_align_of :: < T > ( ) ) ;
267
+ self . alloc_noncopy_inner ( mem:: size_of :: < T > ( ) , mem:: min_align_of :: < T > ( ) ) ;
268
268
let ty_ptr: * mut uint = transmute ( ty_ptr) ;
269
269
let ptr: * mut T = transmute ( ptr) ;
270
270
// Write in our tydesc along with a bit indicating that it
@@ -287,9 +287,9 @@ impl Arena {
287
287
// FIXME: Borrow check
288
288
let this = transmute_mut ( self ) ;
289
289
if intrinsics:: needs_drop :: < T > ( ) {
290
- this. alloc_nonpod ( op)
290
+ this. alloc_noncopy ( op)
291
291
} else {
292
- this. alloc_pod ( op)
292
+ this. alloc_copy ( op)
293
293
}
294
294
}
295
295
}
@@ -496,7 +496,7 @@ mod tests {
496
496
}
497
497
498
498
#[ test]
499
- pub fn test_pod ( ) {
499
+ pub fn test_copy ( ) {
500
500
let arena = TypedArena :: new ( ) ;
501
501
for _ in range ( 0 , 100000 ) {
502
502
arena. alloc ( Point {
@@ -508,7 +508,7 @@ mod tests {
508
508
}
509
509
510
510
#[ bench]
511
- pub fn bench_pod ( bh : & mut BenchHarness ) {
511
+ pub fn bench_copy ( bh : & mut BenchHarness ) {
512
512
let arena = TypedArena :: new ( ) ;
513
513
bh. iter ( || {
514
514
arena. alloc ( Point {
@@ -520,7 +520,7 @@ mod tests {
520
520
}
521
521
522
522
#[ bench]
523
- pub fn bench_pod_nonarena ( bh : & mut BenchHarness ) {
523
+ pub fn bench_copy_nonarena ( bh : & mut BenchHarness ) {
524
524
bh. iter ( || {
525
525
~Point {
526
526
x : 1 ,
@@ -531,7 +531,7 @@ mod tests {
531
531
}
532
532
533
533
#[ bench]
534
- pub fn bench_pod_old_arena ( bh : & mut BenchHarness ) {
534
+ pub fn bench_copy_old_arena ( bh : & mut BenchHarness ) {
535
535
let arena = Arena :: new ( ) ;
536
536
bh. iter ( || {
537
537
arena. alloc ( || {
@@ -544,48 +544,48 @@ mod tests {
544
544
} )
545
545
}
546
546
547
- struct Nonpod {
547
+ struct Noncopy {
548
548
string : ~str ,
549
549
array : Vec < int > ,
550
550
}
551
551
552
552
#[ test]
553
- pub fn test_nonpod ( ) {
553
+ pub fn test_noncopy ( ) {
554
554
let arena = TypedArena :: new ( ) ;
555
555
for _ in range ( 0 , 100000 ) {
556
- arena. alloc ( Nonpod {
556
+ arena. alloc ( Noncopy {
557
557
string : ~"hello world",
558
558
array : vec ! ( 1 , 2 , 3 , 4 , 5 ) ,
559
559
} ) ;
560
560
}
561
561
}
562
562
563
563
#[ bench]
564
- pub fn bench_nonpod ( bh : & mut BenchHarness ) {
564
+ pub fn bench_noncopy ( bh : & mut BenchHarness ) {
565
565
let arena = TypedArena :: new ( ) ;
566
566
bh. iter ( || {
567
- arena. alloc ( Nonpod {
567
+ arena. alloc ( Noncopy {
568
568
string : ~"hello world",
569
569
array : vec ! ( 1 , 2 , 3 , 4 , 5 ) ,
570
570
} )
571
571
} )
572
572
}
573
573
574
574
#[ bench]
575
- pub fn bench_nonpod_nonarena ( bh : & mut BenchHarness ) {
575
+ pub fn bench_noncopy_nonarena ( bh : & mut BenchHarness ) {
576
576
bh. iter ( || {
577
- ~Nonpod {
577
+ ~Noncopy {
578
578
string : ~"hello world",
579
579
array : vec ! ( 1 , 2 , 3 , 4 , 5 ) ,
580
580
}
581
581
} )
582
582
}
583
583
584
584
#[ bench]
585
- pub fn bench_nonpod_old_arena ( bh : & mut BenchHarness ) {
585
+ pub fn bench_noncopy_old_arena ( bh : & mut BenchHarness ) {
586
586
let arena = Arena :: new ( ) ;
587
587
bh. iter ( || {
588
- arena. alloc ( || Nonpod {
588
+ arena. alloc ( || Noncopy {
589
589
string : ~"hello world",
590
590
array : vec ! ( 1 , 2 , 3 , 4 , 5 ) ,
591
591
} )
0 commit comments