@@ -54,7 +54,7 @@ use clone::Clone;
5454use iter:: { range, Iterator } ;
5555use kinds:: Send ;
5656use kinds:: marker;
57- use mem:: { forget, min_align_of, size_of, transmute} ;
57+ use mem:: { forget, min_align_of, size_of, transmute, overwrite } ;
5858use ops:: Drop ;
5959use option:: { Option , Some , None } ;
6060use owned:: Box ;
@@ -371,20 +371,20 @@ impl<T: Send> Buffer<T> {
371371 // Apparently LLVM cannot optimize (foo % (1 << bar)) into this implicitly
372372 fn mask ( & self ) -> int { ( 1 << self . log_size ) - 1 }
373373
374+ unsafe fn elem ( & self , i : int ) -> * T { self . storage . offset ( i & self . mask ( ) ) }
375+
374376 // This does not protect against loading duplicate values of the same cell,
375377 // nor does this clear out the contents contained within. Hence, this is a
376378 // very unsafe method which the caller needs to treat specially in case a
377379 // race is lost.
378380 unsafe fn get ( & self , i : int ) -> T {
379- ptr:: read ( self . storage . offset ( i & self . mask ( ) ) )
381+ ptr:: read ( self . elem ( i ) )
380382 }
381383
382384 // Unsafe because this unsafely overwrites possibly uninitialized or
383385 // initialized data.
384386 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) ;
388388 }
389389
390390 // Again, unsafe because this has incredibly dubious ownership violations.
0 commit comments