about summary refs log tree commit diff
path: root/src/libstd/arena.rs
diff options
context:
space:
mode:
authorNiko Matsakis <niko@alum.mit.edu>2012-03-21 05:45:52 -0700
committerNiko Matsakis <niko@alum.mit.edu>2012-03-21 05:46:31 -0700
commitcce2751461729147ecdbf514e6df6a7052f8f6af (patch)
treefc8788b77d84af7cf5ef302ee5e4441c3e712111 /src/libstd/arena.rs
parent8404ea0c8af1e5006faa8aad0b4b2ab718204902 (diff)
downloadrust-cce2751461729147ecdbf514e6df6a7052f8f6af.tar.gz
rust-cce2751461729147ecdbf514e6df6a7052f8f6af.zip
Adjust arena definition to be compatible with placement new
Diffstat (limited to 'src/libstd/arena.rs')
-rw-r--r--src/libstd/arena.rs19
1 files changed, 13 insertions, 6 deletions
diff --git a/src/libstd/arena.rs b/src/libstd/arena.rs
index eb293d4f2d9..3c316ecf5cc 100644
--- a/src/libstd/arena.rs
+++ b/src/libstd/arena.rs
@@ -20,19 +20,26 @@ fn arena() -> arena {
 }
 
 impl arena for arena {
-    unsafe fn alloc<T>(n_bytes: uint) -> &self.T {
+    fn alloc(n_bytes: uint, align: uint) -> *() {
+        let alignm1 = align - 1u;
         let mut head = list::head(self.chunks);
-        if head.fill + n_bytes > vec::len(head.data) {
+
+        let mut start = head.fill;
+        start = (start + alignm1) & !alignm1;
+        let mut end = start + n_bytes;
+
+        if end > vec::len(head.data) {
             // Allocate a new chunk.
             let new_min_chunk_size = uint::max(n_bytes, vec::len(head.data));
             head = chunk(uint::next_power_of_two(new_min_chunk_size));
             self.chunks = list::cons(head, @self.chunks);
+            start = 0u;
+            end = n_bytes;
         }
 
-        let start = vec::unsafe::to_ptr(head.data);
-        let p = ptr::offset(start, head.fill);
-        head.fill += n_bytes;
-        ret unsafe::reinterpret_cast(p);
+        let p = ptr::offset(ptr::addr_of(head.fill), start);
+        head.fill = end;
+        unsafe { ret unsafe::reinterpret_cast(p); }
     }
 }