Skip to content

Commit

Permalink
Prevent some vector reallocations
Browse files Browse the repository at this point in the history
  • Loading branch information
brendanzab committed Oct 25, 2014
1 parent ec3f020 commit 6a50b4d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
9 changes: 4 additions & 5 deletions src/libsyntax/ext/quote.rs
Expand Up @@ -652,11 +652,10 @@ fn mk_tt(cx: &ExtCtxt, _: Span, tt: &ast::TokenTree) -> Vec<P<ast::Stmt>> {
vec!(cx.stmt_expr(e_push))
},
ast::TTDelimited(sp, ref open, ref tts, ref close) => {
let mut stmts = vec![];
stmts.extend(mk_tt(cx, sp, &open.to_tt()).into_iter());
stmts.extend(tts.iter().flat_map(|tt| mk_tt(cx, sp, tt).into_iter()));
stmts.extend(mk_tt(cx, sp, &close.to_tt()).into_iter());
stmts
mk_tt(cx, sp, &open.to_tt()).into_iter()
.chain(tts.iter().flat_map(|tt| mk_tt(cx, sp, tt).into_iter()))
.chain(mk_tt(cx, sp, &close.to_tt()).into_iter())
.collect()
},
ast::TTSequence(..) => fail!("TTSequence in quote!"),
ast::TTNonterminal(sp, ident) => {
Expand Down
12 changes: 6 additions & 6 deletions src/libsyntax/ext/tt/transcribe.rs
Expand Up @@ -202,14 +202,14 @@ pub fn tt_next_token(r: &mut TtReader) -> TokenAndSpan {
(*frame.forest)[frame.idx].clone()
};
match t {
TTDelimited(_, open, delimed_tts, close) => {
let mut tts = vec![];
tts.push(open.to_tt());
tts.extend(delimed_tts.iter().map(|x| (*x).clone()));
tts.push(close.to_tt());
TTDelimited(_, open, tts, close) => {
let mut forest = Vec::with_capacity(1 + tts.len() + 1);
forest.push(open.to_tt());
forest.extend(tts.iter().map(|x| (*x).clone()));
forest.push(close.to_tt());

r.stack.push(TtFrame {
forest: Rc::new(tts),
forest: Rc::new(forest),
idx: 0,
dotdotdoted: false,
sep: None
Expand Down

0 comments on commit 6a50b4d

Please sign in to comment.