Skip to content

Commit 43f942f

Browse files
committed
auto merge of #14378 : huonw/rust/deque-adjustments, r=alexcrichton
Might as well remove the duplication/`forget` call.
2 parents b546fff + 9a8379d commit 43f942f

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/libstd/sync/deque.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ use clone::Clone;
5454
use iter::{range, Iterator};
5555
use kinds::Send;
5656
use kinds::marker;
57-
use mem::{forget, min_align_of, size_of, transmute};
57+
use mem::{forget, min_align_of, size_of, transmute, overwrite};
5858
use ops::Drop;
5959
use option::{Option, Some, None};
6060
use 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

Comments
 (0)