mirror of
https://github.com/servo/servo.git
synced 2025-08-05 05:30:08 +01:00
Avoid array overallocation when parsing background shorthand. r=xidorn
This is part 2 of the fix for Gecko bug 1397614 <https://bugzilla.mozilla.org/show_bug.cgi?id=1397614>
This commit is contained in:
parent
26b39241f9
commit
385e34acee
2 changed files with 22 additions and 6 deletions
|
@ -37,7 +37,11 @@
|
||||||
let mut background_color = None;
|
let mut background_color = None;
|
||||||
|
|
||||||
% for name in "image position_x position_y repeat size attachment origin clip".split():
|
% for name in "image position_x position_y repeat size attachment origin clip".split():
|
||||||
let mut background_${name} = background_${name}::SpecifiedValue(Vec::new());
|
// Vec grows from 0 to 4 by default on first push(). So allocate
|
||||||
|
// with capacity 1, so in the 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 background_${name} = background_${name}::SpecifiedValue(Vec::with_capacity(1));
|
||||||
% endfor
|
% endfor
|
||||||
input.parse_comma_separated(|input| {
|
input.parse_comma_separated(|input| {
|
||||||
// background-color can only be in the last element, so if it
|
// background-color can only be in the last element, so if it
|
||||||
|
@ -197,8 +201,12 @@
|
||||||
|
|
||||||
pub fn parse_value<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>)
|
pub fn parse_value<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>)
|
||||||
-> Result<Longhands, ParseError<'i>> {
|
-> Result<Longhands, ParseError<'i>> {
|
||||||
let mut position_x = background_position_x::SpecifiedValue(Vec::new());
|
// Vec grows from 0 to 4 by default on first push(). So allocate with
|
||||||
let mut position_y = background_position_y::SpecifiedValue(Vec::new());
|
// capacity 1, so in the 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 position_x = background_position_x::SpecifiedValue(Vec::with_capacity(1));
|
||||||
|
let mut position_y = background_position_y::SpecifiedValue(Vec::with_capacity(1));
|
||||||
let mut any = false;
|
let mut any = false;
|
||||||
|
|
||||||
input.parse_comma_separated(|input| {
|
input.parse_comma_separated(|input| {
|
||||||
|
|
|
@ -38,7 +38,11 @@
|
||||||
pub fn parse_value<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>)
|
pub fn parse_value<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>)
|
||||||
-> Result<Longhands, ParseError<'i>> {
|
-> Result<Longhands, ParseError<'i>> {
|
||||||
% for name in "image mode position_x position_y size repeat origin clip composite".split():
|
% for name in "image mode position_x position_y size repeat origin clip composite".split():
|
||||||
let mut mask_${name} = mask_${name}::SpecifiedValue(Vec::new());
|
// Vec grows from 0 to 4 by default on first push(). So allocate
|
||||||
|
// with capacity 1, so in the 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 mask_${name} = mask_${name}::SpecifiedValue(Vec::with_capacity(1));
|
||||||
% endfor
|
% endfor
|
||||||
|
|
||||||
input.parse_comma_separated(|input| {
|
input.parse_comma_separated(|input| {
|
||||||
|
@ -183,8 +187,12 @@
|
||||||
|
|
||||||
pub fn parse_value<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>)
|
pub fn parse_value<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>)
|
||||||
-> Result<Longhands, ParseError<'i>> {
|
-> Result<Longhands, ParseError<'i>> {
|
||||||
let mut position_x = mask_position_x::SpecifiedValue(Vec::new());
|
// Vec grows from 0 to 4 by default on first push(). So allocate with
|
||||||
let mut position_y = mask_position_y::SpecifiedValue(Vec::new());
|
// capacity 1, so in the 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 position_x = mask_position_x::SpecifiedValue(Vec::with_capacity(1));
|
||||||
|
let mut position_y = mask_position_y::SpecifiedValue(Vec::with_capacity(1));
|
||||||
let mut any = false;
|
let mut any = false;
|
||||||
|
|
||||||
input.parse_comma_separated(|input| {
|
input.parse_comma_separated(|input| {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue