mirror of
https://github.com/servo/servo.git
synced 2025-08-05 05:30:08 +01:00
Unreverse declarations in memory.
This commit is contained in:
parent
31864954ed
commit
477cae67df
4 changed files with 29 additions and 25 deletions
|
@ -788,7 +788,7 @@ impl Element {
|
||||||
// than that.
|
// than that.
|
||||||
let existing_declarations = Arc::make_mut(existing_declarations);
|
let existing_declarations = Arc::make_mut(existing_declarations);
|
||||||
|
|
||||||
while let Some(mut incoming_declaration) = declarations.pop() {
|
for mut incoming_declaration in declarations {
|
||||||
let mut replaced = false;
|
let mut replaced = false;
|
||||||
for existing_declaration in &mut *existing_declarations {
|
for existing_declaration in &mut *existing_declarations {
|
||||||
if existing_declaration.name() == incoming_declaration.name() {
|
if existing_declaration.name() == incoming_declaration.name() {
|
||||||
|
@ -799,8 +799,7 @@ impl Element {
|
||||||
}
|
}
|
||||||
|
|
||||||
if !replaced {
|
if !replaced {
|
||||||
// inserting instead of pushing since the declarations are in reverse order
|
existing_declarations.push(incoming_declaration);
|
||||||
existing_declarations.insert(0, incoming_declaration);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,7 @@ use std::ascii::AsciiExt;
|
||||||
use std::boxed::Box as StdBox;
|
use std::boxed::Box as StdBox;
|
||||||
use std::collections::HashSet;
|
use std::collections::HashSet;
|
||||||
use std::fmt::{self, Write};
|
use std::fmt::{self, Write};
|
||||||
use std::iter::{Iterator, Chain, Zip, Rev, Repeat, repeat};
|
use std::iter::{Iterator, Chain, Zip, Repeat, repeat};
|
||||||
use std::slice;
|
use std::slice;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
@ -296,12 +296,11 @@ pub struct PropertyDeclarationBlock {
|
||||||
impl PropertyDeclarationBlock {
|
impl PropertyDeclarationBlock {
|
||||||
/// Provides an iterator of all declarations, with indication of !important value
|
/// Provides an iterator of all declarations, with indication of !important value
|
||||||
pub fn declarations(&self) -> Chain<
|
pub fn declarations(&self) -> Chain<
|
||||||
Zip<Rev<slice::Iter<PropertyDeclaration>>, Repeat<Importance>>,
|
Zip<slice::Iter<PropertyDeclaration>, Repeat<Importance>>,
|
||||||
Zip<Rev<slice::Iter<PropertyDeclaration>>, Repeat<Importance>>
|
Zip<slice::Iter<PropertyDeclaration>, Repeat<Importance>>
|
||||||
> {
|
> {
|
||||||
// Declarations are stored in reverse order.
|
let normal = self.normal.iter().zip(repeat(Importance::Normal));
|
||||||
let normal = self.normal.iter().rev().zip(repeat(Importance::Normal));
|
let important = self.important.iter().zip(repeat(Importance::Important));
|
||||||
let important = self.important.iter().rev().zip(repeat(Importance::Important));
|
|
||||||
normal.chain(important)
|
normal.chain(important)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -589,7 +588,7 @@ pub fn parse_property_declaration_list(context: &ParserContext, input: &mut Pars
|
||||||
|
|
||||||
|
|
||||||
/// Only keep the last declaration for any given property.
|
/// Only keep the last declaration for any given property.
|
||||||
/// The input is in source order, output in reverse source order.
|
/// The input and output are in source order
|
||||||
fn deduplicate_property_declarations(declarations: Vec<PropertyDeclaration>)
|
fn deduplicate_property_declarations(declarations: Vec<PropertyDeclaration>)
|
||||||
-> Vec<PropertyDeclaration> {
|
-> Vec<PropertyDeclaration> {
|
||||||
let mut deduplicated = vec![];
|
let mut deduplicated = vec![];
|
||||||
|
@ -618,6 +617,7 @@ fn deduplicate_property_declarations(declarations: Vec<PropertyDeclaration>)
|
||||||
}
|
}
|
||||||
deduplicated.push(declaration)
|
deduplicated.push(declaration)
|
||||||
}
|
}
|
||||||
|
deduplicated.reverse();
|
||||||
deduplicated
|
deduplicated
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1683,8 +1683,7 @@ fn cascade_with_cached_declarations(
|
||||||
// Declaration blocks are stored in increasing precedence order,
|
// Declaration blocks are stored in increasing precedence order,
|
||||||
// we want them in decreasing order here.
|
// we want them in decreasing order here.
|
||||||
for sub_list in applicable_declarations.iter().rev() {
|
for sub_list in applicable_declarations.iter().rev() {
|
||||||
// Declarations are already stored in reverse order.
|
for declaration in sub_list.declarations.iter().rev() {
|
||||||
for declaration in sub_list.declarations.iter() {
|
|
||||||
match *declaration {
|
match *declaration {
|
||||||
% for style_struct in data.active_style_structs():
|
% for style_struct in data.active_style_structs():
|
||||||
% for property in style_struct.longhands:
|
% for property in style_struct.longhands:
|
||||||
|
@ -1815,8 +1814,7 @@ pub fn cascade(viewport_size: Size2D<Au>,
|
||||||
let mut custom_properties = None;
|
let mut custom_properties = None;
|
||||||
let mut seen_custom = HashSet::new();
|
let mut seen_custom = HashSet::new();
|
||||||
for sub_list in applicable_declarations.iter().rev() {
|
for sub_list in applicable_declarations.iter().rev() {
|
||||||
// Declarations are already stored in reverse order.
|
for declaration in sub_list.declarations.iter().rev() {
|
||||||
for declaration in sub_list.declarations.iter() {
|
|
||||||
match *declaration {
|
match *declaration {
|
||||||
PropertyDeclaration::Custom(ref name, ref value) => {
|
PropertyDeclaration::Custom(ref name, ref value) => {
|
||||||
::custom_properties::cascade(
|
::custom_properties::cascade(
|
||||||
|
@ -1874,8 +1872,7 @@ pub fn cascade(viewport_size: Size2D<Au>,
|
||||||
ComputedValues::do_cascade_property(|cascade_property| {
|
ComputedValues::do_cascade_property(|cascade_property| {
|
||||||
% for category_to_cascade_now in ["early", "other"]:
|
% for category_to_cascade_now in ["early", "other"]:
|
||||||
for sub_list in applicable_declarations.iter().rev() {
|
for sub_list in applicable_declarations.iter().rev() {
|
||||||
// Declarations are already stored in reverse order.
|
for declaration in sub_list.declarations.iter().rev() {
|
||||||
for declaration in sub_list.declarations.iter() {
|
|
||||||
if let PropertyDeclaration::Custom(..) = *declaration {
|
if let PropertyDeclaration::Custom(..) = *declaration {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,8 +39,6 @@ fn property_declaration_block_should_serialize_correctly() {
|
||||||
let height = DeclaredValue::Value(LengthOrPercentageOrAuto::Length(Length::from_px(20f32)));
|
let height = DeclaredValue::Value(LengthOrPercentageOrAuto::Length(Length::from_px(20f32)));
|
||||||
important.push(PropertyDeclaration::Height(height));
|
important.push(PropertyDeclaration::Height(height));
|
||||||
|
|
||||||
normal.reverse();
|
|
||||||
important.reverse();
|
|
||||||
let block = PropertyDeclarationBlock {
|
let block = PropertyDeclarationBlock {
|
||||||
normal: Arc::new(normal),
|
normal: Arc::new(normal),
|
||||||
important: Arc::new(important)
|
important: Arc::new(important)
|
||||||
|
|
|
@ -39,6 +39,16 @@ fn test_parse_stylesheet() {
|
||||||
let stylesheet = Stylesheet::from_str(css, url, Origin::UserAgent,
|
let stylesheet = Stylesheet::from_str(css, url, Origin::UserAgent,
|
||||||
Box::new(CSSErrorReporterTest),
|
Box::new(CSSErrorReporterTest),
|
||||||
ParserContextExtraData::default());
|
ParserContextExtraData::default());
|
||||||
|
macro_rules! assert_eq {
|
||||||
|
($left: expr, $right: expr) => {
|
||||||
|
let left = $left;
|
||||||
|
let right = $right;
|
||||||
|
if left != right {
|
||||||
|
panic!("{:#?} != {:#?}", left, right)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
assert_eq!(stylesheet, Stylesheet {
|
assert_eq!(stylesheet, Stylesheet {
|
||||||
origin: Origin::UserAgent,
|
origin: Origin::UserAgent,
|
||||||
media: None,
|
media: None,
|
||||||
|
@ -157,13 +167,6 @@ fn test_parse_stylesheet() {
|
||||||
],
|
],
|
||||||
declarations: PropertyDeclarationBlock {
|
declarations: PropertyDeclarationBlock {
|
||||||
normal: Arc::new(vec![
|
normal: Arc::new(vec![
|
||||||
PropertyDeclaration::BackgroundClip(DeclaredValue::Initial),
|
|
||||||
PropertyDeclaration::BackgroundOrigin(DeclaredValue::Initial),
|
|
||||||
PropertyDeclaration::BackgroundSize(DeclaredValue::Initial),
|
|
||||||
PropertyDeclaration::BackgroundImage(DeclaredValue::Initial),
|
|
||||||
PropertyDeclaration::BackgroundAttachment(DeclaredValue::Initial),
|
|
||||||
PropertyDeclaration::BackgroundRepeat(DeclaredValue::Initial),
|
|
||||||
PropertyDeclaration::BackgroundPosition(DeclaredValue::Initial),
|
|
||||||
PropertyDeclaration::BackgroundColor(DeclaredValue::Value(
|
PropertyDeclaration::BackgroundColor(DeclaredValue::Value(
|
||||||
longhands::background_color::SpecifiedValue {
|
longhands::background_color::SpecifiedValue {
|
||||||
authored: Some("blue".to_owned()),
|
authored: Some("blue".to_owned()),
|
||||||
|
@ -172,6 +175,13 @@ fn test_parse_stylesheet() {
|
||||||
}),
|
}),
|
||||||
}
|
}
|
||||||
)),
|
)),
|
||||||
|
PropertyDeclaration::BackgroundPosition(DeclaredValue::Initial),
|
||||||
|
PropertyDeclaration::BackgroundRepeat(DeclaredValue::Initial),
|
||||||
|
PropertyDeclaration::BackgroundAttachment(DeclaredValue::Initial),
|
||||||
|
PropertyDeclaration::BackgroundImage(DeclaredValue::Initial),
|
||||||
|
PropertyDeclaration::BackgroundSize(DeclaredValue::Initial),
|
||||||
|
PropertyDeclaration::BackgroundOrigin(DeclaredValue::Initial),
|
||||||
|
PropertyDeclaration::BackgroundClip(DeclaredValue::Initial),
|
||||||
]),
|
]),
|
||||||
important: Arc::new(vec![]),
|
important: Arc::new(vec![]),
|
||||||
},
|
},
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue