mirror of
https://github.com/servo/servo.git
synced 2025-08-12 08:55:32 +01:00
Rename PrivateStyleData to PersistentStyleData and use AtomicRefCell instead of RefCell as a container.
This allows us to eliminate the unsafe borrows. \o/ MozReview-Commit-ID: 29hpGaWUFQz
This commit is contained in:
parent
5bcc4192bf
commit
687e1f701c
12 changed files with 96 additions and 142 deletions
|
@ -11,7 +11,7 @@ use std::hash::BuildHasherDefault;
|
|||
use std::sync::Arc;
|
||||
use std::sync::atomic::AtomicIsize;
|
||||
|
||||
pub struct PrivateStyleData {
|
||||
pub struct PersistentStyleData {
|
||||
/// The results of CSS styling for this node.
|
||||
pub style: Option<Arc<ComputedValues>>,
|
||||
|
||||
|
@ -23,9 +23,9 @@ pub struct PrivateStyleData {
|
|||
pub parallel: DomParallelInfo,
|
||||
}
|
||||
|
||||
impl PrivateStyleData {
|
||||
impl PersistentStyleData {
|
||||
pub fn new() -> Self {
|
||||
PrivateStyleData {
|
||||
PersistentStyleData {
|
||||
style: None,
|
||||
per_pseudo: HashMap::with_hasher(Default::default()),
|
||||
parallel: DomParallelInfo::new(),
|
||||
|
|
|
@ -6,11 +6,10 @@
|
|||
|
||||
#![allow(unsafe_code)]
|
||||
|
||||
use context::SharedStyleContext;
|
||||
use data::PrivateStyleData;
|
||||
use atomic_refcell::{AtomicRef, AtomicRefMut};
|
||||
use data::PersistentStyleData;
|
||||
use element_state::ElementState;
|
||||
use properties::{ComputedValues, PropertyDeclarationBlock};
|
||||
use refcell::{Ref, RefMut};
|
||||
use restyle_hints::{RESTYLE_DESCENDANTS, RESTYLE_LATER_SIBLINGS, RESTYLE_SELF, RestyleHint};
|
||||
use selector_impl::{ElementExt, PseudoElement};
|
||||
use selector_matching::ApplicableDeclarationBlock;
|
||||
|
@ -139,17 +138,13 @@ pub trait TNode : Sized + Copy + Clone + NodeInfo {
|
|||
|
||||
unsafe fn set_can_be_fragmented(&self, value: bool);
|
||||
|
||||
/// Borrows the PrivateStyleData without checks.
|
||||
/// Borrows the style data immutably. Fails on a conflicting borrow.
|
||||
#[inline(always)]
|
||||
unsafe fn borrow_data_unchecked(&self) -> Option<*const PrivateStyleData>;
|
||||
fn borrow_data(&self) -> Option<AtomicRef<PersistentStyleData>>;
|
||||
|
||||
/// Borrows the PrivateStyleData immutably. Fails on a conflicting borrow.
|
||||
/// Borrows the style data mutably. Fails on a conflicting borrow.
|
||||
#[inline(always)]
|
||||
fn borrow_data(&self) -> Option<Ref<PrivateStyleData>>;
|
||||
|
||||
/// Borrows the PrivateStyleData mutably. Fails on a conflicting borrow.
|
||||
#[inline(always)]
|
||||
fn mutate_data(&self) -> Option<RefMut<PrivateStyleData>>;
|
||||
fn mutate_data(&self) -> Option<AtomicRefMut<PersistentStyleData>>;
|
||||
|
||||
/// Get the description of how to account for recent style changes.
|
||||
fn restyle_damage(self) -> Self::ConcreteRestyleDamage;
|
||||
|
|
|
@ -5,7 +5,8 @@
|
|||
#![allow(unsafe_code)]
|
||||
|
||||
|
||||
use data::PrivateStyleData;
|
||||
use atomic_refcell::{AtomicRef, AtomicRefCell, AtomicRefMut};
|
||||
use data::PersistentStyleData;
|
||||
use dom::{LayoutIterator, NodeInfo, TDocument, TElement, TNode, TRestyleDamage, UnsafeNode};
|
||||
use dom::{OpaqueNode, PresentationalHintsSynthetizer};
|
||||
use element_state::ElementState;
|
||||
|
@ -34,7 +35,6 @@ use libc::uintptr_t;
|
|||
use parser::ParserContextExtraData;
|
||||
use properties::{ComputedValues, parse_style_attribute};
|
||||
use properties::PropertyDeclarationBlock;
|
||||
use refcell::{Ref, RefCell, RefMut};
|
||||
use selector_impl::ElementExt;
|
||||
use selector_matching::ApplicableDeclarationBlock;
|
||||
use selectors::Element;
|
||||
|
@ -48,11 +48,11 @@ use std::sync::atomic::{AtomicBool, AtomicPtr};
|
|||
use string_cache::{Atom, Namespace, WeakAtom, WeakNamespace};
|
||||
use url::Url;
|
||||
|
||||
pub struct NonOpaqueStyleData(RefCell<PrivateStyleData>);
|
||||
pub struct NonOpaqueStyleData(AtomicRefCell<PersistentStyleData>);
|
||||
|
||||
impl NonOpaqueStyleData {
|
||||
pub fn new() -> Self {
|
||||
NonOpaqueStyleData(RefCell::new(PrivateStyleData::new()))
|
||||
NonOpaqueStyleData(AtomicRefCell::new(PersistentStyleData::new()))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -302,18 +302,12 @@ impl<'ln> TNode for GeckoNode<'ln> {
|
|||
}
|
||||
|
||||
#[inline(always)]
|
||||
unsafe fn borrow_data_unchecked(&self) -> Option<*const PrivateStyleData> {
|
||||
self.get_node_data().as_ref().map(|d| d.0.as_unsafe_cell().get()
|
||||
as *const PrivateStyleData)
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
fn borrow_data(&self) -> Option<Ref<PrivateStyleData>> {
|
||||
fn borrow_data(&self) -> Option<AtomicRef<PersistentStyleData>> {
|
||||
self.get_node_data().as_ref().map(|d| d.0.borrow())
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
fn mutate_data(&self) -> Option<RefMut<PrivateStyleData>> {
|
||||
fn mutate_data(&self) -> Option<AtomicRefMut<PersistentStyleData>> {
|
||||
self.get_node_data().as_ref().map(|d| d.0.borrow_mut())
|
||||
}
|
||||
|
||||
|
|
|
@ -11,7 +11,7 @@ use arc_ptr_eq;
|
|||
use cache::{LRUCache, SimpleHashCache};
|
||||
use cascade_info::CascadeInfo;
|
||||
use context::{SharedStyleContext, StyleContext};
|
||||
use data::PrivateStyleData;
|
||||
use data::PersistentStyleData;
|
||||
use dom::{NodeInfo, TElement, TNode, TRestyleDamage, UnsafeNode};
|
||||
use properties::{ComputedValues, PropertyDeclarationBlock, cascade};
|
||||
use properties::longhands::display::computed_value as display;
|
||||
|
@ -874,19 +874,9 @@ pub trait MatchMethods : TNode {
|
|||
-> RestyleResult
|
||||
where Ctx: StyleContext<'a>
|
||||
{
|
||||
// Get our parent's style. This must be unsafe so that we don't touch the parent's
|
||||
// borrow flags.
|
||||
//
|
||||
// FIXME(pcwalton): Isolate this unsafety into the `wrapper` module to allow
|
||||
// enforced safe, race-free access to the parent style.
|
||||
let parent_style = match parent {
|
||||
Some(parent_node) => {
|
||||
let parent_style = (*parent_node.borrow_data_unchecked().unwrap()).style.as_ref().unwrap();
|
||||
Some(parent_style)
|
||||
}
|
||||
None => None,
|
||||
};
|
||||
|
||||
// Get our parent's style.
|
||||
let parent_node_data = parent.as_ref().and_then(|x| x.borrow_data());
|
||||
let parent_style = parent_node_data.as_ref().map(|x| x.style.as_ref().unwrap());
|
||||
|
||||
// In the case we're styling a text node, we don't need to compute the
|
||||
// restyle damage, since it's a subset of the restyle damage of the
|
||||
|
@ -945,7 +935,7 @@ pub trait MatchMethods : TNode {
|
|||
|
||||
fn compute_damage_and_cascade_pseudos<'a, Ctx>(&self,
|
||||
final_style: Arc<ComputedValues>,
|
||||
data: &mut PrivateStyleData,
|
||||
data: &mut PersistentStyleData,
|
||||
context: &Ctx,
|
||||
applicable_declarations: &ApplicableDeclarations,
|
||||
mut applicable_declarations_cache: &mut ApplicableDeclarationsCache)
|
||||
|
|
|
@ -161,9 +161,7 @@ fn bottom_up_dom<N, C>(root: OpaqueNode,
|
|||
Some(parent) => parent,
|
||||
};
|
||||
|
||||
let parent_data = unsafe {
|
||||
&*parent.borrow_data_unchecked().unwrap()
|
||||
};
|
||||
let parent_data = parent.borrow_data().unwrap();
|
||||
|
||||
if parent_data
|
||||
.parallel
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue