Skip to content

Commit 2ec00aa

Browse files
author
bors-servo
authored
Auto merge of #186 - servo:smolvec, r=emilio
Use a SmallVec instead of Vec in consume_until_end_of_block … to avoid allocating in common cases. <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/rust-cssparser/186) <!-- Reviewable:end -->
2 parents acac1ce + e9fc22e commit 2ec00aa

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;
@@ -860,7 +861,8 @@ pub fn parse_nested_block<'i: 't, 't, F, T, E>(parser: &mut Parser<'i, 't>, pars
860861
}
861862

862863
fn consume_until_end_of_block(block_type: BlockType, tokenizer: &mut Tokenizer) {
863-
let mut stack = vec![block_type];
864+
let mut stack = SmallVec::<[BlockType; 16]>::new();
865+
stack.push(block_type);
864866

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

0 commit comments

Comments
 (0)