about summary refs log tree commit diff
path: root/src/libsyntax/parse
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2014-03-21 20:06:44 -0700
committerbors <bors@rust-lang.org>2014-03-21 20:06:44 -0700
commitf5357cf3cee42d12249006a42dfa835f96ab5422 (patch)
treeab8bd94140ba08a70796786a6e5c63529a545f34 /src/libsyntax/parse
parentbbf8cdc43feea08111abc5a59dc49a7f479d3103 (diff)
parente33676b7936b12bb68f47857ab3f8ea9b757d0d5 (diff)
downloadrust-f5357cf3cee42d12249006a42dfa835f96ab5422.tar.gz
rust-f5357cf3cee42d12249006a42dfa835f96ab5422.zip
auto merge of #13016 : huonw/rust/new-opt-vec, r=cmr
Replace syntax::opt_vec with syntax::owned_slice

The `owned_slice::OwnedSlice` is  `(*T, uint)` (i.e. a direct equivalent to DSTs `~[T]`).

This shaves two words off the old OptVec type; and also makes substituting in other implementations easy, by removing all the mutation methods. (And also everything that's very rarely/never used.)
Diffstat (limited to 'src/libsyntax/parse')
-rw-r--r--src/libsyntax/parse/mod.rs22
-rw-r--r--src/libsyntax/parse/parser.rs39
2 files changed, 30 insertions, 31 deletions
diff --git a/src/libsyntax/parse/mod.rs b/src/libsyntax/parse/mod.rs
index 286b44e5c80..eb6b462fb94 100644
--- a/src/libsyntax/parse/mod.rs
+++ b/src/libsyntax/parse/mod.rs
@@ -279,7 +279,7 @@ mod test {
     use std::io::MemWriter;
     use std::str;
     use codemap::{Span, BytePos, Spanned};
-    use opt_vec;
+    use owned_slice::OwnedSlice;
     use ast;
     use abi;
     use parse::parser::Parser;
@@ -312,7 +312,7 @@ mod test {
                             ast::PathSegment {
                                 identifier: str_to_ident("a"),
                                 lifetimes: Vec::new(),
-                                types: opt_vec::Empty,
+                                types: OwnedSlice::empty(),
                             }
                         ),
                     }),
@@ -331,12 +331,12 @@ mod test {
                                 ast::PathSegment {
                                     identifier: str_to_ident("a"),
                                     lifetimes: Vec::new(),
-                                    types: opt_vec::Empty,
+                                    types: OwnedSlice::empty(),
                                 },
                                 ast::PathSegment {
                                     identifier: str_to_ident("b"),
                                     lifetimes: Vec::new(),
-                                    types: opt_vec::Empty,
+                                    types: OwnedSlice::empty(),
                                 }
                             )
                         }),
@@ -545,7 +545,7 @@ mod test {
                                 ast::PathSegment {
                                     identifier: str_to_ident("d"),
                                     lifetimes: Vec::new(),
-                                    types: opt_vec::Empty,
+                                    types: OwnedSlice::empty(),
                                 }
                             ),
                         }),
@@ -567,7 +567,7 @@ mod test {
                                 ast::PathSegment {
                                     identifier: str_to_ident("b"),
                                     lifetimes: Vec::new(),
-                                    types: opt_vec::Empty,
+                                    types: OwnedSlice::empty(),
                                 }
                                ),
                             }),
@@ -595,7 +595,7 @@ mod test {
                                         ast::PathSegment {
                                             identifier: str_to_ident("b"),
                                             lifetimes: Vec::new(),
-                                            types: opt_vec::Empty,
+                                            types: OwnedSlice::empty(),
                                         }
                                     ),
                                 },
@@ -623,7 +623,7 @@ mod test {
                                                 identifier:
                                                     str_to_ident("int"),
                                                 lifetimes: Vec::new(),
-                                                types: opt_vec::Empty,
+                                                types: OwnedSlice::empty(),
                                             }
                                         ),
                                         }, None, ast::DUMMY_NODE_ID),
@@ -641,7 +641,7 @@ mod test {
                                                         identifier:
                                                             str_to_ident("b"),
                                                         lifetimes: Vec::new(),
-                                                        types: opt_vec::Empty,
+                                                        types: OwnedSlice::empty(),
                                                     }
                                                 ),
                                             },
@@ -661,7 +661,7 @@ mod test {
                                     abi::AbiSet::Rust(),
                                     ast::Generics{ // no idea on either of these:
                                         lifetimes: Vec::new(),
-                                        ty_params: opt_vec::Empty,
+                                        ty_params: OwnedSlice::empty(),
                                     },
                                     ast::P(ast::Block {
                                         view_items: Vec::new(),
@@ -680,7 +680,7 @@ mod test {
                                                                 lifetimes:
                                                                 Vec::new(),
                                                                 types:
-                                                                opt_vec::Empty
+                                                                OwnedSlice::empty()
                                                             }
                                                         ),
                                                       }),
diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs
index 5398844d52a..c8492cc4113 100644
--- a/src/libsyntax/parse/parser.rs
+++ b/src/libsyntax/parse/parser.rs
@@ -75,8 +75,7 @@ use parse::token::{is_ident, is_ident_or_path, is_plain_ident};
 use parse::token::{keywords, special_idents, token_to_binop};
 use parse::token;
 use parse::{new_sub_parser_from_file, ParseSess};
-use opt_vec;
-use opt_vec::OptVec;
+use owned_slice::OwnedSlice;
 
 use std::cell::Cell;
 use collections::HashSet;
