diff --git a/components/style/properties/gecko.mako.rs b/components/style/properties/gecko.mako.rs index 1b8a373afcc..9d6b0b9ea65 100644 --- a/components/style/properties/gecko.mako.rs +++ b/components/style/properties/gecko.mako.rs @@ -1469,7 +1469,7 @@ fn static_assert() { &mut ${self_grid}.mRepeatAutoLineNameListAfter, 0); } }, - GridTemplateComponent::Subgrid(mut list) => { + GridTemplateComponent::Subgrid(list) => { ${self_grid}.set_mIsSubgrid(true); let names_length = match list.fill_idx { Some(_) => list.names.len() - 1, @@ -1486,14 +1486,15 @@ fn static_assert() { &mut ${self_grid}.mRepeatAutoLineNameListAfter, 0); } + let mut names = list.names.into_vec(); if let Some(idx) = list.fill_idx { ${self_grid}.set_mIsAutoFill(true); ${self_grid}.mRepeatAutoIndex = idx as i16; - set_line_names(&list.names.swap_remove(idx as usize), + set_line_names(&names.swap_remove(idx as usize), &mut ${self_grid}.mRepeatAutoLineNameListBefore); } - for (servo_names, gecko_names) in list.names.iter().zip(${self_grid}.mLineNameLists.iter_mut()) { + for (servo_names, gecko_names) in names.iter().zip(${self_grid}.mLineNameLists.iter_mut()) { set_line_names(servo_names, gecko_names); } }, diff --git a/components/style/properties/shorthand/position.mako.rs b/components/style/properties/shorthand/position.mako.rs index 9acc385b0aa..46d27aa3691 100644 --- a/components/style/properties/shorthand/position.mako.rs +++ b/components/style/properties/shorthand/position.mako.rs @@ -278,34 +278,35 @@ } % endfor - let first_line_names = input.try(parse_line_names).unwrap_or(vec![]); + let first_line_names = input.try(parse_line_names).unwrap_or(vec![].into_boxed_slice()); if let Ok(s) = input.try(Parser::expect_string) { let mut strings = vec![]; let mut values = vec![]; let mut line_names = vec![]; - let mut names = first_line_names; + let mut names = first_line_names.into_vec(); let mut string = s.into_owned().into_boxed_str(); loop { - line_names.push(names); + line_names.push(names.into_boxed_slice()); strings.push(string); let size = input.try(|i| TrackSize::parse(context, i)).unwrap_or_default(); values.push(size); - names = input.try(parse_line_names).unwrap_or(vec![]); + names = input.try(parse_line_names).unwrap_or(vec![].into_boxed_slice()).into_vec(); if let Ok(v) = input.try(parse_line_names) { - names.extend(v); + names.extend(v.into_vec()); } string = match input.try(Parser::expect_string) { Ok(s) => s.into_owned().into_boxed_str(), _ => { // only the named area determines whether we should bail out - line_names.push(names); + line_names.push(names.into_boxed_slice()); break }, }; } if line_names.len() == values.len() { - line_names.push(vec![]); // should be one longer than track sizes + // should be one longer than track sizes + line_names.push(vec![].into_boxed_slice()); } let template_areas = TemplateAreas::from_vec(strings) @@ -313,7 +314,7 @@ let template_rows = TrackList { list_type: TrackListType::Normal, values: values, - line_names: line_names, + line_names: line_names.into_boxed_slice(), auto_repeat: None, }; diff --git a/components/style/values/generics/grid.rs b/components/style/values/generics/grid.rs index 83b96199a84..5c98d5c33dc 100644 --- a/components/style/values/generics/grid.rs +++ b/components/style/values/generics/grid.rs @@ -386,7 +386,7 @@ pub struct TrackRepeat { /// If there's no ``, then it's represented by an empty vector. /// For N `` values, there will be N+1 ``, and so this vector's /// length is always one value more than that of the ``. - pub line_names: Vec>, + pub line_names: Box<[Box<[CustomIdent]>]>, /// `` values. pub track_sizes: Vec>, } @@ -447,7 +447,8 @@ impl TrackRepeat { let mut names_iter = self.line_names.iter(); for (size, names) in self.track_sizes.iter().zip(&mut names_iter) { prev_names.extend_from_slice(&names); - line_names.push(mem::replace(&mut prev_names, vec![])); + let vec = mem::replace(&mut prev_names, vec![]); + line_names.push(vec.into_boxed_slice()); track_sizes.push(size.clone()); } @@ -456,11 +457,11 @@ impl TrackRepeat { } } - line_names.push(prev_names); + line_names.push(prev_names.into_boxed_slice()); TrackRepeat { count: self.count, track_sizes: track_sizes, - line_names: line_names, + line_names: line_names.into_boxed_slice(), } } else { // if it's auto-fit/auto-fill, then it's left to the layout. @@ -541,7 +542,7 @@ pub struct TrackList { /// If there's no ``, then it's represented by an empty vector. /// For N values, there will be N+1 ``, and so this vector's /// length is always one value more than that of the ``. - pub line_names: Vec>, + pub line_names: Box<[Box<[CustomIdent]>]>, /// `` value. There can only be one `` in a TrackList. pub auto_repeat: Option>, } @@ -598,7 +599,7 @@ impl ToCss for TrackList { #[cfg_attr(feature = "servo", derive(HeapSizeOf))] pub struct LineNameList { /// The optional `` - pub names: Vec>, + pub names: Box<[Box<[CustomIdent]>]>, /// Indicates the line name that requires `auto-fill` pub fill_idx: Option, } @@ -650,7 +651,7 @@ impl Parse for LineNameList { } Ok(LineNameList { - names: line_names, + names: line_names.into_boxed_slice(), fill_idx: fill_idx, }) } diff --git a/components/style/values/specified/grid.rs b/components/style/values/specified/grid.rs index 0f1769ee1d1..9b847626b17 100644 --- a/components/style/values/specified/grid.rs +++ b/components/style/values/specified/grid.rs @@ -81,7 +81,7 @@ impl Parse for TrackSize { /// Parse the grid line names into a vector of owned strings. /// /// https://drafts.csswg.org/css-grid/#typedef-line-names -pub fn parse_line_names<'i, 't>(input: &mut Parser<'i, 't>) -> Result, ParseError<'i>> { +pub fn parse_line_names<'i, 't>(input: &mut Parser<'i, 't>) -> Result, ParseError<'i>> { input.expect_square_bracket_block()?; input.parse_nested_block(|input| { let mut values = vec![]; @@ -90,7 +90,7 @@ pub fn parse_line_names<'i, 't>(input: &mut Parser<'i, 't>) -> Result { let mut current_names; loop { - current_names = input.try(parse_line_names).unwrap_or(vec![]); + current_names = input.try(parse_line_names).unwrap_or(vec![].into_boxed_slice()); if let Ok(track_size) = input.try(|i| TrackSize::parse(context, i)) { if !track_size.is_fixed() { if is_auto { @@ -150,7 +150,7 @@ impl TrackRepeat { // one `TrackSize`. But in current version of the spec, this is deprecated // but we are adding this for gecko parity. We should remove this when // gecko implements new spec. - names.push(input.try(parse_line_names).unwrap_or(vec![])); + names.push(input.try(parse_line_names).unwrap_or(vec![].into_boxed_slice())); break } } else { @@ -167,7 +167,7 @@ impl TrackRepeat { let repeat = TrackRepeat { count: count, track_sizes: values, - line_names: names, + line_names: names.into_boxed_slice(), }; Ok((repeat, repeat_type)) @@ -205,7 +205,7 @@ impl Parse for TrackList { let mut atleast_one_not_fixed = false; loop { - current_names.append(&mut input.try(parse_line_names).unwrap_or(vec![])); + current_names.extend_from_slice(&mut input.try(parse_line_names).unwrap_or(vec![].into_boxed_slice())); if let Ok(track_size) = input.try(|i| TrackSize::parse(context, i)) { if !track_size.is_fixed() { atleast_one_not_fixed = true; @@ -215,7 +215,8 @@ impl Parse for TrackList { } } - names.push(mem::replace(&mut current_names, vec![])); + let vec = mem::replace(&mut current_names, vec![]); + names.push(vec.into_boxed_slice()); values.push(track_size); } else if let Ok((repeat, type_)) = input.try(|i| TrackRepeat::parse_with_repeat_type(context, i)) { if list_type == TrackListType::Explicit { @@ -237,7 +238,8 @@ impl Parse for TrackList { list_type = TrackListType::Auto(values.len() as u16); auto_repeat = Some(repeat); - names.push(mem::replace(&mut current_names, vec![])); + let vec = mem::replace(&mut current_names, vec![]); + names.push(vec.into_boxed_slice()); continue }, RepeatType::Fixed => (), @@ -245,10 +247,11 @@ impl Parse for TrackList { // If the repeat count is numeric, we axpand and merge the values. let mut repeat = repeat.expand(); - let mut repeat_names_iter = repeat.line_names.drain(..); + let mut repeat_names_iter = repeat.line_names.iter(); for (size, repeat_names) in repeat.track_sizes.drain(..).zip(&mut repeat_names_iter) { current_names.extend_from_slice(&repeat_names); - names.push(mem::replace(&mut current_names, vec![])); + let vec = mem::replace(&mut current_names, vec![]); + names.push(vec.into_boxed_slice()); values.push(size); } @@ -260,7 +263,7 @@ impl Parse for TrackList { return Err(StyleParseError::UnspecifiedError.into()) } - names.push(current_names); + names.push(current_names.into_boxed_slice()); break } } @@ -268,7 +271,7 @@ impl Parse for TrackList { Ok(TrackList { list_type: list_type, values: values, - line_names: names, + line_names: names.into_boxed_slice(), auto_repeat: auto_repeat, }) }