auto merge of #14378 : huonw/rust/deque-adjustments, r=alexcrichton
Might as well remove the duplication/`forget` call.
This commit is contained in:
commit
43f942f886
1 changed files with 5 additions and 5 deletions
|
@ -54,7 +54,7 @@ use clone::Clone;
|
||||||
use iter::{range, Iterator};
|
use iter::{range, Iterator};
|
||||||
use kinds::Send;
|
use kinds::Send;
|
||||||
use kinds::marker;
|
use kinds::marker;
|
||||||
use mem::{forget, min_align_of, size_of, transmute};
|
use mem::{forget, min_align_of, size_of, transmute, overwrite};
|
||||||
use ops::Drop;
|
use ops::Drop;
|
||||||
use option::{Option, Some, None};
|
use option::{Option, Some, None};
|
||||||
use owned::Box;
|
use owned::Box;
|
||||||
|
@ -371,20 +371,20 @@ impl<T: Send> Buffer<T> {
|
||||||
// Apparently LLVM cannot optimize (foo % (1 << bar)) into this implicitly
|
// Apparently LLVM cannot optimize (foo % (1 << bar)) into this implicitly
|
||||||
fn mask(&self) -> int { (1 << self.log_size) - 1 }
|
fn mask(&self) -> int { (1 << self.log_size) - 1 }
|
||||||
|
|
||||||
|
unsafe fn elem(&self, i: int) -> *T { self.storage.offset(i & self.mask()) }
|
||||||
|
|
||||||
// This does not protect against loading duplicate values of the same cell,
|
// This does not protect against loading duplicate values of the same cell,
|
||||||
// nor does this clear out the contents contained within. Hence, this is a
|
// nor does this clear out the contents contained within. Hence, this is a
|
||||||
// very unsafe method which the caller needs to treat specially in case a
|
// very unsafe method which the caller needs to treat specially in case a
|
||||||
// race is lost.
|
// race is lost.
|
||||||
unsafe fn get(&self, i: int) -> T {
|
unsafe fn get(&self, i: int) -> T {
|
||||||
ptr::read(self.storage.offset(i & self.mask()))
|
ptr::read(self.elem(i))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Unsafe because this unsafely overwrites possibly uninitialized or
|
// Unsafe because this unsafely overwrites possibly uninitialized or
|
||||||
// initialized data.
|
// initialized data.
|
||||||
unsafe fn put(&self, i: int, t: T) {
|
unsafe fn put(&self, i: int, t: T) {
|
||||||
let ptr = self.storage.offset(i & self.mask());
|
overwrite(self.elem(i) as *mut T, t);
|
||||||
ptr::copy_nonoverlapping_memory(ptr as *mut T, &t as *T, 1);
|
|
||||||
forget(t);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Again, unsafe because this has incredibly dubious ownership violations.
|
// Again, unsafe because this has incredibly dubious ownership violations.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue