about summary refs log tree commit diff
diff options
context:
space:
mode:
authorHuon Wilson <dbau.pp+github@gmail.com>2014-05-24 01:07:05 +1000
committerHuon Wilson <dbau.pp+github@gmail.com>2014-05-24 21:44:37 +1000
commit9a8379deb296b7a8b543fca635c52307d13f6daf (patch)
tree2e955efff70c647d73beec50f46535904f564d6c
parent9e244d708461d5028066a59e70866f52517e7b85 (diff)
downloadrust-9a8379deb296b7a8b543fca635c52307d13f6daf.tar.gz
rust-9a8379deb296b7a8b543fca635c52307d13f6daf.zip
std: minor simplification to sync::deque.
-rw-r--r--src/libstd/sync/deque.rs10
1 files changed, 5 insertions, 5 deletions
diff --git a/src/libstd/sync/deque.rs b/src/libstd/sync/deque.rs
index a3fdc4d3eaf..46d6129ded8 100644
--- a/src/libstd/sync/deque.rs
+++ b/src/libstd/sync/deque.rs
@@ -54,7 +54,7 @@ use clone::Clone;
 use iter::{range, Iterator};
 use kinds::Send;
 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 option::{Option, Some, None};
 use owned::Box;
@@ -371,20 +371,20 @@ impl<T: Send> Buffer<T> {
     // Apparently LLVM cannot optimize (foo % (1 << bar)) into this implicitly
     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,
     // 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
     // race is lost.
     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
     // initialized data.
     unsafe fn put(&self, i: int, t: T) {
-        let ptr = self.storage.offset(i & self.mask());
-        ptr::copy_nonoverlapping_memory(ptr as *mut T, &t as *T, 1);
-        forget(t);
+        overwrite(self.elem(i) as *mut T, t);
     }
 
     // Again, unsafe because this has incredibly dubious ownership violations.