@@ -117,13 +116,13 @@ pub enum PathParsingMode {
 /// for the definition of a path segment.)
 struct PathSegmentAndBoundSet {
     segment: ast::PathSegment,
-    bound_set: Option<OptVec<TyParamBound>>,
+    bound_set: Option<OwnedSlice<TyParamBound>>,
 }
 
 /// A path paired with optional type bounds.
 pub struct PathAndBounds {
     path: ast::Path,
-    bounds: Option<OptVec<TyParamBound>>,
+    bounds: Option<OwnedSlice<TyParamBound>>,
 }
 
 enum ItemOrViewItem {
@@ -630,9 +629,9 @@ impl<'a> Parser<'a> {
                                   &mut self,
                                   sep: Option<token::Token>,
                                   f: |&mut Parser| -> T)
-                                  -> OptVec<T> {
+                                  -> OwnedSlice<T> {
         let mut first = true;
-        let mut v = opt_vec::Empty;
+        let mut v = Vec::new();
         while self.token != token::GT
             && self.token != token::BINOP(token::SHR) {
             match sep {
@@ -644,14 +643,14 @@ impl<'a> Parser<'a> {
             }
             v.push(f(self));
         }
-        return v;
+        return OwnedSlice::from_vec(v);
     }
 
     pub fn parse_seq_to_gt<T>(
                            &mut self,
                            sep: Option<token::Token>,
                            f: |&mut Parser| -> T)
-                           -> OptVec<T> {
+                           -> OwnedSlice<T> {
         let v = self.parse_seq_to_before_gt(sep, f);
         self.expect_gt();
         return v;
@@ -681,7 +680,7 @@ impl<'a> Parser<'a> {
                                    f: |&mut Parser| -> T)
                                    -> Vec<T> {
         let mut first: bool = true;
-        let mut v: Vec<T> = Vec::new();
+        let mut v = vec!();
         while self.token != *ket {
             match sep.sep {
               Some(ref t) => {
@@ -1531,7 +1530,7 @@ impl<'a> Parser<'a> {
                     segment: ast::PathSegment {
                         identifier: identifier,
                         lifetimes: Vec::new(),
-                        types: opt_vec::Empty,
+                        types: OwnedSlice::empty(),
                     },
                     bound_set: bound_set
                 });
@@ -1543,9 +1542,9 @@ impl<'a> Parser<'a> {
                 if mode != NoTypesAllowed && self.eat(&token::LT) {
                     let (lifetimes, types) =
                         self.parse_generic_values_after_lt();
-                    (true, lifetimes, opt_vec::from(types))
+                    (true, lifetimes, OwnedSlice::from_vec(types))
                 } else {
-                    (false, Vec::new(), opt_vec::Empty)
+                    (false, Vec::new(), OwnedSlice::empty())
                 }
             };
 
@@ -3432,12 +3431,12 @@ impl<'a> Parser<'a> {
     // Returns "Some(Empty)" if there's a colon but nothing after (e.g. "T:")
     // Returns "Some(stuff)" otherwise (e.g. "T:stuff").
     // NB: The None/Some distinction is important for issue #7264.
-    fn parse_optional_ty_param_bounds(&mut self) -> Option<OptVec<TyParamBound>> {
+    fn parse_optional_ty_param_bounds(&mut self) -> Option<OwnedSlice<TyParamBound>> {
         if !self.eat(&token::COLON) {
             return None;
         }
 
-        let mut result = opt_vec::Empty;
+        let mut result = vec!();
         loop {
             match self.token {
                 token::LIFETIME(lifetime) => {
@@ -3462,7 +3461,7 @@ impl<'a> Parser<'a> {
             }
         }
 
-        return Some(result);
+        return Some(OwnedSlice::from_vec(result));
     }
 
     // matches typaram = IDENT optbounds ( EQ ty )?
@@ -3515,7 +3514,7 @@ impl<'a> Parser<'a> {
         let result = self.parse_seq_to_gt(
             Some(token::COMMA),
             |p| p.parse_ty(false));
-        (lifetimes, opt_vec::take_vec(result))
+        (lifetimes, result.into_vec())
     }
 
     fn parse_fn_args(&mut self, named_args: bool, allow_variadic: bool)
@@ -4882,7 +4881,7 @@ impl<'a> Parser<'a> {
                     ast::PathSegment {
                         identifier: identifier,
                         lifetimes: Vec::new(),
-                        types: opt_vec::Empty,
+                        types: OwnedSlice::empty(),
                     }
                 }).collect()
             };
@@ -4917,7 +4916,7 @@ impl<'a> Parser<'a> {
                             ast::PathSegment {
                                 identifier: identifier,
                                 lifetimes: Vec::new(),
-                                types: opt_vec::Empty,
+                                types: OwnedSlice::empty(),
                             }
                         }).collect()
                     };
@@ -4935,7 +4934,7 @@ impl<'a> Parser<'a> {
                             ast::PathSegment {
                                 identifier: identifier,
                                 lifetimes: Vec::new(),
-                                types: opt_vec::Empty,
+                                types: OwnedSlice::empty(),
                             }
                         }).collect()
                     };
@@ -4957,7 +4956,7 @@ impl<'a> Parser<'a> {
                 ast::PathSegment {
                     identifier: identifier,
                     lifetimes: Vec::new(),
-                    types: opt_vec::Empty,
+                    types: OwnedSlice::empty(),
                 }
             }).collect()
         };