diff --git a/Cargo.toml b/Cargo.toml index c409bac9..7d1e6a5c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "cssparser" -version = "0.20.1" +version = "0.20.2" authors = [ "Simon Sapin " ] description = "Rust implementation of CSS Syntax Level 3" diff --git a/src/parser.rs b/src/parser.rs index 93a40a62..4887becd 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -478,7 +478,11 @@ impl<'i: 't, 't> Parser<'i, 't> { #[inline] pub fn parse_comma_separated(&mut self, mut parse_one: F) -> Result, ParseError<'i, E>> where F: for<'tt> FnMut(&mut Parser<'i, 'tt>) -> Result> { - let mut values = vec![]; + // Vec grows from 0 to 4 by default on first push(). So allocate with + // capacity 1, so in the somewhat common case of only one item we don't + // way overallocate. Note that we always push at least one item if + // parsing succeeds. + let mut values = Vec::with_capacity(1); loop { self.skip_whitespace(); // Unnecessary for correctness, but may help try() in parse_one rewind less. values.push(self.parse_until_before(Delimiter::Comma, &mut parse_one)?);