about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorNiko Matsakis <niko@alum.mit.edu>2013-03-01 19:38:39 -0500
committerNiko Matsakis <niko@alum.mit.edu>2013-03-01 19:58:17 -0500
commitca9549bdfc3dd969e9182d58038f90bbef026ded (patch)
treed66509b54f56151513e8207da875cb4e7df9ec85 /src
parent50c08dbf0d0150de41fcc7f5e87a97c4ea2bd4f0 (diff)
downloadrust-ca9549bdfc3dd969e9182d58038f90bbef026ded.tar.gz
rust-ca9549bdfc3dd969e9182d58038f90bbef026ded.zip
Avoid calling to_vec() unnecessarily in parser.
Also, rename the OptVec-to-vector conversion method to
opt_vec::take_vec() and convert from a method into a fn
because I fear strange bugs.
Diffstat (limited to 'src')
-rw-r--r--src/librustc/middle/trans/callee.rs2
-rw-r--r--src/libsyntax/ext/auto_encode.rs4
-rw-r--r--src/libsyntax/ext/pipes/ast_builder.rs10
-rw-r--r--src/libsyntax/opt_vec.rs18
-rw-r--r--src/libsyntax/parse/parser.rs12
5 files changed, 28 insertions, 18 deletions
diff --git a/src/librustc/middle/trans/callee.rs b/src/librustc/middle/trans/callee.rs
index e7934ae4ab7..5ebc787dce1 100644
--- a/src/librustc/middle/trans/callee.rs
+++ b/src/librustc/middle/trans/callee.rs
@@ -730,7 +730,7 @@ pub fn trans_arg_expr(bcx: block,
 
                     ast::by_copy => {
                         debug!("by copy arg with type %s, storing to scratch",
-                               ty_to_str(ccx.tcx, arg_datum.ty));
+                               bcx.ty_to_str(arg_datum.ty));
                         let scratch = scratch_datum(bcx, arg_datum.ty, false);
 
                         arg_datum.store_to_datum(bcx, arg_expr.id,
diff --git a/src/libsyntax/ext/auto_encode.rs b/src/libsyntax/ext/auto_encode.rs
index 5f076136271..b00fa9d0a19 100644
--- a/src/libsyntax/ext/auto_encode.rs
+++ b/src/libsyntax/ext/auto_encode.rs
@@ -460,8 +460,8 @@ fn mk_impl(
     let ty = cx.ty_path(
         span,
         ~[ident],
-        generics.ty_params.map(
-            |tp| cx.ty_path(span, ~[tp.ident], ~[])).to_vec()
+        opt_vec::take_vec(generics.ty_params.map(
+            |tp| cx.ty_path(span, ~[tp.ident], ~[])))
     );
 
     let generics = ast::Generics {
diff --git a/src/libsyntax/ext/pipes/ast_builder.rs b/src/libsyntax/ext/pipes/ast_builder.rs
index 3e6dedb3b31..6e1406e3647 100644
--- a/src/libsyntax/ext/pipes/ast_builder.rs
+++ b/src/libsyntax/ext/pipes/ast_builder.rs
@@ -394,13 +394,15 @@ impl ext_ctxt_ast_builder for ext_ctxt {
     }
 
     fn ty_vars(&self, ty_params: &OptVec<ast::TyParam>) -> ~[@ast::Ty] {
-        ty_params.map(|p| self.ty_path_ast_builder(
-            path(~[p.ident], dummy_sp()))).to_vec()
+        opt_vec::take_vec(
+            ty_params.map(|p| self.ty_path_ast_builder(
+                path(~[p.ident], dummy_sp()))))
     }
 
     fn ty_vars_global(&self,
                       ty_params: &OptVec<ast::TyParam>) -> ~[@ast::Ty] {
-        ty_params.map(|p| self.ty_path_ast_builder(
-            path(~[p.ident], dummy_sp()))).to_vec()
+        opt_vec::take_vec(
+            ty_params.map(|p| self.ty_path_ast_builder(
+                path(~[p.ident], dummy_sp()))))
     }
 }
diff --git a/src/libsyntax/opt_vec.rs b/src/libsyntax/opt_vec.rs
index 22d69d89e81..340e2614d2e 100644
--- a/src/libsyntax/opt_vec.rs
+++ b/src/libsyntax/opt_vec.rs
@@ -31,6 +31,14 @@ pub fn with<T>(+t: T) -> OptVec<T> {
     Vec(~[t])
 }
 
+pub fn from<T>(+t: ~[T]) -> OptVec<T> {
+    if t.len() == 0 {
+        Empty
+    } else {
+        Vec(t)
+    }
+}
+
 impl<T> OptVec<T> {
     fn push(&mut self, +t: T) {
         match *self {
@@ -70,12 +78,12 @@ impl<T> OptVec<T> {
             Vec(ref v) => v.len()
         }
     }
+}
 
-    pure fn to_vec(self) -> ~[T] {
-        match self {
-            Empty => ~[],
-            Vec(v) => v
-        }
+pub fn take_vec<T>(+v: OptVec<T>) -> ~[T] {
+    match v {
+        Empty => ~[],
+        Vec(v) => v
     }
 }
 
diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs
index 9ad3e60ba84..6294243d486 100644
--- a/src/libsyntax/parse/parser.rs
+++ b/src/libsyntax/parse/parser.rs
@@ -1157,7 +1157,7 @@ pub impl Parser {
                     let remaining_exprs =
                         self.parse_seq_to_end(token::RBRACKET,
                             seq_sep_trailing_allowed(token::COMMA),
-                            |p| p.parse_expr()).to_vec();
+                            |p| p.parse_expr());
                     ex = expr_vec(~[first_expr] + remaining_exprs, mutbl);
                 } else {
                     // Vector with one element.
@@ -1419,7 +1419,7 @@ pub impl Parser {
                 vec::append(
                     self.parse_seq_to_before_end(
                         ket, seq_sep_none(),
-                        |p| p.parse_token_tree()).to_vec(),
+                        |p| p.parse_token_tree()),
                     // the close delimiter:
                     ~[parse_any_tt_tok(self)])))
           }
@@ -2727,7 +2727,7 @@ pub impl Parser {
         let result = self.parse_seq_to_gt(
             Some(token::COMMA),
             |p| p.parse_ty(false));
-        result.to_vec()
+        opt_vec::take_vec(result)
     }
 
     fn parse_fn_decl(parse_arg_fn: fn(Parser) -> arg_or_capture_item)
@@ -2819,7 +2819,7 @@ pub impl Parser {
                     args_or_capture_items =
                         self.parse_seq_to_before_end(token::RPAREN,
                                                      sep,
-                                                     parse_arg_fn).to_vec();
+                                                     parse_arg_fn);
                 }
                 token::RPAREN => {
                     args_or_capture_items = ~[];
@@ -2835,7 +2835,7 @@ pub impl Parser {
             args_or_capture_items =
                 self.parse_seq_to_before_end(token::RPAREN,
                                              sep,
-                                             parse_arg_fn).to_vec();
+                                             parse_arg_fn);
         }
 
         self.expect(token::RPAREN);
@@ -3032,7 +3032,7 @@ pub impl Parser {
     fn parse_trait_ref_list(ket: token::Token) -> ~[@trait_ref] {
         self.parse_seq_to_before_end(
             ket, seq_sep_none(),
-            |p| p.parse_trait_ref()).to_vec()
+            |p| p.parse_trait_ref())
     }
 
     fn parse_item_struct() -> item_info {