Skip to content

Commit

Permalink
Use SmallVector for the stack in macro_parser::parse.
Browse files Browse the repository at this point in the history
This avoids 800,000 heap allocations when compiling html5ever.
  • Loading branch information
nnethercote committed Oct 25, 2016
1 parent 1e5dab1 commit 0a16a11
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions src/libsyntax/ext/tt/macro_parser.rs
Expand Up @@ -92,6 +92,7 @@ use parse::token;
use print::pprust;
use ptr::P;
use tokenstream::{self, TokenTree};
use util::small_vector::SmallVector;

use std::mem;
use std::rc::Rc;
Expand Down Expand Up @@ -284,12 +285,9 @@ pub fn parse(sess: &ParseSess,
mut rdr: TtReader,
ms: &[TokenTree])
-> NamedParseResult {
let mut cur_eis = Vec::new();
cur_eis.push(initial_matcher_pos(Rc::new(ms.iter()
.cloned()
.collect()),
None,
rdr.peek().sp.lo));
let mut cur_eis = SmallVector::one(initial_matcher_pos(Rc::new(ms.to_owned()),
None,
rdr.peek().sp.lo));

loop {
let mut bb_eis = Vec::new(); // black-box parsed by parser.rs
Expand Down

0 comments on commit 0a16a11

Please sign in to comment.