]> git.lizzy.rs Git - rust.git/commitdiff
Use Box<[u8]> instead of Vec<u8> for allocations.
authorScott Olson <scott@solson.me>
Tue, 22 Mar 2016 06:48:28 +0000 (00:48 -0600)
committerScott Olson <scott@solson.me>
Tue, 22 Mar 2016 06:48:28 +0000 (00:48 -0600)
src/memory.rs

index 72dd0d9b1e9edffea3188837afa8aaa0afdc6e8f..fc66b847ef9d06e1553ffa8ec5ae50880e64fa90 100644 (file)
@@ -18,7 +18,7 @@ pub struct Memory {
 
 #[derive(Debug)]
 pub struct Allocation {
-    pub bytes: Vec<u8>,
+    pub bytes: Box<[u8]>,
     pub relocations: BTreeMap<usize, AllocId>,
     // TODO(tsion): undef mask
 }
@@ -76,7 +76,10 @@ pub fn new() -> Self {
 
     pub fn allocate(&mut self, size: usize) -> Pointer {
         let id = AllocId(self.next_id);
-        let alloc = Allocation { bytes: vec![0; size], relocations: BTreeMap::new() };
+        let alloc = Allocation {
+            bytes: vec![0; size].into_boxed_slice(),
+            relocations: BTreeMap::new(),
+        };
         self.alloc_map.insert(self.next_id, alloc);
         self.next_id += 1;
         Pointer {