Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stylo: avoid traversing non element/text nodes in style and layout #13172

Merged
merged 3 commits into from Sep 22, 2016
Merged
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

Introduce the LayoutIterator newtype and return it for all children()…

… methods in style and layout.
  • Loading branch information
bholley committed Sep 21, 2016
commit 4aa3e589c047f006fa37c25e5bf1ba1e1b69b8e4
@@ -58,7 +58,8 @@ use style::attr::AttrValue;
use style::computed_values::display;
use style::context::SharedStyleContext;
use style::data::PrivateStyleData;
use style::dom::{NodeInfo, OpaqueNode, PresentationalHintsSynthetizer, TDocument, TElement, TNode, UnsafeNode};
use style::dom::{LayoutIterator, NodeInfo, OpaqueNode, PresentationalHintsSynthetizer, TDocument, TElement, TNode};
use style::dom::UnsafeNode;
use style::element_state::*;
use style::properties::{ComputedValues, PropertyDeclarationBlock};
use style::refcell::{Ref, RefCell, RefMut};
@@ -149,10 +150,10 @@ impl<'ln> TNode for ServoLayoutNode<'ln> {
self.dump_style_indent(0);
}

fn children(self) -> ServoChildrenIterator<'ln> {
ServoChildrenIterator {
fn children(self) -> LayoutIterator<ServoChildrenIterator<'ln>> {
LayoutIterator(ServoChildrenIterator {
current: self.first_child(),
}
})
}

fn opaque(&self) -> OpaqueNode {
@@ -771,8 +772,8 @@ impl<'ln> ThreadSafeLayoutNode for ServoThreadSafeLayoutNode<'ln> {
self.node.debug_id()
}

fn children(&self) -> Self::ChildrenIterator {
ThreadSafeLayoutNodeChildrenIterator::new(*self)
fn children(&self) -> LayoutIterator<Self::ChildrenIterator> {
LayoutIterator(ThreadSafeLayoutNodeChildrenIterator::new(*self))
}

fn as_element(&self) -> ServoThreadSafeLayoutElement<'ln> {
@@ -15,7 +15,7 @@ use std::sync::Arc;
use string_cache::{Atom, Namespace};
use style::computed_values::display;
use style::context::SharedStyleContext;
use style::dom::{NodeInfo, PresentationalHintsSynthetizer, TNode};
use style::dom::{LayoutIterator, NodeInfo, PresentationalHintsSynthetizer, TNode};
use style::dom::OpaqueNode;
use style::properties::ServoComputedValues;
use style::refcell::{Ref, RefCell};
@@ -81,10 +81,10 @@ pub trait LayoutNode: TNode {
fn init_style_and_layout_data(&self, data: OpaqueStyleAndLayoutData);
fn get_style_and_layout_data(&self) -> Option<OpaqueStyleAndLayoutData>;

fn rev_children(self) -> ReverseChildrenIterator<Self> {
ReverseChildrenIterator {
fn rev_children(self) -> LayoutIterator<ReverseChildrenIterator<Self>> {
LayoutIterator(ReverseChildrenIterator {
current: self.last_child(),
}
})
}

fn traverse_preorder(self) -> TreeIterator<Self> {
@@ -169,7 +169,7 @@ pub trait ThreadSafeLayoutNode: Clone + Copy + NodeInfo + PartialEq + Sized {
fn debug_id(self) -> usize;

/// Returns an iterator over this node's children.
fn children(&self) -> Self::ChildrenIterator;
fn children(&self) -> LayoutIterator<Self::ChildrenIterator>;

/// If this is an element, accesses the element data. Fails if this is not an element node.
#[inline]
@@ -73,6 +73,14 @@ pub trait NodeInfo {
fn is_text_node(&self) -> bool;
}

pub struct LayoutIterator<T>(pub T);
impl<T, I> Iterator for LayoutIterator<T> where T: Iterator<Item=I>, I: NodeInfo {
type Item = I;
fn next(&mut self) -> Option<I> {
self.0.next()
}
}

pub trait TNode : Sized + Copy + Clone + NodeInfo {
type ConcreteElement: TElement<ConcreteNode = Self, ConcreteDocument = Self::ConcreteDocument>;
type ConcreteDocument: TDocument<ConcreteNode = Self, ConcreteElement = Self::ConcreteElement>;
@@ -87,7 +95,7 @@ pub trait TNode : Sized + Copy + Clone + NodeInfo {
fn dump_style(self);

/// Returns an iterator over this node's children.
fn children(self) -> Self::ConcreteChildrenIterator;
fn children(self) -> LayoutIterator<Self::ConcreteChildrenIterator>;

/// Converts self into an `OpaqueNode`.
fn opaque(&self) -> OpaqueNode;
@@ -39,8 +39,8 @@ use std::ops::BitOr;
use std::ptr;
use std::sync::Arc;
use style::data::PrivateStyleData;
use style::dom::{LayoutIterator, NodeInfo, TDocument, TElement, TNode, TRestyleDamage, UnsafeNode};
use style::dom::{OpaqueNode, PresentationalHintsSynthetizer};
use style::dom::{NodeInfo, TDocument, TElement, TNode, TRestyleDamage, UnsafeNode};
use style::element_state::ElementState;
use style::error_reporting::StdoutErrorReporter;
use style::gecko_selector_impl::{GeckoSelectorImpl, NonTSPseudoClass, PseudoElement};
@@ -161,12 +161,12 @@ impl<'ln> TNode for GeckoNode<'ln> {
unimplemented!()
}

fn children(self) -> GeckoChildrenIterator<'ln> {
fn children(self) -> LayoutIterator<GeckoChildrenIterator<'ln>> {
let maybe_iter = unsafe { Gecko_MaybeCreateStyleChildrenIterator(self.0) };
if let Some(iter) = maybe_iter.into_owned_opt() {
GeckoChildrenIterator::GeckoIterator(iter)
LayoutIterator(GeckoChildrenIterator::GeckoIterator(iter))
} else {
GeckoChildrenIterator::Current(self.first_child())
LayoutIterator(GeckoChildrenIterator::Current(self.first_child()))
}
}

ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.