Skip to content

Commit e9fc22e

Browse files
committed
Use a SmallVec instead of Vec in consume_until_end_of_block
… to avoid allocating in common cases.
1 parent a161e1f commit e9fc22e

File tree

3 files changed

+5
-1
lines changed

3 files changed

+5
-1
lines changed

Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ matches = "0.1"
2626
phf = "0.7"
2727
procedural-masquerade = {path = "./procedural-masquerade", version = "0.1"}
2828
serde = {version = "1.0", optional = true}
29+
smallvec = "0.4.3"
2930

3031
[build-dependencies]
3132
syn = "0.11"

src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ extern crate dtoa_short;
7878
#[cfg(test)] extern crate rustc_serialize;
7979
#[cfg(feature = "serde")] extern crate serde;
8080
#[cfg(feature = "heapsize")] #[macro_use] extern crate heapsize;
81+
extern crate smallvec;
8182

8283
pub use cssparser_macros::*;
8384

src/parser.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
44

55
use cow_rc_str::CowRcStr;
6+
use smallvec::SmallVec;
67
use std::ops::Range;
78
use std::ascii::AsciiExt;
89
use std::ops::BitOr;
@@ -858,7 +859,8 @@ pub fn parse_nested_block<'i: 't, 't, F, T, E>(parser: &mut Parser<'i, 't>, pars
858859
}
859860

860861
fn consume_until_end_of_block(block_type: BlockType, tokenizer: &mut Tokenizer) {
861-
let mut stack = vec![block_type];
862+
let mut stack = SmallVec::<[BlockType; 16]>::new();
863+
stack.push(block_type);
862864

863865
// FIXME: have a special-purpose tokenizer method for this that does less work.
864866
while let Ok(ref token) = tokenizer.next() {

0 commit comments

Comments
 (0)