@@ -54,7 +54,7 @@ use clone::Clone;
54
54
use iter:: { range, Iterator } ;
55
55
use kinds:: Send ;
56
56
use kinds:: marker;
57
- use mem:: { forget, min_align_of, size_of, transmute} ;
57
+ use mem:: { forget, min_align_of, size_of, transmute, overwrite } ;
58
58
use ops:: Drop ;
59
59
use option:: { Option , Some , None } ;
60
60
use owned:: Box ;
@@ -371,20 +371,20 @@ impl<T: Send> Buffer<T> {
371
371
// Apparently LLVM cannot optimize (foo % (1 << bar)) into this implicitly
372
372
fn mask ( & self ) -> int { ( 1 << self . log_size ) - 1 }
373
373
374
+ unsafe fn elem ( & self , i : int ) -> * T { self . storage . offset ( i & self . mask ( ) ) }
375
+
374
376
// This does not protect against loading duplicate values of the same cell,
375
377
// nor does this clear out the contents contained within. Hence, this is a
376
378
// very unsafe method which the caller needs to treat specially in case a
377
379
// race is lost.
378
380
unsafe fn get ( & self , i : int ) -> T {
379
- ptr:: read ( self . storage . offset ( i & self . mask ( ) ) )
381
+ ptr:: read ( self . elem ( i ) )
380
382
}
381
383
382
384
// Unsafe because this unsafely overwrites possibly uninitialized or
383
385
// initialized data.
384
386
unsafe fn put ( & self , i : int , t : T ) {
385
- let ptr = self . storage . offset ( i & self . mask ( ) ) ;
386
- ptr:: copy_nonoverlapping_memory ( ptr as * mut T , & t as * T , 1 ) ;
387
- forget ( t) ;
387
+ overwrite ( self . elem ( i) as * mut T , t) ;
388
388
}
389
389
390
390
// Again, unsafe because this has incredibly dubious ownership violations.
0 commit comments