about summary refs log tree commit diff
path: root/src/libsyntax/util
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2014-03-02 08:31:33 -0800
committerbors <bors@rust-lang.org>2014-03-02 08:31:33 -0800
commit910012aabae3dfd4b7190f46e88cde75804b5cb0 (patch)
treeac07696b5bb7a8ba6dacd1b2abd3926b59621058 /src/libsyntax/util
parentbaf79083aedb8ae64efddbcf28b358841cfd1157 (diff)
parent355932407ba324d33cd9353a69203f7f76c059a6 (diff)
downloadrust-910012aabae3dfd4b7190f46e88cde75804b5cb0.tar.gz
rust-910012aabae3dfd4b7190f46e88cde75804b5cb0.zip
auto merge of #12637 : pcwalton/rust/devecing, r=alexcrichton
r? @alexcrichton
Diffstat (limited to 'src/libsyntax/util')
-rw-r--r--src/libsyntax/util/interner.rs17
-rw-r--r--src/libsyntax/util/parser_testing.rs14
-rw-r--r--src/libsyntax/util/small_vector.rs34
3 files changed, 36 insertions, 29 deletions
diff --git a/src/libsyntax/util/interner.rs b/src/libsyntax/util/interner.rs
index 7b885df0317..ba154a8d892 100644
--- a/src/libsyntax/util/interner.rs
+++ b/src/libsyntax/util/interner.rs
@@ -21,10 +21,11 @@ use std::cmp::Equiv;
 use std::fmt;
 use std::hash::Hash;
 use std::rc::Rc;
+use std::vec_ng::Vec;
 
 pub struct Interner<T> {
     priv map: RefCell<HashMap<T, Name>>,
-    priv vect: RefCell<~[T]>,
+    priv vect: RefCell<Vec<T> >,
 }
 
 // when traits can extend traits, we should extend index<Name,T> to get []
@@ -32,7 +33,7 @@ impl<T:Eq + Hash + Freeze + Clone + 'static> Interner<T> {
     pub fn new() -> Interner<T> {
         Interner {
             map: RefCell::new(HashMap::new()),
-            vect: RefCell::new(~[]),
+            vect: RefCell::new(Vec::new()),
         }
     }
 
@@ -68,7 +69,7 @@ impl<T:Eq + Hash + Freeze + Clone + 'static> Interner<T> {
 
     pub fn get(&self, idx: Name) -> T {
         let vect = self.vect.borrow();
-        vect.get()[idx].clone()
+        (*vect.get().get(idx as uint)).clone()
     }
 
     pub fn len(&self) -> uint {
@@ -134,7 +135,7 @@ impl RcStr {
 // &str rather than RcStr, resulting in less allocation.
 pub struct StrInterner {
     priv map: RefCell<HashMap<RcStr, Name>>,
-    priv vect: RefCell<~[RcStr]>,
+    priv vect: RefCell<Vec<RcStr> >,
 }
 
 // when traits can extend traits, we should extend index<Name,T> to get []
@@ -142,7 +143,7 @@ impl StrInterner {
     pub fn new() -> StrInterner {
         StrInterner {
             map: RefCell::new(HashMap::new()),
-            vect: RefCell::new(~[]),
+            vect: RefCell::new(Vec::new()),
         }
     }
 
@@ -189,21 +190,21 @@ impl StrInterner {
         let new_idx = self.len() as Name;
         // leave out of map to avoid colliding
         let mut vect = self.vect.borrow_mut();
-        let existing = vect.get()[idx].clone();
+        let existing = (*vect.get().get(idx as uint)).clone();
         vect.get().push(existing);
         new_idx
     }
 
     pub fn get(&self, idx: Name) -> RcStr {
         let vect = self.vect.borrow();
-        vect.get()[idx].clone()
+        (*vect.get().get(idx as uint)).clone()
     }
 
     /// Returns this string with lifetime tied to the interner. Since
     /// strings may never be removed from the interner, this is safe.
     pub fn get_ref<'a>(&'a self, idx: Name) -> &'a str {
         let vect = self.vect.borrow();
-        let s: &str = vect.get()[idx].as_slice();
+        let s: &str = vect.get().get(idx as uint).as_slice();
         unsafe {
             cast::transmute(s)
         }
diff --git a/src/libsyntax/util/parser_testing.rs b/src/libsyntax/util/parser_testing.rs
index 8c7ad028a8e..03fc30e2fd7 100644
--- a/src/libsyntax/util/parser_testing.rs
+++ b/src/libsyntax/util/parser_testing.rs
@@ -15,22 +15,24 @@ use parse::{new_parser_from_source_str};
 use parse::parser::Parser;
 use parse::token;
 
+use std::vec_ng::Vec;
+
 // map a string to tts, using a made-up filename: return both the TokenTree's
 // and the ParseSess
-pub fn string_to_tts_and_sess (source_str : ~str) -> (~[ast::TokenTree], @ParseSess) {
+pub fn string_to_tts_and_sess (source_str : ~str) -> (Vec<ast::TokenTree> , @ParseSess) {
     let ps = new_parse_sess();
     (filemap_to_tts(ps,string_to_filemap(ps,source_str,~"bogofile")),ps)
 }
 
 // map a string to tts, using a made-up filename:
-pub fn string_to_tts(source_str : ~str) -> ~[ast::TokenTree] {
+pub fn string_to_tts(source_str : ~str) -> Vec<ast::TokenTree> {
     let (tts,_) = string_to_tts_and_sess(source_str);
     tts
 }
 
 pub fn string_to_parser_and_sess(source_str: ~str) -> (Parser,@ParseSess) {
     let ps = new_parse_sess();
-    (new_parser_from_source_str(ps,~[],~"bogofile",source_str),ps)
+    (new_parser_from_source_str(ps,Vec::new(),~"bogofile",source_str),ps)
 }
 
 // map string to parser (via tts)
@@ -69,14 +71,14 @@ pub fn string_to_expr (source_str : ~str) -> @ast::Expr {
 // parse a string, return an item
 pub fn string_to_item (source_str : ~str) -> Option<@ast::Item> {
     with_error_checking_parse(source_str, |p| {
-        p.parse_item(~[])
+        p.parse_item(Vec::new())
     })
 }
 
 // parse a string, return a stmt
 pub fn string_to_stmt(source_str : ~str) -> @ast::Stmt {
     with_error_checking_parse(source_str, |p| {
-        p.parse_stmt(~[])
+        p.parse_stmt(Vec::new())
     })
 }
 
@@ -87,7 +89,7 @@ pub fn string_to_pat(source_str : ~str) -> @ast::Pat {
 }
 
 // convert a vector of strings to a vector of ast::Ident's
-pub fn strs_to_idents(ids: ~[&str]) -> ~[ast::Ident] {
+pub fn strs_to_idents(ids: Vec<&str> ) -> Vec<ast::Ident> {
     ids.map(|u| token::str_to_ident(*u))
 }
 
diff --git a/src/libsyntax/util/small_vector.rs b/src/libsyntax/util/small_vector.rs
index d6cc35a6f9d..9eb9871bb21 100644
--- a/src/libsyntax/util/small_vector.rs
+++ b/src/libsyntax/util/small_vector.rs
@@ -7,14 +7,16 @@
 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
+
 use std::mem;
-use std::vec;
+use std::vec_ng::Vec;
+use std::vec_ng;
 
 /// A vector type optimized for cases where the size is almost always 0 or 1
 pub enum SmallVector<T> {
     priv Zero,
     priv One(T),
-    priv Many(~[T]),
+    priv Many(Vec<T> ),
 }
 
 impl<T> Container for SmallVector<T> {
@@ -46,7 +48,7 @@ impl<T> SmallVector<T> {
         One(v)
     }
 
-    pub fn many(vs: ~[T]) -> SmallVector<T> {
+    pub fn many(vs: Vec<T> ) -> SmallVector<T> {
         Many(vs)
     }
 
@@ -56,7 +58,7 @@ impl<T> SmallVector<T> {
             One(..) => {
                 let one = mem::replace(self, Zero);
                 match one {
-                    One(v1) => mem::replace(self, Many(~[v1, v])),
+                    One(v1) => mem::replace(self, Many(vec!(v1, v))),
                     _ => unreachable!()
                 };
             }
@@ -73,7 +75,7 @@ impl<T> SmallVector<T> {
     pub fn get<'a>(&'a self, idx: uint) -> &'a T {
         match *self {
             One(ref v) if idx == 0 => v,
-            Many(ref vs) => &vs[idx],
+            Many(ref vs) => vs.get(idx),
             _ => fail!("out of bounds access")
         }
     }
@@ -104,7 +106,7 @@ impl<T> SmallVector<T> {
 pub enum MoveItems<T> {
     priv ZeroIterator,
     priv OneIterator(T),
-    priv ManyIterator(vec::MoveItems<T>),
+    priv ManyIterator(vec_ng::MoveItems<T>),
 }
 
 impl<T> Iterator<T> for MoveItems<T> {
@@ -136,13 +138,15 @@ impl<T> Iterator<T> for MoveItems<T> {
 mod test {
     use super::*;
 
+    use std::vec_ng::Vec;
+
     #[test]
     fn test_len() {
         let v: SmallVector<int> = SmallVector::zero();
         assert_eq!(0, v.len());
 
         assert_eq!(1, SmallVector::one(1).len());
-        assert_eq!(5, SmallVector::many(~[1, 2, 3, 4, 5]).len());
+        assert_eq!(5, SmallVector::many(vec!(1, 2, 3, 4, 5)).len());
     }
 
     #[test]
@@ -161,7 +165,7 @@ mod test {
 
     #[test]
     fn test_from_iterator() {
-        let v: SmallVector<int> = (~[1, 2, 3]).move_iter().collect();
+        let v: SmallVector<int> = (vec!(1, 2, 3)).move_iter().collect();
         assert_eq!(3, v.len());
         assert_eq!(&1, v.get(0));
         assert_eq!(&2, v.get(1));
@@ -171,14 +175,14 @@ mod test {
     #[test]
     fn test_move_iter() {
         let v = SmallVector::zero();
-        let v: ~[int] = v.move_iter().collect();
-        assert_eq!(~[], v);
+        let v: Vec<int> = v.move_iter().collect();
+        assert_eq!(Vec::new(), v);
 
         let v = SmallVector::one(1);
-        assert_eq!(~[1], v.move_iter().collect());
+        assert_eq!(vec!(1), v.move_iter().collect());
 
-        let v = SmallVector::many(~[1, 2, 3]);
-        assert_eq!(~[1, 2, 3], v.move_iter().collect());
+        let v = SmallVector::many(vec!(1, 2, 3));
+        assert_eq!(vec!(1, 2, 3), v.move_iter().collect());
     }
 
     #[test]
@@ -190,12 +194,12 @@ mod test {
     #[test]
     #[should_fail]
     fn test_expect_one_many() {
-        SmallVector::many(~[1, 2]).expect_one("");
+        SmallVector::many(vec!(1, 2)).expect_one("");
     }
 
     #[test]
     fn test_expect_one_one() {
         assert_eq!(1, SmallVector::one(1).expect_one(""));
-        assert_eq!(1, SmallVector::many(~[1]).expect_one(""));
+        assert_eq!(1, SmallVector::many(vec!(1)).expect_one(""));
     }
 }