Skip to content

Commit 657c442

Browse files
committed
Merge remote branch 'nmatsakis/parser-perf-problem' into incoming
2 parents cab8ec2 + ca9549b commit 657c442

File tree

5 files changed

+28
-18
lines changed

5 files changed

+28
-18
lines changed

src/librustc/middle/trans/callee.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -731,7 +731,7 @@ pub fn trans_arg_expr(bcx: block,
731731

732732
ast::by_copy => {
733733
debug!("by copy arg with type %s, storing to scratch",
734-
ty_to_str(ccx.tcx, arg_datum.ty));
734+
bcx.ty_to_str(arg_datum.ty));
735735
let scratch = scratch_datum(bcx, arg_datum.ty, false);
736736

737737
arg_datum.store_to_datum(bcx, arg_expr.id,

src/libsyntax/ext/auto_encode.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -460,8 +460,8 @@ fn mk_impl(
460460
let ty = cx.ty_path(
461461
span,
462462
~[ident],
463-
generics.ty_params.map(
464-
|tp| cx.ty_path(span, ~[tp.ident], ~[])).to_vec()
463+
opt_vec::take_vec(generics.ty_params.map(
464+
|tp| cx.ty_path(span, ~[tp.ident], ~[])))
465465
);
466466

467467
let generics = ast::Generics {

src/libsyntax/ext/pipes/ast_builder.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -394,13 +394,15 @@ impl ext_ctxt_ast_builder for ext_ctxt {
394394
}
395395

396396
fn ty_vars(&self, ty_params: &OptVec<ast::TyParam>) -> ~[@ast::Ty] {
397-
ty_params.map(|p| self.ty_path_ast_builder(
398-
path(~[p.ident], dummy_sp()))).to_vec()
397+
opt_vec::take_vec(
398+
ty_params.map(|p| self.ty_path_ast_builder(
399+
path(~[p.ident], dummy_sp()))))
399400
}
400401

401402
fn ty_vars_global(&self,
402403
ty_params: &OptVec<ast::TyParam>) -> ~[@ast::Ty] {
403-
ty_params.map(|p| self.ty_path_ast_builder(
404-
path(~[p.ident], dummy_sp()))).to_vec()
404+
opt_vec::take_vec(
405+
ty_params.map(|p| self.ty_path_ast_builder(
406+
path(~[p.ident], dummy_sp()))))
405407
}
406408
}

src/libsyntax/opt_vec.rs

+13-5
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,14 @@ pub fn with<T>(+t: T) -> OptVec<T> {
3131
Vec(~[t])
3232
}
3333

34+
pub fn from<T>(+t: ~[T]) -> OptVec<T> {
35+
if t.len() == 0 {
36+
Empty
37+
} else {
38+
Vec(t)
39+
}
40+
}
41+
3442
impl<T> OptVec<T> {
3543
fn push(&mut self, +t: T) {
3644
match *self {
@@ -70,12 +78,12 @@ impl<T> OptVec<T> {
7078
Vec(ref v) => v.len()
7179
}
7280
}
81+
}
7382

74-
pure fn to_vec(self) -> ~[T] {
75-
match self {
76-
Empty => ~[],
77-
Vec(v) => v
78-
}
83+
pub fn take_vec<T>(+v: OptVec<T>) -> ~[T] {
84+
match v {
85+
Empty => ~[],
86+
Vec(v) => v
7987
}
8088
}
8189

src/libsyntax/parse/parser.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -1157,7 +1157,7 @@ pub impl Parser {
11571157
let remaining_exprs =
11581158
self.parse_seq_to_end(token::RBRACKET,
11591159
seq_sep_trailing_allowed(token::COMMA),
1160-
|p| p.parse_expr()).to_vec();
1160+
|p| p.parse_expr());
11611161
ex = expr_vec(~[first_expr] + remaining_exprs, mutbl);
11621162
} else {
11631163
// Vector with one element.
@@ -1419,7 +1419,7 @@ pub impl Parser {
14191419
vec::append(
14201420
self.parse_seq_to_before_end(
14211421
ket, seq_sep_none(),
1422-
|p| p.parse_token_tree()).to_vec(),
1422+
|p| p.parse_token_tree()),
14231423
// the close delimiter:
14241424
~[parse_any_tt_tok(self)])))
14251425
}
@@ -2727,7 +2727,7 @@ pub impl Parser {
27272727
let result = self.parse_seq_to_gt(
27282728
Some(token::COMMA),
27292729
|p| p.parse_ty(false));
2730-
result.to_vec()
2730+
opt_vec::take_vec(result)
27312731
}
27322732

27332733
fn parse_fn_decl(parse_arg_fn: fn(Parser) -> arg_or_capture_item)
@@ -2819,7 +2819,7 @@ pub impl Parser {
28192819
args_or_capture_items =
28202820
self.parse_seq_to_before_end(token::RPAREN,
28212821
sep,
2822-
parse_arg_fn).to_vec();
2822+
parse_arg_fn);
28232823
}
28242824
token::RPAREN => {
28252825
args_or_capture_items = ~[];
@@ -2835,7 +2835,7 @@ pub impl Parser {
28352835
args_or_capture_items =
28362836
self.parse_seq_to_before_end(token::RPAREN,
28372837
sep,
2838-
parse_arg_fn).to_vec();
2838+
parse_arg_fn);
28392839
}
28402840

28412841
self.expect(token::RPAREN);
@@ -3032,7 +3032,7 @@ pub impl Parser {
30323032
fn parse_trait_ref_list(ket: token::Token) -> ~[@trait_ref] {
30333033
self.parse_seq_to_before_end(
30343034
ket, seq_sep_none(),
3035-
|p| p.parse_trait_ref()).to_vec()
3035+
|p| p.parse_trait_ref())
30363036
}
30373037

30383038
fn parse_item_struct() -> item_info {

0 commit comments

Comments
 (0)