about summary refs log tree commit diff
path: root/src/libextra
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2014-01-03 22:36:53 -0800
committerbors <bors@rust-lang.org>2014-01-03 22:36:53 -0800
commit3dd7c49faf5ae3a9158ab242a264c0f0eb99f657 (patch)
tree0393c0b2e10c7579d86c222071bb9c64b0451b60 /src/libextra
parent0ff6c12ce94993dae702d597a213eee6b969231a (diff)
parent80921536343e87d2f7d7f19ad90d63f50b557e06 (diff)
auto merge of #11251 : pcwalton/rust/remove-at-mut, r=pcwalton
r? @nikomatsakis 

for the borrow checker changes. Write guards are now eliminated.
Diffstat (limited to 'src/libextra')
-rw-r--r--src/libextra/arena.rs61
-rw-r--r--src/libextra/list.rs27
-rw-r--r--src/libextra/serialize.rs12
-rw-r--r--src/libextra/term.rs3
-rw-r--r--src/libextra/terminfo/searcher.rs14
-rw-r--r--src/libextra/test.rs3
-rw-r--r--src/libextra/uuid.rs4
-rw-r--r--src/libextra/workcache.rs10
8 files changed, 55 insertions, 79 deletions
diff --git a/src/libextra/arena.rs b/src/libextra/arena.rs
index dc5f3b5d3cf..5ee0099561a 100644
--- a/src/libextra/arena.rs
+++ b/src/libextra/arena.rs
@@ -35,11 +35,13 @@
 #[allow(missing_doc)];
 
 
-use list::{MutList, MutCons, MutNil};
+use list::{List, Cons, Nil};
+use list;
 
 use std::at_vec;
 use std::cast::{transmute, transmute_mut, transmute_mut_region};
 use std::cast;
+use std::cell::{Cell, RefCell};
 use std::num;
 use std::ptr;
 use std::mem;
@@ -50,10 +52,11 @@ use std::unstable::intrinsics::{TyDesc, get_tydesc};
 // The way arena uses arrays is really deeply awful. The arrays are
 // allocated, and have capacities reserved, but the fill for the array
 // will always stay at 0.
+#[deriving(Clone)]
 struct Chunk {
-    data: @[u8],
-    fill: uint,
-    is_pod: bool,
+    data: RefCell<@[u8]>,
+    fill: Cell<uint>,
+    is_pod: Cell<bool>,
 }
 
 #[no_freeze]
@@ -63,7 +66,7 @@ pub struct Arena {
     // access the head.
     priv head: Chunk,
     priv pod_head: Chunk,
-    priv chunks: @mut MutList<Chunk>,
+    priv chunks: RefCell<@List<Chunk>>,
 }
 
 impl Arena {
@@ -75,7 +78,7 @@ impl Arena {
         Arena {
             head: chunk(initial_size, false),
             pod_head: chunk(initial_size, true),
-            chunks: @mut MutNil,
+            chunks: RefCell::new(@Nil),
         }
     }
 }
@@ -84,9 +87,9 @@ fn chunk(size: uint, is_pod: bool) -> Chunk {
     let mut v: @[u8] = @[];
     unsafe { at_vec::raw::reserve(&mut v, size); }
     Chunk {
-        data: unsafe { cast::transmute(v) },
-        fill: 0u,
-        is_pod: is_pod,
+        data: RefCell::new(unsafe { cast::transmute(v) }),
+        fill: Cell::new(0u),
+        is_pod: Cell::new(is_pod),
     }
 }
 
@@ -95,8 +98,9 @@ impl Drop for Arena {
     fn drop(&mut self) {
         unsafe {
             destroy_chunk(&self.head);
-            self.chunks.each(|chunk| {
-                if !chunk.is_pod {
+
+            list::each(self.chunks.get(), |chunk| {
+                if !chunk.is_pod.get() {
                     destroy_chunk(chunk);
                 }
                 true
@@ -114,8 +118,11 @@ fn round_up_to(base: uint, align: uint) -> uint {
 // in it.
 unsafe fn destroy_chunk(chunk: &Chunk) {
     let mut idx = 0;
-    let buf = chunk.data.as_ptr();
-    let fill = chunk.fill;
+    let buf = {
+        let data = chunk.data.borrow();
+        data.get().as_ptr()
+    };
+    let fill = chunk.fill.get();
 
     while idx < fill {
         let tydesc_data: *uint = transmute(ptr::offset(buf, idx as int));
@@ -155,9 +162,9 @@ impl Arena {
     // Functions for the POD part of the arena
     fn alloc_pod_grow(&mut self, n_bytes: uint, align: uint) -> *u8 {
         // Allocate a new chunk.
-        let chunk_size = at_vec::capacity(self.pod_head.data);
+        let chunk_size = at_vec::capacity(self.pod_head.data.get());
         let new_min_chunk_size = num::max(n_bytes, chunk_size);
-        self.chunks = @mut MutCons(self.pod_head, self.chunks);
+        self.chunks.set(@Cons(self.pod_head.clone(), self.chunks.get()));
         self.pod_head =
             chunk(uint::next_power_of_two(new_min_chunk_size + 1u), true);
 
@@ -168,17 +175,17 @@ impl Arena {
     fn alloc_pod_inner(&mut self, n_bytes: uint, align: uint) -> *u8 {
         unsafe {
             let this = transmute_mut_region(self);
-            let start = round_up_to(this.pod_head.fill, align);
+            let start = round_up_to(this.pod_head.fill.get(), align);
             let end = start + n_bytes;
-            if end > at_vec::capacity(this.pod_head.data) {
+            if end > at_vec::capacity(this.pod_head.data.get()) {
                 return this.alloc_pod_grow(n_bytes, align);
             }
-            this.pod_head.fill = end;
+            this.pod_head.fill.set(end);
 
             //debug!("idx = {}, size = {}, align = {}, fill = {}",
-            //       start, n_bytes, align, head.fill);
+            //       start, n_bytes, align, head.fill.get());
 
-            ptr::offset(this.pod_head.data.as_ptr(), start as int)
+            ptr::offset(this.pod_head.data.get().as_ptr(), start as int)
         }
     }
 
@@ -197,9 +204,9 @@ impl Arena {
     fn alloc_nonpod_grow(&mut self, n_bytes: uint, align: uint)
                          -> (*u8, *u8) {
         // Allocate a new chunk.
-        let chunk_size = at_vec::capacity(self.head.data);
+        let chunk_size = at_vec::capacity(self.head.data.get());
         let new_min_chunk_size = num::max(n_bytes, chunk_size);
-        self.chunks = @mut MutCons(self.head, self.chunks);
+        self.chunks.set(@Cons(self.head.clone(), self.chunks.get()));
         self.head =
             chunk(uint::next_power_of_two(new_min_chunk_size + 1u), false);
 
@@ -218,23 +225,23 @@ impl Arena {
             {
                 let head = transmute_mut_region(&mut self.head);
 
-                tydesc_start = head.fill;
-                after_tydesc = head.fill + mem::size_of::<*TyDesc>();
+                tydesc_start = head.fill.get();
+                after_tydesc = head.fill.get() + mem::size_of::<*TyDesc>();
                 start = round_up_to(after_tydesc, align);
                 end = start + n_bytes;
             }
 
-            if end > at_vec::capacity(self.head.data) {
+            if end > at_vec::capacity(self.head.data.get()) {
                 return self.alloc_nonpod_grow(n_bytes, align);
             }
 
             let head = transmute_mut_region(&mut self.head);
-            head.fill = round_up_to(end, mem::pref_align_of::<*TyDesc>());
+            head.fill.set(round_up_to(end, mem::pref_align_of::<*TyDesc>()));
 
             //debug!("idx = {}, size = {}, align = {}, fill = {}",
             //       start, n_bytes, align, head.fill);
 
-            let buf = self.head.data.as_ptr();
+            let buf = self.head.data.get().as_ptr();
             return (ptr::offset(buf, tydesc_start as int), ptr::offset(buf, start as int));
         }
     }
diff --git a/src/libextra/list.rs b/src/libextra/list.rs
index a2540d3948e..b530d9c9bc1 100644
--- a/src/libextra/list.rs
+++ b/src/libextra/list.rs
@@ -19,13 +19,6 @@ pub enum List<T> {
     Nil,
 }
 
-#[deriving(Eq)]
-#[allow(missing_doc)]
-pub enum MutList<T> {
-    MutCons(T, @mut MutList<T>),
-    MutNil,
-}
-
 /// Create a list from a vector
 pub fn from_vec<T:Clone + 'static>(v: &[T]) -> @List<T> {
     v.rev_iter().fold(@Nil::<T>, |t, h| @Cons((*h).clone(), t))
@@ -158,26 +151,6 @@ pub fn each<T>(l: @List<T>, f: |&T| -> bool) -> bool {
     }
 }
 
-impl<T> MutList<T> {
-    /// Iterate over a mutable list
-    pub fn each(@mut self, f: |&mut T| -> bool) -> bool {
-        let mut cur = self;
-        loop {
-            let borrowed = &mut *cur;
-            cur = match *borrowed {
-                MutCons(ref mut hd, tl) => {
-                    if !f(hd) {
-                        return false;
-                    }
-                    tl
-                }
-                MutNil => break
-            }
-        }
-        return true;
-    }
-}
-
 #[cfg(test)]
 mod tests {
     use list::*;
diff --git a/src/libextra/serialize.rs b/src/libextra/serialize.rs
index 6b298d877da..e7ccb91fb75 100644
--- a/src/libextra/serialize.rs
+++ b/src/libextra/serialize.rs
@@ -426,18 +426,6 @@ impl<D:Decoder,T:Decodable<D> + 'static> Decodable<D> for @T {
     }
 }
 
-impl<S:Encoder,T:Encodable<S>> Encodable<S> for @mut T {
-    fn encode(&self, s: &mut S) {
-        (**self).encode(s)
-    }
-}
-
-impl<D:Decoder,T:Decodable<D> + 'static> Decodable<D> for @mut T {
-    fn decode(d: &mut D) -> @mut T {
-        @mut Decodable::decode(d)
-    }
-}
-
 impl<'a, S:Encoder,T:Encodable<S>> Encodable<S> for &'a [T] {
     fn encode(&self, s: &mut S) {
         s.emit_seq(self.len(), |s| {
diff --git a/src/libextra/term.rs b/src/libextra/term.rs
index 05e9b65d19c..1f119ca9db4 100644
--- a/src/libextra/term.rs
+++ b/src/libextra/term.rs
@@ -113,7 +113,8 @@ impl<T: Writer> Terminal<T> {
             return Err(entry.unwrap_err());
         }
 
-        let ti = parse(entry.unwrap(), false);
+        let mut file = entry.unwrap();
+        let ti = parse(&mut file, false);
         if ti.is_err() {
             return Err(ti.unwrap_err());
         }
diff --git a/src/libextra/terminfo/searcher.rs b/src/libextra/terminfo/searcher.rs
index 09f8cc0efef..8cbb0902697 100644
--- a/src/libextra/terminfo/searcher.rs
+++ b/src/libextra/terminfo/searcher.rs
@@ -11,10 +11,9 @@
 /// Implement ncurses-compatible database discovery
 /// Does not support hashed database, only filesystem!
 
-use std::{os, str};
-use std::os::getenv;
-use std::io;
 use std::io::File;
+use std::os::getenv;
+use std::{os, str};
 
 /// Return path to database entry for `term`
 pub fn get_dbpath_for_term(term: &str) -> Option<~Path> {
@@ -74,9 +73,14 @@ pub fn get_dbpath_for_term(term: &str) -> Option<~Path> {
 }
 
 /// Return open file for `term`
-pub fn open(term: &str) -> Result<@mut io::Reader, ~str> {
+pub fn open(term: &str) -> Result<File, ~str> {
     match get_dbpath_for_term(term) {
-        Some(x) => Ok(@mut File::open(x) as @mut io::Reader),
+        Some(x) => {
+            match File::open(x) {
+                Some(file) => Ok(file),
+                None => Err(~"error opening file"),
+            }
+        }
         None => Err(format!("could not find terminfo entry for {}", term))
     }
 }
diff --git a/src/libextra/test.rs b/src/libextra/test.rs
index 63e19df9519..79fb9e3935a 100644
--- a/src/libextra/test.rs
+++ b/src/libextra/test.rs
@@ -949,7 +949,8 @@ impl MetricMap {
 
     /// Write MetricDiff to a file.
     pub fn save(&self, p: &Path) {
-        self.to_json().to_pretty_writer(@mut File::create(p) as @mut io::Writer);
+        let mut file = File::create(p);
+        self.to_json().to_pretty_writer(&mut file)
     }
 
     /// Compare against another MetricMap. Optionally compare all
diff --git a/src/libextra/uuid.rs b/src/libextra/uuid.rs
index cf40a59a8c5..ef6c9e7f9cd 100644
--- a/src/libextra/uuid.rs
+++ b/src/libextra/uuid.rs
@@ -796,8 +796,8 @@ mod test {
         use serialize::{Encodable, Decodable};
 
         let u = Uuid::new_v4();
-        let wr = @mut MemWriter::new();
-        u.encode(&mut ebml::writer::Encoder(wr));
+        let mut wr = MemWriter::new();
+        u.encode(&mut ebml::writer::Encoder(&mut wr));
         let doc = ebml::reader::Doc(wr.inner_ref().as_slice());
         let u2 = Decodable::decode(&mut ebml::reader::Decoder(doc));
         assert_eq!(u, u2);
diff --git a/src/libextra/workcache.rs b/src/libextra/workcache.rs
index 8713dbde920..874e3c70af0 100644
--- a/src/libextra/workcache.rs
+++ b/src/libextra/workcache.rs
@@ -173,8 +173,8 @@ impl Database {
 
     // FIXME #4330: This should have &mut self and should set self.db_dirty to false.
     fn save(&self) {
-        let f = @mut File::create(&self.db_filename);
-        self.db_cache.to_json().to_pretty_writer(f as @mut io::Writer);
+        let mut f = File::create(&self.db_filename);
+        self.db_cache.to_json().to_pretty_writer(&mut f);
     }
 
     fn load(&mut self) {
@@ -184,14 +184,16 @@ impl Database {
             Err(e) => fail!("Couldn't load workcache database {}: {}",
                             self.db_filename.display(),
                             e.desc),
-            Ok(r) =>
-                match json::from_reader(@mut r.unwrap() as @mut io::Reader) {
+            Ok(r) => {
+                let mut stream = r.unwrap();
+                match json::from_reader(&mut stream) {
                     Err(e) => fail!("Couldn't parse workcache database (from file {}): {}",
                                     self.db_filename.display(), e.to_str()),
                     Ok(r) => {
                         let mut decoder = json::Decoder::new(r);
                         self.db_cache = Decodable::decode(&mut decoder);
                     }
+                }
             }
         }
     }