From 4e858f2a874e95d1669a968d4dc67777f6ef1746 Mon Sep 17 00:00:00 2001 From: Marco Castelluccio Date: Tue, 1 Oct 2019 00:38:20 +0000 Subject: [PATCH] servo: Merge #13459 - Use parking_lot::RwLock for PropertyDeclarationBlock (from servo:no-arc-heapsize); r=emilio As discussed in https://bugzilla.mozilla.org/show_bug.cgi?id=1305141 Closes #13176 --- Original PR title: Stop relying on `impl HeapSizeOf for Arc` https://github.com/servo/heapsize/issues/37#issuecomment-249861171 This builds on top of that. --- - [x] `./mach build -d` does not report any errors - [x] `./mach test-tidy` does not report any errors - [ ] These changes fix #__ (github issue number if applicable). - [ ] There are tests for these changes OR - [x] These changes do not require tests because refactor Source-Repo: https://github.com/servo/servo Source-Revision: aea9545e16fd6ea4a6b1234d1b969457313a5fa7 UltraBlame original commit: 0e74d9fe18cf1cbbab7d7410027a051f94eac90f --- servo/components/layout/Cargo.toml | 2 +- .../plugins/lints/unrooted_must_root.rs | 2 - servo/components/script/Cargo.toml | 3 +- servo/components/script/body.rs | 2 +- servo/components/script/dom/attr.rs | 2 +- .../dom/bindings/cell.rs} | 7 +- servo/components/script/dom/bindings/mod.rs | 3 +- servo/components/script/dom/bindings/trace.rs | 2 +- servo/components/script/dom/characterdata.rs | 2 +- .../script/dom/cssstyledeclaration.rs | 70 ++++++++++--------- servo/components/script/dom/document.rs | 20 ++++-- .../script/dom/dommatrixreadonly.rs | 3 +- servo/components/script/dom/element.rs | 60 ++++++++-------- .../components/script/dom/htmlimageelement.rs | 1 + .../components/script/dom/htmllinkelement.rs | 1 + .../components/script/dom/htmlmetaelement.rs | 1 + .../script/dom/htmlobjectelement.rs | 1 + .../components/script/dom/htmlstyleelement.rs | 1 + servo/components/script/dom/request.rs | 3 +- servo/components/script/dom/response.rs | 2 +- .../script/dom/workerglobalscope.rs | 1 + servo/components/script/layout_wrapper.rs | 3 +- servo/components/script/lib.rs | 2 + .../script_layout_interface/Cargo.toml | 2 +- servo/components/servo/Cargo.lock | 58 +++++++-------- servo/components/style/Cargo.toml | 4 +- servo/components/style/animation.rs | 2 +- servo/components/style/dom.rs | 3 +- servo/components/style/gecko/wrapper.rs | 5 +- servo/components/style/keyframes.rs | 34 +++++---- servo/components/style/lib.rs | 1 - servo/components/style/matching.rs | 13 +++- .../style/properties/properties.mako.rs | 45 +++++++----- servo/components/style/refcell.rs | 20 ------ servo/components/style/restyle_hints.rs | 1 + servo/components/style/selector_matching.rs | 49 +++++++++---- servo/components/style/stylesheets.rs | 20 +++--- servo/ports/cef/Cargo.lock | 57 ++++++++------- servo/ports/geckolib/Cargo.lock | 15 ++-- servo/ports/geckolib/Cargo.toml | 1 + servo/ports/geckolib/glue.rs | 5 +- servo/ports/geckolib/lib.rs | 1 + servo/tests/unit/style/Cargo.toml | 3 +- servo/tests/unit/style/lib.rs | 1 + servo/tests/unit/style/selector_matching.rs | 7 +- servo/tests/unit/style/stylesheets.rs | 37 ++++------ 46 files changed, 313 insertions(+), 265 deletions(-) rename servo/components/{style/domrefcell.rs => script/dom/bindings/cell.rs} (92%) diff --git a/servo/components/layout/Cargo.toml b/servo/components/layout/Cargo.toml index 68289ce22030..b7007219e7d1 100644 --- a/servo/components/layout/Cargo.toml +++ b/servo/components/layout/Cargo.toml @@ -33,7 +33,7 @@ range = {path = "../range"} rustc-serialize = "0.3" script_layout_interface = {path = "../script_layout_interface"} script_traits = {path = "../script_traits"} -selectors = {version = "0.13", features = ["heap_size"]} +selectors = "0.13" serde_macros = "0.8" smallvec = "0.1" string_cache = {version = "0.2.26", features = ["heap_size"]} diff --git a/servo/components/plugins/lints/unrooted_must_root.rs b/servo/components/plugins/lints/unrooted_must_root.rs index 4b9ba776717a..11b91a70df30 100644 --- a/servo/components/plugins/lints/unrooted_must_root.rs +++ b/servo/components/plugins/lints/unrooted_must_root.rs @@ -51,8 +51,6 @@ fn is_unrooted_ty(cx: &LateContext, ty: &ty::TyS, in_new_function: bool) -> bool false } else if match_def_path(cx, did.did, &["core", "cell", "Ref"]) || match_def_path(cx, did.did, &["core", "cell", "RefMut"]) - || match_def_path(cx, did.did, &["style", "refcell", "Ref"]) - || match_def_path(cx, did.did, &["style", "refcell", "RefMut"]) || match_def_path(cx, did.did, &["core", "slice", "Iter"]) || match_def_path(cx, did.did, &["std", "collections", "hash", "map", "OccupiedEntry"]) || match_def_path(cx, did.did, &["std", "collections", "hash", "map", "VacantEntry"]) { diff --git a/servo/components/script/Cargo.toml b/servo/components/script/Cargo.toml index 626eb4e22884..14ea398964aa 100644 --- a/servo/components/script/Cargo.toml +++ b/servo/components/script/Cargo.toml @@ -51,6 +51,7 @@ net_traits = {path = "../net_traits"} num-traits = "0.1.32" offscreen_gl_context = "0.4" open = "1.1.1" +parking_lot = "0.3" phf = "0.7.16" phf_macros = "0.7.16" plugins = {path = "../plugins"} @@ -62,7 +63,7 @@ regex = "0.1.43" rustc-serialize = "0.3" script_layout_interface = {path = "../script_layout_interface"} script_traits = {path = "../script_traits"} -selectors = {version = "0.13", features = ["heap_size"]} +selectors = "0.13" serde = "0.8" smallvec = "0.1" string_cache = {version = "0.2.26", features = ["heap_size", "unstable"]} diff --git a/servo/components/script/body.rs b/servo/components/script/body.rs index a4f3ccdb4192..d054f84479e4 100644 --- a/servo/components/script/body.rs +++ b/servo/components/script/body.rs @@ -19,9 +19,9 @@ use js::jsapi::JS_ParseJSON; use js::jsapi::Value as JSValue; use js::jsval::UndefinedValue; use mime::{Mime, TopLevel, SubLevel}; +use std::cell::Ref; use std::rc::Rc; use std::str; -use style::refcell::Ref; use url::form_urlencoded; pub enum BodyType { diff --git a/servo/components/script/dom/attr.rs b/servo/components/script/dom/attr.rs index d07f96968609..0a34d7929d4b 100644 --- a/servo/components/script/dom/attr.rs +++ b/servo/components/script/dom/attr.rs @@ -15,10 +15,10 @@ use dom::element::{AttributeMutation, Element}; use dom::virtualmethods::vtable_for; use dom::window::Window; use std::borrow::ToOwned; +use std::cell::Ref; use std::mem; use string_cache::{Atom, Namespace}; use style::attr::{AttrIdentifier, AttrValue}; -use style::refcell::Ref; #[dom_struct] diff --git a/servo/components/style/domrefcell.rs b/servo/components/script/dom/bindings/cell.rs similarity index 92% rename from servo/components/style/domrefcell.rs rename to servo/components/script/dom/bindings/cell.rs index e678aec3bc5a..fdce078dbf1c 100644 --- a/servo/components/style/domrefcell.rs +++ b/servo/components/script/dom/bindings/cell.rs @@ -4,15 +4,14 @@ -use refcell::{BorrowError, BorrowMutError, Ref, RefCell, RefMut}; -use thread_state; +use std::cell::{BorrowError, BorrowMutError, Ref, RefCell, RefMut}; +use style::thread_state; -#[derive(Clone)] -#[cfg_attr(feature = "servo", derive(HeapSizeOf))] +#[derive(Clone, PartialEq, Debug, HeapSizeOf)] pub struct DOMRefCell { value: RefCell, } diff --git a/servo/components/script/dom/bindings/mod.rs b/servo/components/script/dom/bindings/mod.rs index c7a4469c8111..a59ba667ac3a 100644 --- a/servo/components/script/dom/bindings/mod.rs +++ b/servo/components/script/dom/bindings/mod.rs @@ -127,10 +127,9 @@ - -pub use style::domrefcell as cell; pub mod callback; +pub mod cell; pub mod constant; pub mod conversions; pub mod error; diff --git a/servo/components/script/dom/bindings/trace.rs b/servo/components/script/dom/bindings/trace.rs index 7606689ec510..056422cef09c 100644 --- a/servo/components/script/dom/bindings/trace.rs +++ b/servo/components/script/dom/bindings/trace.rs @@ -35,6 +35,7 @@ use cssparser::RGBA; use devtools_traits::CSSError; use devtools_traits::WorkerId; use dom::abstractworker::SharedRt; +use dom::bindings::cell::DOMRefCell; use dom::bindings::js::{JS, Root}; use dom::bindings::refcounted::{Trusted, TrustedPromise}; use dom::bindings::reflector::{Reflectable, Reflector}; @@ -89,7 +90,6 @@ use std::sync::mpsc::{Receiver, Sender}; use std::time::{SystemTime, Instant}; use string_cache::{Atom, Namespace, QualName}; use style::attr::{AttrIdentifier, AttrValue, LengthOrPercentageOrAuto}; -use style::domrefcell::DOMRefCell; use style::element_state::*; use style::properties::PropertyDeclarationBlock; use style::selector_impl::{ElementSnapshot, PseudoElement}; diff --git a/servo/components/script/dom/characterdata.rs b/servo/components/script/dom/characterdata.rs index af169afdb717..31532beabbc7 100644 --- a/servo/components/script/dom/characterdata.rs +++ b/servo/components/script/dom/characterdata.rs @@ -19,7 +19,7 @@ use dom::element::Element; use dom::node::{Node, NodeDamage}; use dom::processinginstruction::ProcessingInstruction; use dom::text::Text; -use style::refcell::Ref; +use std::cell::Ref; use util::opts; diff --git a/servo/components/script/dom/cssstyledeclaration.rs b/servo/components/script/dom/cssstyledeclaration.rs index b5b586b38108..c2a57ff0ee0e 100644 --- a/servo/components/script/dom/cssstyledeclaration.rs +++ b/servo/components/script/dom/cssstyledeclaration.rs @@ -13,14 +13,13 @@ use dom::bindings::str::DOMString; use dom::element::Element; use dom::node::{Node, NodeDamage, window_from_node}; use dom::window::Window; +use parking_lot::RwLock; use std::ascii::AsciiExt; -use std::slice; use std::sync::Arc; use string_cache::Atom; use style::parser::ParserContextExtraData; -use style::properties::{PropertyDeclaration, Shorthand, Importance}; +use style::properties::{Shorthand, Importance}; use style::properties::{is_supported_property, parse_one_declaration, parse_style_attribute}; -use style::refcell::Ref; use style::selector_impl::PseudoElement; @@ -93,7 +92,7 @@ impl CSSStyleDeclarationMethods for CSSStyleDeclaration { fn Length(&self) -> u32 { let elem = self.owner.upcast::(); let len = match *elem.style_attribute().borrow() { - Some(ref declarations) => declarations.declarations.len(), + Some(ref declarations) => declarations.read().declarations.len(), None => 0, }; len as u32 @@ -119,43 +118,42 @@ impl CSSStyleDeclarationMethods for CSSStyleDeclaration { // Step 2 if let Some(shorthand) = Shorthand::from_name(&property) { + let style_attribute = owner.style_attribute().borrow(); + let style_attribute = if let Some(ref style_attribute) = *style_attribute { + style_attribute.read() + } else { + // shorthand.longhands() is never empty, so with no style attribute + // step 2.2.2 would do this: + return DOMString::new() + }; + // Step 2.1 let mut list = vec![]; // Step 2.2 for longhand in shorthand.longhands() { // Step 2.2.1 - let declaration = owner.get_inline_style_declaration(&Atom::from(*longhand)); + let declaration = style_attribute.get(longhand); // Step 2.2.2 & 2.2.3 match declaration { - Some(declaration) => list.push(declaration), + Some(&(ref declaration, _importance)) => list.push(declaration), None => return DOMString::new(), } } // Step 2.3 - // Work around closures not being Clone - #[derive(Clone)] - struct Map<'a, 'b: 'a>(slice::Iter<'a, Ref<'b, (PropertyDeclaration, Importance)>>); - impl<'a, 'b> Iterator for Map<'a, 'b> { - type Item = &'a PropertyDeclaration; - fn next(&mut self) -> Option { - self.0.next().map(|r| &r.0) - } - } - // TODO: important is hardcoded to false because method does not implement it yet let serialized_value = shorthand.serialize_shorthand_value_to_string( - Map(list.iter()), Importance::Normal); + list, Importance::Normal); return DOMString::from(serialized_value); } // Step 3 & 4 - match owner.get_inline_style_declaration(&property) { + owner.get_inline_style_declaration(&property, |d| match d { Some(declaration) => DOMString::from(declaration.0.value()), None => DOMString::new(), - } + }) } // https://dev.w3.org/csswg/cssom/#dom-cssstyledeclaration-getpropertypriority @@ -172,13 +170,18 @@ impl CSSStyleDeclarationMethods for CSSStyleDeclaration { .all(|priority| priority == "important") { return DOMString::from("important"); } - // Step 3 } else { - if let Some(decl) = self.owner.get_inline_style_declaration(&property) { - if decl.1.important() { - return DOMString::from("important"); + // Step 3 + return self.owner.get_inline_style_declaration(&property, |d| { + if let Some(decl) = d { + if decl.1.important() { + return DOMString::from("important"); + } } - } + + // Step 4 + DOMString::new() + }) } // Step 4 @@ -328,13 +331,14 @@ impl CSSStyleDeclarationMethods for CSSStyleDeclaration { let elem = self.owner.upcast::(); let style_attribute = elem.style_attribute().borrow(); style_attribute.as_ref().and_then(|declarations| { - declarations.declarations.get(index) - }).map(|&(ref declaration, importance)| { - let mut css = declaration.to_css_string(); - if importance.important() { - css += " !important"; - } - DOMString::from(css) + declarations.read().declarations.get(index).map(|entry| { + let (ref declaration, importance) = *entry; + let mut css = declaration.to_css_string(); + if importance.important() { + css += " !important"; + } + DOMString::from(css) + }) }) } @@ -344,7 +348,7 @@ impl CSSStyleDeclarationMethods for CSSStyleDeclaration { let style_attribute = elem.style_attribute().borrow(); if let Some(declarations) = style_attribute.as_ref() { - DOMString::from(declarations.to_css_string()) + DOMString::from(declarations.read().to_css_string()) } else { DOMString::new() } @@ -366,7 +370,7 @@ impl CSSStyleDeclarationMethods for CSSStyleDeclaration { *element.style_attribute().borrow_mut() = if decl_block.declarations.is_empty() { None } else { - Some(Arc::new(decl_block)) + Some(Arc::new(RwLock::new(decl_block))) }; element.sync_property_with_attrs_style(); let node = element.upcast::(); diff --git a/servo/components/script/dom/document.rs b/servo/components/script/dom/document.rs index 1f8b6d76e2bd..63b1d96bb8bb 100644 --- a/servo/components/script/dom/document.rs +++ b/servo/components/script/dom/document.rs @@ -113,7 +113,7 @@ use script_traits::UntrustedNodeAddress; use std::ascii::AsciiExt; use std::borrow::ToOwned; use std::boxed::FnBox; -use std::cell::Cell; +use std::cell::{Cell, Ref, RefMut}; use std::collections::HashMap; use std::collections::hash_map::Entry::{Occupied, Vacant}; use std::default::Default; @@ -125,7 +125,6 @@ use std::time::{Duration, Instant}; use string_cache::{Atom, QualName}; use style::attr::AttrValue; use style::context::ReflowGoal; -use style::refcell::{Ref, RefMut}; use style::selector_impl::ElementSnapshot; use style::str::{split_html_space_chars, str_join}; use style::stylesheets::Stylesheet; @@ -146,6 +145,14 @@ enum ParserBlockedByScript { Unblocked, } +#[derive(JSTraceable, HeapSizeOf)] +#[must_root] +struct StylesheetInDocument { + node: JS, + #[ignore_heap_size_of = "Arc"] + stylesheet: Arc, +} + #[dom_struct] pub struct Document { @@ -174,7 +181,7 @@ pub struct Document { anchors: MutNullableHeap>, applets: MutNullableHeap>, - stylesheets: DOMRefCell, Arc)>>>, + stylesheets: DOMRefCell>>, stylesheets_changed_since_reflow: Cell, ready_state: Cell, @@ -1879,13 +1886,16 @@ impl Document { node.get_stylesheet() } else { None - }.map(|stylesheet| (JS::from_ref(&*node), stylesheet)) + }.map(|stylesheet| StylesheetInDocument { + node: JS::from_ref(&*node), + stylesheet: stylesheet + }) }) .collect()); }; } self.stylesheets.borrow().as_ref().unwrap().iter() - .map(|&(_, ref stylesheet)| stylesheet.clone()) + .map(|s| s.stylesheet.clone()) .collect() } diff --git a/servo/components/script/dom/dommatrixreadonly.rs b/servo/components/script/dom/dommatrixreadonly.rs index 580549dfe9c6..f2e0576e9c7a 100644 --- a/servo/components/script/dom/dommatrixreadonly.rs +++ b/servo/components/script/dom/dommatrixreadonly.rs @@ -14,9 +14,8 @@ use dom::bindings::reflector::{reflect_dom_object, Reflectable, Reflector}; use dom::dommatrix::DOMMatrix; use dom::dompoint::DOMPoint; use euclid::{Matrix4D, Point4D, Radians}; -use std::cell::Cell; +use std::cell::{Cell, Ref}; use std::f64; -use style::refcell::Ref; #[dom_struct] pub struct DOMMatrixReadOnly { diff --git a/servo/components/script/dom/element.rs b/servo/components/script/dom/element.rs index 9c6ae9a50a07..5736ae22ebed 100644 --- a/servo/components/script/dom/element.rs +++ b/servo/components/script/dom/element.rs @@ -70,12 +70,13 @@ use html5ever::serialize::SerializeOpts; use html5ever::serialize::TraversalScope; use html5ever::serialize::TraversalScope::{ChildrenOnly, IncludeNode}; use html5ever::tree_builder::{LimitedQuirks, NoQuirks, Quirks}; +use parking_lot::RwLock; use selectors::matching::{ElementFlags, MatchingReason, matches}; use selectors::matching::{HAS_EDGE_CHILD_SELECTOR, HAS_SLOW_SELECTOR, HAS_SLOW_SELECTOR_LATER_SIBLINGS}; use selectors::parser::{AttrSelector, NamespaceConstraint, parse_author_origin_selector_list_from_str}; use std::ascii::AsciiExt; use std::borrow::Cow; -use std::cell::Cell; +use std::cell::{Cell, Ref}; use std::convert::TryFrom; use std::default::Default; use std::fmt; @@ -89,7 +90,6 @@ use style::parser::ParserContextExtraData; use style::properties::{DeclaredValue, Importance}; use style::properties::{PropertyDeclaration, PropertyDeclarationBlock, parse_style_attribute}; use style::properties::longhands::{self, background_image, border_spacing, font_family, font_size, overflow_x}; -use style::refcell::Ref; use style::selector_impl::{NonTSPseudoClass, ServoSelectorImpl}; use style::selector_matching::ApplicableDeclarationBlock; use style::sink::Push; @@ -109,7 +109,8 @@ pub struct Element { prefix: Option, attrs: DOMRefCell>>, id_attribute: DOMRefCell>, - style_attribute: DOMRefCell>>, + #[ignore_heap_size_of = "Arc"] + style_attribute: DOMRefCell>>>, attr_list: MutNullableHeap>, class_list: MutNullableHeap>, state: Cell, @@ -297,7 +298,7 @@ pub trait LayoutElementHelpers { #[allow(unsafe_code)] unsafe fn html_element_in_html_document_for_layout(&self) -> bool; fn id_attribute(&self) -> *const Option; - fn style_attribute(&self) -> *const Option>; + fn style_attribute(&self) -> *const Option>>; fn local_name(&self) -> &Atom; fn namespace(&self) -> &Namespace; fn get_checked_state_for_layout(&self) -> bool; @@ -329,10 +330,10 @@ impl LayoutElementHelpers for LayoutJS { #[inline] fn from_declaration(rule: PropertyDeclaration) -> ApplicableDeclarationBlock { ApplicableDeclarationBlock::from_declarations( - Arc::new(PropertyDeclarationBlock { + Arc::new(RwLock::new(PropertyDeclarationBlock { declarations: vec![(rule, Importance::Normal)], important_count: 0, - }), + })), Importance::Normal) } @@ -618,7 +619,7 @@ impl LayoutElementHelpers for LayoutJS { } #[allow(unsafe_code)] - fn style_attribute(&self) -> *const Option> { + fn style_attribute(&self) -> *const Option>> { unsafe { (*self.unsafe_get()).style_attribute.borrow_for_layout() } @@ -707,7 +708,7 @@ impl Element { self.attrs.borrow() } - pub fn style_attribute(&self) -> &DOMRefCell>> { + pub fn style_attribute(&self) -> &DOMRefCell>>> { &self.style_attribute } @@ -737,7 +738,7 @@ impl Element { // therefore, it should not trigger subsequent mutation events pub fn sync_property_with_attrs_style(&self) { let style_str = if let &Some(ref declarations) = &*self.style_attribute().borrow() { - declarations.to_css_string() + declarations.read().to_css_string() } else { String::new() }; @@ -769,7 +770,7 @@ impl Element { let mut inline_declarations = element.style_attribute.borrow_mut(); if let &mut Some(ref mut declarations) = &mut *inline_declarations { let mut importance = None; - let index = declarations.declarations.iter().position(|&(ref decl, i)| { + let index = declarations.read().declarations.iter().position(|&(ref decl, i)| { let matching = decl.matches(property); if matching { importance = Some(i) @@ -777,7 +778,7 @@ impl Element { matching }); if let Some(index) = index { - let declarations = Arc::make_mut(declarations); + let mut declarations = declarations.write(); declarations.declarations.remove(index); if importance.unwrap().important() { declarations.important_count -= 1; @@ -798,9 +799,8 @@ impl Element { let mut inline_declarations = element.style_attribute().borrow_mut(); if let &mut Some(ref mut declaration_block) = &mut *inline_declarations { { - // Usually, the reference count will be 1 here. But transitions could make it greater - // than that. - let declaration_block = Arc::make_mut(declaration_block); + let mut declaration_block = declaration_block.write(); + let declaration_block = &mut *declaration_block; let existing_declarations = &mut declaration_block.declarations; 'outer: for incoming_declaration in declarations { @@ -834,10 +834,10 @@ impl Element { 0 }; - *inline_declarations = Some(Arc::new(PropertyDeclarationBlock { + *inline_declarations = Some(Arc::new(RwLock::new(PropertyDeclarationBlock { declarations: declarations.into_iter().map(|d| (d, importance)).collect(), important_count: important_count, - })); + }))); } update(self, declarations, importance); @@ -850,9 +850,8 @@ impl Element { { let mut inline_declarations = self.style_attribute().borrow_mut(); if let &mut Some(ref mut block) = &mut *inline_declarations { - // Usually, the reference counts of `from` and `to` will be 1 here. But transitions - // could make them greater than that. - let block = Arc::make_mut(block); + let mut block = block.write(); + let block = &mut *block; let declarations = &mut block.declarations; for &mut (ref declaration, ref mut importance) in declarations { if properties.iter().any(|p| declaration.name() == **p) { @@ -874,16 +873,15 @@ impl Element { self.sync_property_with_attrs_style(); } - pub fn get_inline_style_declaration(&self, - property: &Atom) - -> Option> { - Ref::filter_map(self.style_attribute.borrow(), |inline_declarations| { - inline_declarations.as_ref().and_then(|declarations| { - declarations.declarations - .iter() - .find(|&&(ref decl, _)| decl.matches(&property)) - }) - }) + pub fn get_inline_style_declaration(&self, property: &str, f: F) -> R + where F: FnOnce(Option<&(PropertyDeclaration, Importance)>) -> R { + let style_attr = self.style_attribute.borrow(); + if let Some(ref block) = *style_attr { + let block = block.read(); + f(block.get(property)) + } else { + f(None) + } } pub fn serialize(&self, traversal_scope: TraversalScope) -> Fallible { @@ -2129,11 +2127,11 @@ impl VirtualMethods for Element { *self.style_attribute.borrow_mut() = mutation.new_value(attr).map(|value| { let win = window_from_node(self); - Arc::new(parse_style_attribute( + Arc::new(RwLock::new(parse_style_attribute( &value, &doc.base_url(), win.css_error_reporter(), - ParserContextExtraData::default())) + ParserContextExtraData::default()))) }); if node.is_in_doc() { node.dirty(NodeDamage::NodeStyleDamaged); diff --git a/servo/components/script/dom/htmlimageelement.rs b/servo/components/script/dom/htmlimageelement.rs index 195166124f24..6b26daab395b 100644 --- a/servo/components/script/dom/htmlimageelement.rs +++ b/servo/components/script/dom/htmlimageelement.rs @@ -47,6 +47,7 @@ struct ImageRequest { state: State, parsed_url: Option, source_url: Option, + #[ignore_heap_size_of = "Arc"] image: Option>, metadata: Option, } diff --git a/servo/components/script/dom/htmllinkelement.rs b/servo/components/script/dom/htmllinkelement.rs index 064a3787b82a..ff64d8d1fa9f 100644 --- a/servo/components/script/dom/htmllinkelement.rs +++ b/servo/components/script/dom/htmllinkelement.rs @@ -52,6 +52,7 @@ no_jsmanaged_fields!(Stylesheet); pub struct HTMLLinkElement { htmlelement: HTMLElement, rel_list: MutNullableHeap>, + #[ignore_heap_size_of = "Arc"] stylesheet: DOMRefCell>>, diff --git a/servo/components/script/dom/htmlmetaelement.rs b/servo/components/script/dom/htmlmetaelement.rs index 1c51db5de4d4..1b954ce9807b 100644 --- a/servo/components/script/dom/htmlmetaelement.rs +++ b/servo/components/script/dom/htmlmetaelement.rs @@ -27,6 +27,7 @@ use style::viewport::ViewportRule; #[dom_struct] pub struct HTMLMetaElement { htmlelement: HTMLElement, + #[ignore_heap_size_of = "Arc"] stylesheet: DOMRefCell>>, } diff --git a/servo/components/script/dom/htmlobjectelement.rs b/servo/components/script/dom/htmlobjectelement.rs index 7cfd64d73439..d68e13043726 100644 --- a/servo/components/script/dom/htmlobjectelement.rs +++ b/servo/components/script/dom/htmlobjectelement.rs @@ -24,6 +24,7 @@ use string_cache::Atom; #[dom_struct] pub struct HTMLObjectElement { htmlelement: HTMLElement, + #[ignore_heap_size_of = "Arc"] image: DOMRefCell>>, } diff --git a/servo/components/script/dom/htmlstyleelement.rs b/servo/components/script/dom/htmlstyleelement.rs index 73fa545792fb..e8d475a34520 100644 --- a/servo/components/script/dom/htmlstyleelement.rs +++ b/servo/components/script/dom/htmlstyleelement.rs @@ -24,6 +24,7 @@ use style::stylesheets::{Stylesheet, Origin}; #[dom_struct] pub struct HTMLStyleElement { htmlelement: HTMLElement, + #[ignore_heap_size_of = "Arc"] stylesheet: DOMRefCell>>, } diff --git a/servo/components/script/dom/request.rs b/servo/components/script/dom/request.rs index af298a79b556..692dd1fc0f80 100644 --- a/servo/components/script/dom/request.rs +++ b/servo/components/script/dom/request.rs @@ -35,10 +35,9 @@ use net_traits::request::Referrer as NetTraitsRequestReferrer; use net_traits::request::Request as NetTraitsRequest; use net_traits::request::RequestMode as NetTraitsRequestMode; use net_traits::request::Type as NetTraitsRequestType; -use std::cell::Cell; +use std::cell::{Cell, Ref}; use std::mem; use std::rc::Rc; -use style::refcell::Ref; use url::Url; #[dom_struct] diff --git a/servo/components/script/dom/response.rs b/servo/components/script/dom/response.rs index 5e5973a52780..d438281c3560 100644 --- a/servo/components/script/dom/response.rs +++ b/servo/components/script/dom/response.rs @@ -22,10 +22,10 @@ use hyper::header::Headers as HyperHeaders; use hyper::status::StatusCode; use hyper_serde::Serde; use net_traits::response::{ResponseBody as NetTraitsResponseBody}; +use std::cell::Ref; use std::mem; use std::rc::Rc; use std::str::FromStr; -use style::refcell::Ref; use url::Position; use url::Url; diff --git a/servo/components/script/dom/workerglobalscope.rs b/servo/components/script/dom/workerglobalscope.rs index 96743c1af7b4..e7b81e4dae8f 100644 --- a/servo/components/script/dom/workerglobalscope.rs +++ b/servo/components/script/dom/workerglobalscope.rs @@ -83,6 +83,7 @@ pub struct WorkerGlobalScope { worker_id: WorkerId, pipeline_id: PipelineId, worker_url: Url, + #[ignore_heap_size_of = "Arc"] closing: Option>, #[ignore_heap_size_of = "Defined in js"] runtime: Runtime, diff --git a/servo/components/script/layout_wrapper.rs b/servo/components/script/layout_wrapper.rs index b5fc2316ac78..b4b96c0e7fd8 100644 --- a/servo/components/script/layout_wrapper.rs +++ b/servo/components/script/layout_wrapper.rs @@ -41,6 +41,7 @@ use dom::node::{LayoutNodeHelpers, Node}; use dom::text::Text; use gfx_traits::ByteIndex; use msg::constellation_msg::PipelineId; +use parking_lot::RwLock; use range::Range; use script_layout_interface::{HTMLCanvasData, LayoutNodeType, TrustedNodeAddress}; use script_layout_interface::{OpaqueStyleAndLayoutData, PartialPersistentLayoutData}; @@ -461,7 +462,7 @@ impl<'le> TElement for ServoLayoutElement<'le> { ServoLayoutNode::from_layout_js(self.element.upcast()) } - fn style_attribute(&self) -> Option<&Arc> { + fn style_attribute(&self) -> Option<&Arc>> { unsafe { (*self.element.style_attribute()).as_ref() } diff --git a/servo/components/script/lib.rs b/servo/components/script/lib.rs index 07927e986925..7d3d0d2f2c58 100644 --- a/servo/components/script/lib.rs +++ b/servo/components/script/lib.rs @@ -17,6 +17,7 @@ #![feature(slice_patterns)] #![feature(stmt_expr_attributes)] #![feature(question_mark)] +#![feature(try_borrow)] #![feature(try_from)] #![deny(unsafe_code)] @@ -64,6 +65,7 @@ extern crate net_traits; extern crate num_traits; extern crate offscreen_gl_context; extern crate open; +extern crate parking_lot; extern crate phf; #[macro_use] extern crate profile_traits; diff --git a/servo/components/script_layout_interface/Cargo.toml b/servo/components/script_layout_interface/Cargo.toml index 18c90e2cf59a..970c74aa5158 100644 --- a/servo/components/script_layout_interface/Cargo.toml +++ b/servo/components/script_layout_interface/Cargo.toml @@ -27,7 +27,7 @@ plugins = {path = "../plugins"} profile_traits = {path = "../profile_traits"} range = {path = "../range"} script_traits = {path = "../script_traits"} -selectors = {version = "0.13", features = ["heap_size"]} +selectors = "0.13" string_cache = {version = "0.2.26", features = ["heap_size"]} style = {path = "../style"} url = {version = "1.2", features = ["heap_size"]} diff --git a/servo/components/servo/Cargo.lock b/servo/components/servo/Cargo.lock index c88c090559ee..de7c74f5af40 100644 --- a/servo/components/servo/Cargo.lock +++ b/servo/components/servo/Cargo.lock @@ -82,7 +82,7 @@ name = "app_units" version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "heapsize 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "heapsize 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", "num-traits 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)", "serde 0.8.8 (registry+https://github.com/rust-lang/crates.io-index)", @@ -123,7 +123,7 @@ dependencies = [ "core-text 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "euclid 0.10.2 (registry+https://github.com/rust-lang/crates.io-index)", "freetype 0.1.0 (git+https://github.com/servo/rust-freetype)", - "heapsize 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "heapsize 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", "heapsize_plugin 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.16 (registry+https://github.com/rust-lang/crates.io-index)", "serde 0.8.8 (registry+https://github.com/rust-lang/crates.io-index)", @@ -249,7 +249,7 @@ dependencies = [ "cssparser 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", "euclid 0.10.2 (registry+https://github.com/rust-lang/crates.io-index)", "gfx_traits 0.0.1", - "heapsize 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "heapsize 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", "heapsize_plugin 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", "ipc-channel 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", "plugins 0.0.1", @@ -451,7 +451,7 @@ version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "encoding 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)", - "heapsize 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "heapsize 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", "matches 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "serde 0.8.8 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -531,7 +531,7 @@ name = "devtools_traits" version = "0.0.1" dependencies = [ "bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", - "heapsize 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "heapsize 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", "heapsize_plugin 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", "hyper 0.9.10 (registry+https://github.com/rust-lang/crates.io-index)", "hyper_serde 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", @@ -685,7 +685,7 @@ name = "euclid" version = "0.10.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "heapsize 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "heapsize 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", "num-traits 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)", @@ -798,7 +798,7 @@ dependencies = [ "freetype 0.1.0 (git+https://github.com/servo/rust-freetype)", "gfx_traits 0.0.1", "harfbuzz-sys 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", - "heapsize 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "heapsize 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", "heapsize_plugin 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", "ipc-channel 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", "layers 0.5.3 (git+https://github.com/servo/rust-layers)", @@ -845,7 +845,7 @@ version = "0.0.1" dependencies = [ "azure 0.8.0 (git+https://github.com/servo/rust-azure)", "euclid 0.10.2 (registry+https://github.com/rust-lang/crates.io-index)", - "heapsize 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "heapsize 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", "heapsize_plugin 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", "layers 0.5.3 (git+https://github.com/servo/rust-layers)", "msg 0.0.1", @@ -937,7 +937,7 @@ dependencies = [ [[package]] name = "heapsize" -version = "0.3.6" +version = "0.3.7" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", @@ -980,7 +980,7 @@ name = "html5ever" version = "0.5.4" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "heapsize 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "heapsize 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", "heapsize_plugin 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", "mac 0.0.2 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1117,7 +1117,7 @@ version = "0.1.3" source = "git+https://github.com/servo/rust-mozjs#fc380e0e7700f3179a86e8261eafe0828532bbfe" dependencies = [ "cmake 0.1.17 (registry+https://github.com/rust-lang/crates.io-index)", - "heapsize 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "heapsize 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.16 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1154,7 +1154,7 @@ dependencies = [ "euclid 0.10.2 (registry+https://github.com/rust-lang/crates.io-index)", "gleam 0.2.22 (registry+https://github.com/rust-lang/crates.io-index)", "glx 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", - "heapsize 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "heapsize 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", "io-surface 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.16 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1177,7 +1177,7 @@ dependencies = [ "fnv 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", "gfx 0.0.1", "gfx_traits 0.0.1", - "heapsize 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "heapsize 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", "heapsize_plugin 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", "ipc-channel 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.16 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1221,7 +1221,7 @@ dependencies = [ "fnv 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", "gfx 0.0.1", "gfx_traits 0.0.1", - "heapsize 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "heapsize 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", "heapsize_plugin 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", "ipc-channel 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", "layout 0.0.1", @@ -1419,7 +1419,7 @@ version = "0.0.1" dependencies = [ "bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", "cssparser 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", - "heapsize 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "heapsize 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", "heapsize_plugin 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", "hyper 0.9.10 (registry+https://github.com/rust-lang/crates.io-index)", "hyper_serde 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1509,7 +1509,7 @@ name = "net_traits" version = "0.0.1" dependencies = [ "cookie 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)", - "heapsize 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "heapsize 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", "heapsize_plugin 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", "hyper 0.9.10 (registry+https://github.com/rust-lang/crates.io-index)", "hyper_serde 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1919,7 +1919,7 @@ dependencies = [ name = "range" version = "0.0.1" dependencies = [ - "heapsize 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "heapsize 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", "heapsize_plugin 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", "num-traits 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2000,7 +2000,7 @@ dependencies = [ "euclid 0.10.2 (registry+https://github.com/rust-lang/crates.io-index)", "fnv 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", "gfx_traits 0.0.1", - "heapsize 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "heapsize 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", "heapsize_plugin 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", "html5ever 0.5.4 (registry+https://github.com/rust-lang/crates.io-index)", "hyper 0.9.10 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2017,6 +2017,7 @@ dependencies = [ "num-traits 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)", "offscreen_gl_context 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", "open 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "parking_lot 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", "phf 0.7.16 (registry+https://github.com/rust-lang/crates.io-index)", "phf_macros 0.7.16 (registry+https://github.com/rust-lang/crates.io-index)", "plugins 0.0.1", @@ -2053,7 +2054,7 @@ dependencies = [ "cssparser 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", "euclid 0.10.2 (registry+https://github.com/rust-lang/crates.io-index)", "gfx_traits 0.0.1", - "heapsize 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "heapsize 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", "heapsize_plugin 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", "ipc-channel 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.16 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2091,7 +2092,7 @@ dependencies = [ "devtools_traits 0.0.1", "euclid 0.10.2 (registry+https://github.com/rust-lang/crates.io-index)", "gfx_traits 0.0.1", - "heapsize 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "heapsize 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", "heapsize_plugin 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", "hyper_serde 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", "ipc-channel 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2119,8 +2120,6 @@ dependencies = [ "bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", "cssparser 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", "fnv 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", - "heapsize 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", - "heapsize_plugin 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", "matches 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "string_cache 0.2.29 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -2308,7 +2307,7 @@ version = "0.2.29" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "debug_unreachable 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "heapsize 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "heapsize 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "phf_generator 0.7.16 (registry+https://github.com/rust-lang/crates.io-index)", "phf_shared 0.7.16 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2327,7 +2326,7 @@ dependencies = [ "encoding 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)", "euclid 0.10.2 (registry+https://github.com/rust-lang/crates.io-index)", "fnv 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", - "heapsize 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "heapsize 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", "heapsize_plugin 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2362,6 +2361,7 @@ dependencies = [ "app_units 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "cssparser 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", "euclid 0.10.2 (registry+https://github.com/rust-lang/crates.io-index)", + "parking_lot 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)", "selectors 0.13.1 (registry+https://github.com/rust-lang/crates.io-index)", "string_cache 0.2.29 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2378,7 +2378,7 @@ dependencies = [ "app_units 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "cssparser 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", "euclid 0.10.2 (registry+https://github.com/rust-lang/crates.io-index)", - "heapsize 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "heapsize 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", "heapsize_plugin 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)", "serde 0.8.8 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2526,7 +2526,7 @@ version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "encoding 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)", - "heapsize 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "heapsize 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", "idna 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "matches 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2563,7 +2563,7 @@ dependencies = [ "bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", "euclid 0.10.2 (registry+https://github.com/rust-lang/crates.io-index)", "getopts 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)", - "heapsize 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "heapsize 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", "ipc-channel 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2727,7 +2727,7 @@ dependencies = [ "core-graphics 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", "euclid 0.10.2 (registry+https://github.com/rust-lang/crates.io-index)", "gleam 0.2.22 (registry+https://github.com/rust-lang/crates.io-index)", - "heapsize 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "heapsize 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", "ipc-channel 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", "offscreen_gl_context 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", "serde 0.8.8 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2898,7 +2898,7 @@ dependencies = [ "checksum glob 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "8be18de09a56b60ed0edf84bc9df007e30040691af7acd1c41874faac5895bfb" "checksum glx 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "b280007fa9c7442cfd1e0b1addb8d1a59240267110e8705f8f7e2c7bfb7e2f72" "checksum harfbuzz-sys 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "6b76113246f5c089dcf272cf89c3f61168a4d77b50ec5b2c1fab8c628c9ea762" -"checksum heapsize 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "abb306abb8d398e053cfb1b3e7b72c2f580be048b85745c52652954f8ad1439c" +"checksum heapsize 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)" = "8c80e194758495a9109566134dc06e42ea0423987d6ceca016edaa90381b3549" "checksum heapsize_plugin 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "c9a70a1ef0122b54e0553f1d960b686c40d33a7953bc63029509a7649c8ee2c4" "checksum heartbeats-simple 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "78c0810722eacd0bdd3f1f691524bd9900bf8fed1947f6b883c10ddecd2560b1" "checksum heartbeats-simple-sys 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "9d975666b80fe43ca3af2294ba5995a0f3a2a00fe8a229ac4788bdfd5f01a45d" diff --git a/servo/components/style/Cargo.toml b/servo/components/style/Cargo.toml index 358df77ff8c2..2a208f7ff3df 100644 --- a/servo/components/style/Cargo.toml +++ b/servo/components/style/Cargo.toml @@ -16,8 +16,8 @@ gecko = [] servo = ["serde/unstable", "serde", "serde_macros", "heapsize_plugin", "style_traits/servo", "app_units/plugins", "cssparser/heap_size", "cssparser/serde-serialization", - "selectors/heap_size", "selectors/unstable", "string_cache", - "url/heap_size", "plugins"] + "selectors/unstable", "string_cache", + "url/heap_size", "plugins", "parking_lot/nightly"] testing = [] [dependencies] diff --git a/servo/components/style/animation.rs b/servo/components/style/animation.rs index e76ada9b6103..a74b9d9a3c28 100644 --- a/servo/components/style/animation.rs +++ b/servo/components/style/animation.rs @@ -383,7 +383,7 @@ fn compute_style_for_animation_step(context: &SharedStyleContext, KeyframesStepValue::ComputedValues => style_from_cascade.clone(), - KeyframesStepValue::Declarations(ref declarations) => { + KeyframesStepValue::Declarations { block: ref declarations } => { let declaration_block = ApplicableDeclarationBlock { mixed_declarations: declarations.clone(), importance: Importance::Normal, diff --git a/servo/components/style/dom.rs b/servo/components/style/dom.rs index 66a722dbf0d9..099be65f80cb 100644 --- a/servo/components/style/dom.rs +++ b/servo/components/style/dom.rs @@ -9,6 +9,7 @@ use atomic_refcell::{AtomicRef, AtomicRefMut}; use data::PersistentStyleData; use element_state::ElementState; +use parking_lot::RwLock; use properties::{ComputedValues, PropertyDeclarationBlock}; use restyle_hints::{RESTYLE_DESCENDANTS, RESTYLE_LATER_SIBLINGS, RESTYLE_SELF, RestyleHint}; use selector_impl::{ElementExt, PseudoElement}; @@ -202,7 +203,7 @@ pub trait TElement : PartialEq + Debug + Sized + Copy + Clone + ElementExt + Pre fn as_node(&self) -> Self::ConcreteNode; - fn style_attribute(&self) -> Option<&Arc>; + fn style_attribute(&self) -> Option<&Arc>>; fn get_state(&self) -> ElementState; diff --git a/servo/components/style/gecko/wrapper.rs b/servo/components/style/gecko/wrapper.rs index 56b6d0bcf825..9c1dc08c278c 100644 --- a/servo/components/style/gecko/wrapper.rs +++ b/servo/components/style/gecko/wrapper.rs @@ -32,6 +32,7 @@ use gecko_bindings::structs::{nsChangeHint, nsIAtom, nsIContent, nsStyleContext} use gecko_bindings::structs::OpaqueStyleData; use gecko_bindings::sugar::ownership::{FFIArcHelpers, HasArcFFI, HasFFI}; use libc::uintptr_t; +use parking_lot::RwLock; use parser::ParserContextExtraData; use properties::{ComputedValues, parse_style_attribute}; use properties::PropertyDeclarationBlock; @@ -58,7 +59,7 @@ impl NonOpaqueStyleData { pub struct GeckoDeclarationBlock { - pub declarations: Option>, + pub declarations: Option>>, @@ -468,7 +469,7 @@ impl<'le> TElement for GeckoElement<'le> { unsafe { GeckoNode(&*(self.0 as *const _ as *const RawGeckoNode)) } } - fn style_attribute(&self) -> Option<&Arc> { + fn style_attribute(&self) -> Option<&Arc>> { let declarations = unsafe { Gecko_GetServoDeclarationBlock(self.0) }; if declarations.is_null() { None diff --git a/servo/components/style/keyframes.rs b/servo/components/style/keyframes.rs index 3a4f01a94830..d96862814274 100644 --- a/servo/components/style/keyframes.rs +++ b/servo/components/style/keyframes.rs @@ -4,6 +4,7 @@ use cssparser::{AtRuleParser, Parser, QualifiedRuleParser, RuleListParser}; use cssparser::{DeclarationListParser, DeclarationParser}; +use parking_lot::RwLock; use parser::{ParserContext, log_css_error}; use properties::{Importance, PropertyDeclaration, PropertyDeclarationBlock}; use properties::PropertyDeclarationParseResult; @@ -68,7 +69,7 @@ impl KeyframeSelector { } -#[derive(Debug, Clone, PartialEq)] +#[derive(Debug, Clone)] #[cfg_attr(feature = "servo", derive(HeapSizeOf))] pub struct Keyframe { pub selector: KeyframeSelector, @@ -77,23 +78,27 @@ pub struct Keyframe { - pub block: Arc, + #[cfg_attr(feature = "servo", ignore_heap_size_of = "Arc")] + pub block: Arc>, } -#[derive(Debug, Clone, PartialEq)] +#[derive(Debug, Clone)] #[cfg_attr(feature = "servo", derive(HeapSizeOf))] pub enum KeyframesStepValue { - Declarations(Arc), + Declarations { + #[cfg_attr(feature = "servo", ignore_heap_size_of = "Arc")] + block: Arc> + }, ComputedValues, } -#[derive(Debug, Clone, PartialEq)] +#[derive(Debug, Clone)] #[cfg_attr(feature = "servo", derive(HeapSizeOf))] pub struct KeyframesStep { @@ -109,12 +114,13 @@ pub struct KeyframesStep { } impl KeyframesStep { + #[allow(unsafe_code)] #[inline] fn new(percentage: KeyframePercentage, value: KeyframesStepValue) -> Self { let declared_timing_function = match value { - KeyframesStepValue::Declarations(ref block) => { - block.declarations.iter().any(|&(ref prop_decl, _)| { + KeyframesStepValue::Declarations { ref block } => { + block.read().declarations.iter().any(|&(ref prop_decl, _)| { match *prop_decl { PropertyDeclaration::AnimationTimingFunction(..) => true, _ => false, @@ -136,7 +142,7 @@ impl KeyframesStep { -#[derive(Debug, Clone, PartialEq)] +#[derive(Debug, Clone)] #[cfg_attr(feature = "servo", derive(HeapSizeOf))] pub struct KeyframesAnimation { pub steps: Vec, @@ -150,11 +156,12 @@ pub struct KeyframesAnimation { +#[allow(unsafe_code)] fn get_animated_properties(keyframe: &Keyframe) -> Vec { let mut ret = vec![]; - for &(ref declaration, _) in keyframe.block.declarations.iter() { + for &(ref declaration, _) in keyframe.block.read().declarations.iter() { if let Some(property) = TransitionProperty::from_declaration(declaration) { ret.push(property); } @@ -178,8 +185,9 @@ impl KeyframesAnimation { for keyframe in keyframes { for percentage in keyframe.selector.0.iter() { - steps.push(KeyframesStep::new(*percentage, - KeyframesStepValue::Declarations(keyframe.block.clone()))); + steps.push(KeyframesStep::new(*percentage, KeyframesStepValue::Declarations { + block: keyframe.block.clone(), + })); } } @@ -265,10 +273,10 @@ impl<'a> QualifiedRuleParser for KeyframeListParser<'a> { } Ok(Arc::new(Keyframe { selector: prelude, - block: Arc::new(PropertyDeclarationBlock { + block: Arc::new(RwLock::new(PropertyDeclarationBlock { declarations: declarations, important_count: 0, - }), + })), })) } } diff --git a/servo/components/style/lib.rs b/servo/components/style/lib.rs index f8e1229a646e..a10d0b9c0135 100644 --- a/servo/components/style/lib.rs +++ b/servo/components/style/lib.rs @@ -90,7 +90,6 @@ pub mod context; pub mod custom_properties; pub mod data; pub mod dom; -pub mod domrefcell; pub mod element_state; pub mod error_reporting; pub mod font_face; diff --git a/servo/components/style/matching.rs b/servo/components/style/matching.rs index ecf740315e7d..38c11213ac92 100644 --- a/servo/components/style/matching.rs +++ b/servo/components/style/matching.rs @@ -13,7 +13,7 @@ use cascade_info::CascadeInfo; use context::{SharedStyleContext, StyleContext}; use data::PersistentStyleData; use dom::{NodeInfo, TElement, TNode, TRestyleDamage, UnsafeNode}; -use properties::{ComputedValues, PropertyDeclarationBlock, cascade}; +use properties::{ComputedValues, cascade}; use properties::longhands::display::computed_value as display; use selector_impl::{PseudoElement, TheSelectorImpl}; use selector_matching::{ApplicableDeclarationBlock, Stylist}; @@ -24,6 +24,7 @@ use sink::ForgetfulSink; use smallvec::SmallVec; use std::collections::HashMap; use std::hash::{BuildHasherDefault, Hash, Hasher}; +use std::ops::Deref; use std::slice::IterMut; use std::sync::Arc; use string_cache::Atom; @@ -139,7 +140,7 @@ impl<'a> Hash for ApplicableDeclarationsCacheQuery<'a> { for declaration in self.declarations { - let ptr: *const PropertyDeclarationBlock = &*declaration.mixed_declarations; + let ptr: *const _ = Arc::deref(&declaration.mixed_declarations); ptr.hash(state); declaration.importance.hash(state); } @@ -502,7 +503,13 @@ trait PrivateMatchMethods: TNode { -> Arc where Ctx: StyleContext<'a> { - let mut cacheable = true; + + + + + + let has_style_attribute = self.as_element().map_or(false, |e| e.style_attribute().is_some()); + let mut cacheable = !has_style_attribute; let shared_context = context.shared_context(); if animate_properties { cacheable = !self.update_animations_for_cascade(shared_context, diff --git a/servo/components/style/properties/properties.mako.rs b/servo/components/style/properties/properties.mako.rs index 52ce97f73580..7564a3af2a27 100644 --- a/servo/components/style/properties/properties.mako.rs +++ b/servo/components/style/properties/properties.mako.rs @@ -29,7 +29,7 @@ use computed_values; #[cfg(feature = "servo")] use logical_geometry::{LogicalMargin, PhysicalSide}; use logical_geometry::WritingMode; use parser::{ParserContext, ParserContextExtraData, log_css_error}; -use selector_matching::ApplicableDeclarationBlock; +use selector_matching::{ApplicableDeclarationBlock, ApplicableDeclarationBlockReadGuard}; use stylesheets::Origin; use values::LocalToCss; use values::HasViewportPercentage; @@ -311,6 +311,10 @@ impl PropertyDeclarationBlock { pub fn any_normal(&self) -> bool { self.declarations.len() > self.important_count as usize } + + pub fn get(&self, property_name: &str) -> Option< &(PropertyDeclaration, Importance)> { + self.declarations.iter().find(|&&(ref decl, _)| decl.matches(property_name)) + } } impl ToCss for PropertyDeclarationBlock { @@ -741,7 +745,7 @@ impl Shorthand { /// Serializes possible shorthand value to String. pub fn serialize_shorthand_value_to_string<'a, I>(self, declarations: I, importance: Importance) -> String - where I: Iterator + Clone { + where I: IntoIterator, I::IntoIter: Clone { let appendable_value = self.get_shorthand_appendable_value(declarations).unwrap(); let mut result = String::new(); append_declaration_value(&mut result, appendable_value, importance).unwrap(); @@ -755,7 +759,7 @@ impl Shorthand { declarations: I, is_first_serialization: &mut bool) -> Result - where W: Write, I: Iterator + Clone { + where W: Write, I: IntoIterator, I::IntoIter: Clone { match self.get_shorthand_appendable_value(declarations) { None => Ok(false), Some(appendable_value) => { @@ -772,8 +776,10 @@ impl Shorthand { } } - fn get_shorthand_appendable_value<'a, I>(self, declarations: I) -> Option> - where I: Iterator + Clone { + fn get_shorthand_appendable_value<'a, I>(self, declarations: I) + -> Option> + where I: IntoIterator, I::IntoIter: Clone { + let declarations = declarations.into_iter(); // Only cloning iterators (a few pointers each) not declarations. let mut declarations2 = declarations.clone(); @@ -1378,7 +1384,7 @@ pub use gecko_properties::ComputedValues; pub type ServoComputedValues = ComputedValues; #[cfg(feature = "servo")] -#[cfg_attr(feature = "servo", derive(Clone, Debug, HeapSizeOf))] +#[cfg_attr(feature = "servo", derive(Clone, Debug))] pub struct ComputedValues { % for style_struct in data.active_style_structs(): ${style_struct.ident}: Arc, @@ -1719,7 +1725,7 @@ mod lazy_static_module { #[allow(unused_mut, unused_imports)] fn cascade_with_cached_declarations( viewport_size: Size2D, - applicable_declarations: &[ApplicableDeclarationBlock], + applicable_declarations: &[ApplicableDeclarationBlockReadGuard], shareable: bool, parent_style: &ComputedValues, cached_style: &ComputedValues, @@ -1749,8 +1755,8 @@ fn cascade_with_cached_declarations( let mut seen = PropertyBitField::new(); // Declaration blocks are stored in increasing precedence order, // we want them in decreasing order here. - for sub_list in applicable_declarations.iter().rev() { - for declaration in sub_list.iter().rev() { + for block in applicable_declarations.iter().rev() { + for declaration in block.iter().rev() { match *declaration { % for style_struct in data.active_style_structs(): % for property in style_struct.longhands: @@ -1877,15 +1883,20 @@ pub fn cascade(viewport_size: Size2D, None => (true, initial_values), }; + // Aquire locks for at least the lifetime of `specified_custom_properties`. + let applicable_declarations = applicable_declarations.iter() + .map(|block| block.read()) + .collect::>(); + let inherited_custom_properties = inherited_style.custom_properties(); - let mut custom_properties = None; + let mut specified_custom_properties = None; let mut seen_custom = HashSet::new(); - for sub_list in applicable_declarations.iter().rev() { - for declaration in sub_list.iter().rev() { + for block in applicable_declarations.iter().rev() { + for declaration in block.iter().rev() { match *declaration { PropertyDeclaration::Custom(ref name, ref value) => { ::custom_properties::cascade( - &mut custom_properties, &inherited_custom_properties, + &mut specified_custom_properties, &inherited_custom_properties, &mut seen_custom, name, value) } _ => {} @@ -1893,11 +1904,11 @@ pub fn cascade(viewport_size: Size2D, } } let custom_properties = ::custom_properties::finish_cascade( - custom_properties, &inherited_custom_properties); + specified_custom_properties, &inherited_custom_properties); if let (Some(cached_style), Some(parent_style)) = (cached_style, parent_style) { let style = cascade_with_cached_declarations(viewport_size, - applicable_declarations, + &applicable_declarations, shareable, parent_style, cached_style, @@ -1938,8 +1949,8 @@ pub fn cascade(viewport_size: Size2D, // virtual dispatch instead. ComputedValues::do_cascade_property(|cascade_property| { % for category_to_cascade_now in ["early", "other"]: - for sub_list in applicable_declarations.iter().rev() { - for declaration in sub_list.iter().rev() { + for block in applicable_declarations.iter().rev() { + for declaration in block.iter().rev() { if let PropertyDeclaration::Custom(..) = *declaration { continue } diff --git a/servo/components/style/refcell.rs b/servo/components/style/refcell.rs index e002c94adf92..89c199a962e0 100644 --- a/servo/components/style/refcell.rs +++ b/servo/components/style/refcell.rs @@ -15,7 +15,6 @@ #![allow(unsafe_code)] -#[cfg(feature = "servo")] use heapsize::HeapSizeOf; use std::cell::{UnsafeCell, Cell}; use std::cmp::Ordering; use std::fmt::{self, Debug, Display}; @@ -32,13 +31,6 @@ pub struct RefCell { value: UnsafeCell, } -#[cfg(feature = "servo")] -impl HeapSizeOf for RefCell { - fn heap_size_of_children(&self) -> usize { - self.borrow().heap_size_of_children() - } -} - #[derive(Copy, Clone, PartialEq, Eq, Debug)] pub enum BorrowState { @@ -535,18 +527,6 @@ impl<'b, T: ?Sized> Ref<'b, T> { borrow: orig.borrow, } } - - #[inline] - pub fn filter_map(orig: Ref<'b, T>, f: F) -> Option> - where F: FnOnce(&T) -> Option<&U> - { - f(orig.value).map(move |new_value| { - Ref { - value: new_value, - borrow: orig.borrow, - } - }) - } } impl<'b, T: ?Sized> RefMut<'b, T> { diff --git a/servo/components/style/restyle_hints.rs b/servo/components/style/restyle_hints.rs index f4fdb215f7c4..c42116124fa0 100644 --- a/servo/components/style/restyle_hints.rs +++ b/servo/components/style/restyle_hints.rs @@ -340,6 +340,7 @@ impl Sensitivities { #[derive(Debug)] #[cfg_attr(feature = "servo", derive(HeapSizeOf))] struct Dependency { + #[cfg_attr(feature = "servo", ignore_heap_size_of = "Arc")] selector: Arc>, hint: RestyleHint, sensitivities: Sensitivities, diff --git a/servo/components/style/selector_matching.rs b/servo/components/style/selector_matching.rs index f705a39003fd..0c41bbd77676 100644 --- a/servo/components/style/selector_matching.rs +++ b/servo/components/style/selector_matching.rs @@ -9,6 +9,7 @@ use element_state::*; use error_reporting::StdoutErrorReporter; use keyframes::KeyframesAnimation; use media_queries::{Device, MediaType}; +use parking_lot::{RwLock, RwLockReadGuard}; use properties::{self, PropertyDeclaration, PropertyDeclarationBlock, ComputedValues, Importance}; use quickersort::sort_by; use restyle_hints::{RestyleHint, DependencySet}; @@ -78,10 +79,12 @@ pub struct Stylist { state_deps: DependencySet, + #[cfg_attr(feature = "servo", ignore_heap_size_of = "Arc")] sibling_affecting_selectors: Vec>, + #[cfg_attr(feature = "servo", ignore_heap_size_of = "Arc")] non_common_style_affecting_attributes_selectors: Vec>, } @@ -176,7 +179,7 @@ impl Stylist { map.insert(Rule { selector: selector.complex_selector.clone(), - declarations: style_rule.declarations.clone(), + declarations: style_rule.block.clone(), specificity: selector.specificity, source_order: rules_source_order, }); @@ -325,11 +328,12 @@ impl Stylist { + #[allow(unsafe_code)] pub fn push_applicable_declarations( &self, element: &E, parent_bf: Option<&BloomFilter>, - style_attribute: Option<&Arc>, + style_attribute: Option<&Arc>>, pseudo_element: Option<&PseudoElement>, applicable_declarations: &mut V, reason: MatchingReason) -> StyleRelations @@ -388,8 +392,8 @@ impl Stylist { debug!("author normal: {:?}", relations); - if let Some(sa) = style_attribute { - if sa.any_normal() { + if let Some(sa) = style_attribute { + if sa.read().any_normal() { relations |= AFFECTED_BY_STYLE_ATTRIBUTE; Push::push( applicable_declarations, @@ -411,7 +415,7 @@ impl Stylist { if let Some(sa) = style_attribute { - if sa.any_important() { + if sa.read().any_important() { relations |= AFFECTED_BY_STYLE_ATTRIBUTE; Push::push( applicable_declarations, @@ -689,6 +693,7 @@ impl SelectorMap { + #[allow(unsafe_code)] pub fn get_universal_rules(&self, matching_rules_list: &mut V) where V: VecLike @@ -702,11 +707,12 @@ impl SelectorMap { for rule in self.other_rules.iter() { if rule.selector.compound_selector.is_empty() && rule.selector.next.is_none() { - if rule.declarations.any_normal() { + let block = rule.declarations.read(); + if block.any_normal() { matching_rules_list.push( rule.to_applicable_declaration_block(Importance::Normal)); } - if rule.declarations.any_important() { + if block.any_important() { matching_rules_list.push( rule.to_applicable_declaration_block(Importance::Important)); } @@ -743,6 +749,7 @@ impl SelectorMap { } + #[allow(unsafe_code)] fn get_matching_rules(element: &E, parent_bf: Option<&BloomFilter>, rules: &[Rule], @@ -754,7 +761,7 @@ impl SelectorMap { V: VecLike { for rule in rules.iter() { - let block = &rule.declarations; + let block = rule.declarations.read(); let any_declaration_for_importance = if importance.important() { block.any_important() } else { @@ -839,8 +846,10 @@ pub struct Rule { + #[cfg_attr(feature = "servo", ignore_heap_size_of = "Arc")] pub selector: Arc>, - pub declarations: Arc, + #[cfg_attr(feature = "servo", ignore_heap_size_of = "Arc")] + pub declarations: Arc>, pub source_order: usize, pub specificity: u32, } @@ -864,7 +873,8 @@ impl Rule { pub struct ApplicableDeclarationBlock { - pub mixed_declarations: Arc, + #[cfg_attr(feature = "servo", ignore_heap_size_of = "Arc")] + pub mixed_declarations: Arc>, pub importance: Importance, pub source_order: usize, pub specificity: u32, @@ -872,7 +882,7 @@ pub struct ApplicableDeclarationBlock { impl ApplicableDeclarationBlock { #[inline] - pub fn from_declarations(declarations: Arc, + pub fn from_declarations(declarations: Arc>, importance: Importance) -> Self { ApplicableDeclarationBlock { @@ -883,9 +893,24 @@ impl ApplicableDeclarationBlock { } } + pub fn read(&self) -> ApplicableDeclarationBlockReadGuard { + ApplicableDeclarationBlockReadGuard { + guard: self.mixed_declarations.read(), + importance: self.importance, + } + } + +} + +pub struct ApplicableDeclarationBlockReadGuard<'a> { + guard: RwLockReadGuard<'a, PropertyDeclarationBlock>, + importance: Importance, +} + +impl<'a> ApplicableDeclarationBlockReadGuard<'a> { pub fn iter(&self) -> ApplicableDeclarationBlockIter { ApplicableDeclarationBlockIter { - iter: self.mixed_declarations.declarations.iter(), + iter: self.guard.declarations.iter(), importance: self.importance, } } diff --git a/servo/components/style/stylesheets.rs b/servo/components/style/stylesheets.rs index 2a14194f0ce7..f2dffe90d3cc 100644 --- a/servo/components/style/stylesheets.rs +++ b/servo/components/style/stylesheets.rs @@ -11,6 +11,7 @@ use error_reporting::ParseErrorReporter; use font_face::{FontFaceRule, parse_font_face_block}; use keyframes::{Keyframe, parse_keyframe_list}; use media_queries::{Device, MediaQueryList, parse_media_query_list}; +use parking_lot::RwLock; use parser::{ParserContext, ParserContextExtraData, log_css_error}; use properties::{PropertyDeclarationBlock, parse_property_declaration_list}; use selector_impl::TheSelectorImpl; @@ -42,8 +43,7 @@ pub enum Origin { } -#[derive(Debug, PartialEq)] -#[cfg_attr(feature = "servo", derive(HeapSizeOf))] +#[derive(Debug)] pub struct Stylesheet { @@ -62,8 +62,7 @@ pub struct UserAgentStylesheets { } -#[derive(Debug, PartialEq)] -#[cfg_attr(feature = "servo", derive(HeapSizeOf))] +#[derive(Debug)] pub enum CSSRule { @@ -85,15 +84,13 @@ pub struct NamespaceRule { pub url: Namespace, } -#[derive(Debug, PartialEq)] -#[cfg_attr(feature = "servo", derive(HeapSizeOf))] +#[derive(Debug)] pub struct KeyframesRule { pub name: Atom, pub keyframes: Vec>, } -#[derive(Debug, PartialEq)] -#[cfg_attr(feature = "servo", derive(HeapSizeOf))] +#[derive(Debug)] pub struct MediaRule { pub media_queries: Arc, pub rules: Vec, @@ -107,11 +104,10 @@ impl MediaRule { } } -#[derive(Debug, PartialEq)] -#[cfg_attr(feature = "servo", derive(HeapSizeOf))] +#[derive(Debug)] pub struct StyleRule { pub selectors: Vec>, - pub declarations: Arc, + pub block: Arc>, } @@ -563,7 +559,7 @@ impl<'a, 'b> QualifiedRuleParser for NestedRuleParser<'a, 'b> { -> Result { Ok(CSSRule::Style(Arc::new(StyleRule { selectors: prelude, - declarations: Arc::new(parse_property_declaration_list(self.context, input)) + block: Arc::new(RwLock::new(parse_property_declaration_list(self.context, input))) }))) } } diff --git a/servo/ports/cef/Cargo.lock b/servo/ports/cef/Cargo.lock index f2ecc4c327bb..a081b0328a58 100644 --- a/servo/ports/cef/Cargo.lock +++ b/servo/ports/cef/Cargo.lock @@ -55,7 +55,7 @@ name = "app_units" version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "heapsize 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "heapsize 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", "num-traits 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)", "serde 0.8.8 (registry+https://github.com/rust-lang/crates.io-index)", @@ -96,7 +96,7 @@ dependencies = [ "core-text 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "euclid 0.10.2 (registry+https://github.com/rust-lang/crates.io-index)", "freetype 0.1.0 (git+https://github.com/servo/rust-freetype)", - "heapsize 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "heapsize 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", "heapsize_plugin 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.16 (registry+https://github.com/rust-lang/crates.io-index)", "serde 0.8.8 (registry+https://github.com/rust-lang/crates.io-index)", @@ -222,7 +222,7 @@ dependencies = [ "cssparser 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", "euclid 0.10.2 (registry+https://github.com/rust-lang/crates.io-index)", "gfx_traits 0.0.1", - "heapsize 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "heapsize 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", "heapsize_plugin 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", "ipc-channel 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", "plugins 0.0.1", @@ -408,7 +408,7 @@ version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "encoding 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)", - "heapsize 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "heapsize 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", "matches 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "serde 0.8.8 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -488,7 +488,7 @@ name = "devtools_traits" version = "0.0.1" dependencies = [ "bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", - "heapsize 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "heapsize 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", "heapsize_plugin 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", "hyper 0.9.10 (registry+https://github.com/rust-lang/crates.io-index)", "hyper_serde 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", @@ -601,7 +601,7 @@ name = "euclid" version = "0.10.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "heapsize 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "heapsize 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", "num-traits 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)", @@ -714,7 +714,7 @@ dependencies = [ "freetype 0.1.0 (git+https://github.com/servo/rust-freetype)", "gfx_traits 0.0.1", "harfbuzz-sys 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", - "heapsize 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "heapsize 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", "heapsize_plugin 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", "ipc-channel 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", "layers 0.5.3 (git+https://github.com/servo/rust-layers)", @@ -752,7 +752,7 @@ version = "0.0.1" dependencies = [ "azure 0.8.0 (git+https://github.com/servo/rust-azure)", "euclid 0.10.2 (registry+https://github.com/rust-lang/crates.io-index)", - "heapsize 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "heapsize 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", "heapsize_plugin 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", "layers 0.5.3 (git+https://github.com/servo/rust-layers)", "msg 0.0.1", @@ -844,7 +844,7 @@ dependencies = [ [[package]] name = "heapsize" -version = "0.3.6" +version = "0.3.7" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", @@ -887,7 +887,7 @@ name = "html5ever" version = "0.5.4" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "heapsize 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "heapsize 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", "heapsize_plugin 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", "mac 0.0.2 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1024,7 +1024,7 @@ version = "0.1.3" source = "git+https://github.com/servo/rust-mozjs#fc380e0e7700f3179a86e8261eafe0828532bbfe" dependencies = [ "cmake 0.1.17 (registry+https://github.com/rust-lang/crates.io-index)", - "heapsize 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "heapsize 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.16 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1061,7 +1061,7 @@ dependencies = [ "euclid 0.10.2 (registry+https://github.com/rust-lang/crates.io-index)", "gleam 0.2.22 (registry+https://github.com/rust-lang/crates.io-index)", "glx 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", - "heapsize 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "heapsize 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", "io-surface 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.16 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1084,7 +1084,7 @@ dependencies = [ "fnv 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", "gfx 0.0.1", "gfx_traits 0.0.1", - "heapsize 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "heapsize 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", "heapsize_plugin 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", "ipc-channel 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.16 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1121,7 +1121,7 @@ dependencies = [ "fnv 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", "gfx 0.0.1", "gfx_traits 0.0.1", - "heapsize 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "heapsize 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", "heapsize_plugin 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", "ipc-channel 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", "layout 0.0.1", @@ -1319,7 +1319,7 @@ version = "0.0.1" dependencies = [ "bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", "cssparser 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", - "heapsize 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "heapsize 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", "heapsize_plugin 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", "hyper 0.9.10 (registry+https://github.com/rust-lang/crates.io-index)", "hyper_serde 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1387,7 +1387,7 @@ name = "net_traits" version = "0.0.1" dependencies = [ "cookie 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)", - "heapsize 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "heapsize 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", "heapsize_plugin 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", "hyper 0.9.10 (registry+https://github.com/rust-lang/crates.io-index)", "hyper_serde 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1770,7 +1770,7 @@ dependencies = [ name = "range" version = "0.0.1" dependencies = [ - "heapsize 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "heapsize 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", "heapsize_plugin 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", "num-traits 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1851,7 +1851,7 @@ dependencies = [ "euclid 0.10.2 (registry+https://github.com/rust-lang/crates.io-index)", "fnv 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", "gfx_traits 0.0.1", - "heapsize 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "heapsize 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", "heapsize_plugin 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", "html5ever 0.5.4 (registry+https://github.com/rust-lang/crates.io-index)", "hyper 0.9.10 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1868,6 +1868,7 @@ dependencies = [ "num-traits 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)", "offscreen_gl_context 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", "open 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "parking_lot 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", "phf 0.7.16 (registry+https://github.com/rust-lang/crates.io-index)", "phf_macros 0.7.16 (registry+https://github.com/rust-lang/crates.io-index)", "plugins 0.0.1", @@ -1904,7 +1905,7 @@ dependencies = [ "cssparser 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", "euclid 0.10.2 (registry+https://github.com/rust-lang/crates.io-index)", "gfx_traits 0.0.1", - "heapsize 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "heapsize 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", "heapsize_plugin 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", "ipc-channel 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.16 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1932,7 +1933,7 @@ dependencies = [ "devtools_traits 0.0.1", "euclid 0.10.2 (registry+https://github.com/rust-lang/crates.io-index)", "gfx_traits 0.0.1", - "heapsize 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "heapsize 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", "heapsize_plugin 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", "hyper_serde 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", "ipc-channel 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1960,8 +1961,6 @@ dependencies = [ "bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", "cssparser 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", "fnv 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", - "heapsize 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", - "heapsize_plugin 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", "matches 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "string_cache 0.2.29 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -2191,7 +2190,7 @@ version = "0.2.29" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "debug_unreachable 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "heapsize 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "heapsize 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "phf_generator 0.7.16 (registry+https://github.com/rust-lang/crates.io-index)", "phf_shared 0.7.16 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2210,7 +2209,7 @@ dependencies = [ "encoding 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)", "euclid 0.10.2 (registry+https://github.com/rust-lang/crates.io-index)", "fnv 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", - "heapsize 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "heapsize 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", "heapsize_plugin 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2245,7 +2244,7 @@ dependencies = [ "app_units 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "cssparser 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", "euclid 0.10.2 (registry+https://github.com/rust-lang/crates.io-index)", - "heapsize 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "heapsize 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", "heapsize_plugin 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)", "serde 0.8.8 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2393,7 +2392,7 @@ version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "encoding 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)", - "heapsize 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "heapsize 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", "idna 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "matches 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2430,7 +2429,7 @@ dependencies = [ "bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", "euclid 0.10.2 (registry+https://github.com/rust-lang/crates.io-index)", "getopts 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)", - "heapsize 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "heapsize 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", "ipc-channel 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2587,7 +2586,7 @@ dependencies = [ "core-graphics 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", "euclid 0.10.2 (registry+https://github.com/rust-lang/crates.io-index)", "gleam 0.2.22 (registry+https://github.com/rust-lang/crates.io-index)", - "heapsize 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "heapsize 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", "ipc-channel 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", "offscreen_gl_context 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", "serde 0.8.8 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2752,7 +2751,7 @@ dependencies = [ "checksum glob 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "8be18de09a56b60ed0edf84bc9df007e30040691af7acd1c41874faac5895bfb" "checksum glx 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "b280007fa9c7442cfd1e0b1addb8d1a59240267110e8705f8f7e2c7bfb7e2f72" "checksum harfbuzz-sys 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "6b76113246f5c089dcf272cf89c3f61168a4d77b50ec5b2c1fab8c628c9ea762" -"checksum heapsize 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "abb306abb8d398e053cfb1b3e7b72c2f580be048b85745c52652954f8ad1439c" +"checksum heapsize 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)" = "8c80e194758495a9109566134dc06e42ea0423987d6ceca016edaa90381b3549" "checksum heapsize_plugin 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "c9a70a1ef0122b54e0553f1d960b686c40d33a7953bc63029509a7649c8ee2c4" "checksum heartbeats-simple 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "78c0810722eacd0bdd3f1f691524bd9900bf8fed1947f6b883c10ddecd2560b1" "checksum heartbeats-simple-sys 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "9d975666b80fe43ca3af2294ba5995a0f3a2a00fe8a229ac4788bdfd5f01a45d" diff --git a/servo/ports/geckolib/Cargo.lock b/servo/ports/geckolib/Cargo.lock index 22cd756a8f39..ad9fb96bc924 100644 --- a/servo/ports/geckolib/Cargo.lock +++ b/servo/ports/geckolib/Cargo.lock @@ -9,6 +9,7 @@ dependencies = [ "libc 0.2.16 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", "num_cpus 0.2.13 (registry+https://github.com/rust-lang/crates.io-index)", + "parking_lot 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", "selectors 0.13.1 (registry+https://github.com/rust-lang/crates.io-index)", "style 0.0.1", "style_traits 0.0.1", @@ -29,7 +30,7 @@ name = "app_units" version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "heapsize 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "heapsize 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", "num-traits 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)", "serde 0.8.8 (registry+https://github.com/rust-lang/crates.io-index)", @@ -51,7 +52,7 @@ version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "encoding 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)", - "heapsize 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "heapsize 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", "matches 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -142,7 +143,7 @@ name = "euclid" version = "0.10.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "heapsize 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "heapsize 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", "num-traits 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)", @@ -161,7 +162,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "heapsize" -version = "0.3.6" +version = "0.3.7" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", @@ -369,7 +370,7 @@ dependencies = [ "encoding 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)", "euclid 0.10.2 (registry+https://github.com/rust-lang/crates.io-index)", "fnv 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", - "heapsize 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "heapsize 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.16 (registry+https://github.com/rust-lang/crates.io-index)", @@ -482,7 +483,7 @@ dependencies = [ "bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", "euclid 0.10.2 (registry+https://github.com/rust-lang/crates.io-index)", "getopts 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)", - "heapsize 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "heapsize 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", "num_cpus 0.2.13 (registry+https://github.com/rust-lang/crates.io-index)", @@ -539,7 +540,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum euclid 0.10.2 (registry+https://github.com/rust-lang/crates.io-index)" = "44ef2a3e4a621518e488db36820a12b49a9d5004764b8daf1458bbe5d7c9b626" "checksum fnv 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "8e8af7b5408ab0c4910cad114c8f9eb454bf75df7afe8964307eeafb68a13a5e" "checksum getopts 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)" = "d9047cfbd08a437050b363d35ef160452c5fe8ea5187ae0a624708c91581d685" -"checksum heapsize 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "abb306abb8d398e053cfb1b3e7b72c2f580be048b85745c52652954f8ad1439c" +"checksum heapsize 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)" = "8c80e194758495a9109566134dc06e42ea0423987d6ceca016edaa90381b3549" "checksum idna 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1053236e00ce4f668aeca4a769a09b3bf5a682d802abd6f3cb39374f6b162c11" "checksum kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d" "checksum lazy_static 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "49247ec2a285bb3dcb23cbd9c35193c025e7251bfce77c1d5da97e6362dffe7f" diff --git a/servo/ports/geckolib/Cargo.toml b/servo/ports/geckolib/Cargo.toml index 63f980f3bb9b..50260374172f 100644 --- a/servo/ports/geckolib/Cargo.toml +++ b/servo/ports/geckolib/Cargo.toml @@ -17,6 +17,7 @@ lazy_static = "0.2" libc = "0.2" log = {version = "0.3.5", features = ["release_max_level_info"]} num_cpus = "0.2.2" +parking_lot = "0.3" selectors = "0.13" style = {path = "../../components/style", features = ["gecko"]} style_traits = {path = "../../components/style_traits"} diff --git a/servo/ports/geckolib/glue.rs b/servo/ports/geckolib/glue.rs index 5b4cdd04679a..ab4da50c7dbb 100644 --- a/servo/ports/geckolib/glue.rs +++ b/servo/ports/geckolib/glue.rs @@ -7,6 +7,7 @@ use app_units::Au; use env_logger; use euclid::Size2D; +use parking_lot::RwLock; use std::mem::transmute; use std::ptr; use std::slice; @@ -344,7 +345,9 @@ pub extern "C" fn Servo_ParseStyleAttribute(bytes: *const u8, length: u32, -> ServoDeclarationBlockStrong { let value = unsafe { from_utf8_unchecked(slice::from_raw_parts(bytes, length as usize)) }; Arc::new(GeckoDeclarationBlock { - declarations: GeckoElement::parse_style_attribute(value).map(Arc::new), + declarations: GeckoElement::parse_style_attribute(value).map(|block| { + Arc::new(RwLock::new(block)) + }), cache: AtomicPtr::new(cache), immutable: AtomicBool::new(false), }).into_strong() diff --git a/servo/ports/geckolib/lib.rs b/servo/ports/geckolib/lib.rs index 913310243177..7e0d8e52000b 100644 --- a/servo/ports/geckolib/lib.rs +++ b/servo/ports/geckolib/lib.rs @@ -9,6 +9,7 @@ extern crate env_logger; extern crate euclid; extern crate libc; #[macro_use] extern crate log; +extern crate parking_lot; extern crate url; #[allow(non_snake_case)] diff --git a/servo/tests/unit/style/Cargo.toml b/servo/tests/unit/style/Cargo.toml index a7923a49a696..4dd3dd0e574a 100644 --- a/servo/tests/unit/style/Cargo.toml +++ b/servo/tests/unit/style/Cargo.toml @@ -13,8 +13,9 @@ doctest = false app_units = "0.3" cssparser = {version = "0.7", features = ["heap_size"]} euclid = "0.10.1" +parking_lot = "0.3" rustc-serialize = "0.3" -selectors = {version = "0.13", features = ["heap_size"]} +selectors = "0.13" string_cache = {version = "0.2.26", features = ["heap_size"]} style = {path = "../../../components/style"} style_traits = {path = "../../../components/style_traits"} diff --git a/servo/tests/unit/style/lib.rs b/servo/tests/unit/style/lib.rs index 226da9de30c9..bd3768359a56 100644 --- a/servo/tests/unit/style/lib.rs +++ b/servo/tests/unit/style/lib.rs @@ -9,6 +9,7 @@ extern crate app_units; extern crate cssparser; extern crate euclid; +extern crate parking_lot; extern crate rustc_serialize; extern crate selectors; #[macro_use(atom, ns)] extern crate string_cache; diff --git a/servo/tests/unit/style/selector_matching.rs b/servo/tests/unit/style/selector_matching.rs index 82465806704d..eb95048a70f5 100644 --- a/servo/tests/unit/style/selector_matching.rs +++ b/servo/tests/unit/style/selector_matching.rs @@ -3,12 +3,14 @@ use cssparser::Parser; +use parking_lot::RwLock; use selectors::parser::{LocalName, ParserContext, parse_selector_list}; use std::sync::Arc; use string_cache::Atom; use style::properties::{PropertyDeclarationBlock, PropertyDeclaration, DeclaredValue}; use style::properties::{longhands, Importance}; use style::selector_matching::{Rule, SelectorMap}; +use style::thread_state; @@ -19,14 +21,14 @@ fn get_mock_rules(css_selectors: &[&str]) -> Vec> { .unwrap().into_iter().map(|s| { Rule { selector: s.complex_selector.clone(), - declarations: Arc::new(PropertyDeclarationBlock { + declarations: Arc::new(RwLock::new(PropertyDeclarationBlock { declarations: vec![ (PropertyDeclaration::Display(DeclaredValue::Value( longhands::display::SpecifiedValue::block)), Importance::Normal), ], important_count: 0, - }), + })), specificity: s.specificity, source_order: i, } @@ -99,6 +101,7 @@ fn test_insert() { #[test] fn test_get_universal_rules() { + thread_state::initialize(thread_state::LAYOUT); let map = get_mock_map(&["*|*", "#foo > *|*", ".klass", "#id"]); let mut decls = vec![]; diff --git a/servo/tests/unit/style/stylesheets.rs b/servo/tests/unit/style/stylesheets.rs index 4ec44e6700f0..c9af969f4b9f 100644 --- a/servo/tests/unit/style/stylesheets.rs +++ b/servo/tests/unit/style/stylesheets.rs @@ -4,6 +4,7 @@ use cssparser::{self, Parser, SourcePosition}; use media_queries::CSSErrorReporterTest; +use parking_lot::RwLock; use selectors::parser::*; use std::borrow::ToOwned; use std::sync::Arc; @@ -50,17 +51,7 @@ fn test_parse_stylesheet() { let stylesheet = Stylesheet::from_str(css, url, Origin::UserAgent, Box::new(CSSErrorReporterTest), 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 { + let expected = Stylesheet { origin: Origin::UserAgent, media: None, dirty_on_viewport_size_change: false, @@ -97,7 +88,7 @@ fn test_parse_stylesheet() { specificity: (0 << 20) + (1 << 10) + (1 << 0), }, ], - declarations: Arc::new(PropertyDeclarationBlock { + block: Arc::new(RwLock::new(PropertyDeclarationBlock { declarations: vec![ (PropertyDeclaration::Display(DeclaredValue::Value( longhands::display::SpecifiedValue::none)), @@ -106,7 +97,7 @@ fn test_parse_stylesheet() { Importance::Important), ], important_count: 2, - }), + })), })), CSSRule::Style(Arc::new(StyleRule { selectors: vec![ @@ -145,14 +136,14 @@ fn test_parse_stylesheet() { specificity: (0 << 20) + (0 << 10) + (1 << 0), }, ], - declarations: Arc::new(PropertyDeclarationBlock { + block: Arc::new(RwLock::new(PropertyDeclarationBlock { declarations: vec![ (PropertyDeclaration::Display(DeclaredValue::Value( longhands::display::SpecifiedValue::block)), Importance::Normal), ], important_count: 0, - }), + })), })), CSSRule::Style(Arc::new(StyleRule { selectors: vec![ @@ -180,7 +171,7 @@ fn test_parse_stylesheet() { specificity: (1 << 20) + (1 << 10) + (0 << 0), }, ], - declarations: Arc::new(PropertyDeclarationBlock { + block: Arc::new(RwLock::new(PropertyDeclarationBlock { declarations: vec![ (PropertyDeclaration::BackgroundColor(DeclaredValue::Value( longhands::background_color::SpecifiedValue { @@ -228,7 +219,7 @@ fn test_parse_stylesheet() { Importance::Normal), ], important_count: 0, - }), + })), })), CSSRule::Keyframes(Arc::new(KeyframesRule { name: "foo".into(), @@ -236,19 +227,19 @@ fn test_parse_stylesheet() { Arc::new(Keyframe { selector: KeyframeSelector::new_for_unit_testing( vec![KeyframePercentage::new(0.)]), - block: Arc::new(PropertyDeclarationBlock { + block: Arc::new(RwLock::new(PropertyDeclarationBlock { declarations: vec![ (PropertyDeclaration::Width(DeclaredValue::Value( LengthOrPercentageOrAuto::Percentage(Percentage(0.)))), Importance::Normal), ], important_count: 0, - }) + })) }), Arc::new(Keyframe { selector: KeyframeSelector::new_for_unit_testing( vec![KeyframePercentage::new(1.)]), - block: Arc::new(PropertyDeclarationBlock { + block: Arc::new(RwLock::new(PropertyDeclarationBlock { declarations: vec![ (PropertyDeclaration::Width(DeclaredValue::Value( LengthOrPercentageOrAuto::Percentage(Percentage(1.)))), @@ -259,13 +250,15 @@ fn test_parse_stylesheet() { Importance::Normal), ], important_count: 0, - }), + })), }), ] })) ], - }); + }; + + assert_eq!(format!("{:#?}", stylesheet), format!("{:#?}", expected)); } struct CSSError {