Skip to content

Commit

Permalink
Add an extra lifetime parameter to TElement / TNode
Browse files Browse the repository at this point in the history
This isn't used for anything yet, but it's easier to propagate this
change in a separate commit.
  • Loading branch information
Cameron Zwarich committed Sep 27, 2014
1 parent a2220f1 commit 61ae80e
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 27 deletions.
4 changes: 2 additions & 2 deletions components/layout/wrapper.rs
Expand Up @@ -242,7 +242,7 @@ impl<'ln> LayoutNode<'ln> {
}
}

impl<'ln> TNode<LayoutElement<'ln>> for LayoutNode<'ln> {
impl<'ln> TNode<'ln, LayoutElement<'ln>> for LayoutNode<'ln> {
fn parent_node(&self) -> Option<LayoutNode<'ln>> {
unsafe {
self.node.parent_node_ref().map(|node| self.new_with_this_lifetime(&node))
Expand Down Expand Up @@ -389,7 +389,7 @@ impl<'le> LayoutElement<'le> {
}
}

impl<'le> TElement for LayoutElement<'le> {
impl<'le> TElement<'le> for LayoutElement<'le> {
#[inline]
fn get_local_name<'a>(&'a self) -> &'a Atom {
&self.element.local_name
Expand Down
2 changes: 1 addition & 1 deletion components/script/dom/element.rs
Expand Up @@ -948,7 +948,7 @@ impl<'a> VirtualMethods for JSRef<'a, Element> {
}
}

impl<'a> style::TElement for JSRef<'a, Element> {
impl<'a> style::TElement<'a> for JSRef<'a, Element> {
fn get_attr(&self, namespace: &Namespace, attr: &str) -> Option<&'static str> {
self.get_attribute(namespace.clone(), attr).root().map(|attr| {
unsafe { mem::transmute(attr.deref().value().as_slice()) }
Expand Down
2 changes: 1 addition & 1 deletion components/script/dom/node.rs
Expand Up @@ -2033,7 +2033,7 @@ impl<'a> VirtualMethods for JSRef<'a, Node> {
}
}

impl<'a> style::TNode<JSRef<'a, Element>> for JSRef<'a, Node> {
impl<'a> style::TNode<'a, JSRef<'a, Element>> for JSRef<'a, Node> {
fn parent_node(&self) -> Option<JSRef<'a, Node>> {
(self as &NodeHelpers).parent_node().map(|node| *node.root())
}
Expand Down
4 changes: 2 additions & 2 deletions components/style/node.rs
Expand Up @@ -10,7 +10,7 @@ use servo_util::atom::Atom;
use servo_util::namespace::Namespace;


pub trait TNode<E:TElement> : Clone {
pub trait TNode<'a, E: TElement<'a>> : Clone {
fn parent_node(&self) -> Option<Self>;
/// Name is prefixed to avoid a conflict with TLayoutNode.
fn tnode_first_child(&self) -> Option<Self>;
Expand All @@ -23,7 +23,7 @@ pub trait TNode<E:TElement> : Clone {
fn is_html_element_in_html_document(&self) -> bool;
}

pub trait TElement {
pub trait TElement<'a> {
fn get_attr(&self, namespace: &Namespace, attr: &str) -> Option<&'static str>;
fn get_link(&self) -> Option<&'static str>;
fn get_local_name<'a>(&'a self) -> &'a Atom;
Expand Down
48 changes: 27 additions & 21 deletions components/style/selector_matching.rs
Expand Up @@ -79,8 +79,9 @@ impl SelectorMap {
///
/// Extract matching rules as per node's ID, classes, tag name, etc..
/// Sort the Rules at the end to maintain cascading order.
fn get_all_matching_rules<E:TElement,
N:TNode<E>,
fn get_all_matching_rules<'a,
E:TElement<'a>,
N:TNode<'a, E>,
V:VecLike<DeclarationBlock>>(
&self,
node: &N,
Expand Down Expand Up @@ -147,8 +148,9 @@ impl SelectorMap {
}
}

fn get_matching_rules_from_hash<E:TElement,
N:TNode<E>,
fn get_matching_rules_from_hash<'a,
E:TElement<'a>,
N:TNode<'a, E>,
V:VecLike<DeclarationBlock>>(
node: &N,
parent_bf: &Option<BloomFilter>,
Expand All @@ -165,8 +167,9 @@ impl SelectorMap {
}

/// Adds rules in `rules` that match `node` to the `matching_rules` list.
fn get_matching_rules<E:TElement,
N:TNode<E>,
fn get_matching_rules<'a,
E:TElement<'a>,
N:TNode<'a, E>,
V:VecLike<DeclarationBlock>>(
node: &N,
parent_bf: &Option<BloomFilter>,
Expand Down Expand Up @@ -344,8 +347,9 @@ impl Stylist {
/// The returned boolean indicates whether the style is *shareable*; that is, whether the
/// matched selectors are simple enough to allow the matching logic to be reduced to the logic
/// in `css::matching::PrivateMatchMethods::candidate_element_allows_for_style_sharing`.
pub fn push_applicable_declarations<E:TElement,
N:TNode<E>,
pub fn push_applicable_declarations<'a,
E:TElement<'a>,
N:TNode<'a, E>,
V:VecLike<DeclarationBlock>>(
&self,
element: &N,
Expand Down Expand Up @@ -467,7 +471,7 @@ impl DeclarationBlock {
}
}

pub fn matches<E:TElement, N:TNode<E>>(selector_list: &SelectorList, element: &N, parent_bf: &Option<BloomFilter>) -> bool {
pub fn matches<'a, E:TElement<'a>, N:TNode<'a, E>>(selector_list: &SelectorList, element: &N, parent_bf: &Option<BloomFilter>) -> bool {
get_selector_list_selectors(selector_list).iter().any(|selector|
selector.pseudo_element.is_none() &&
matches_compound_selector(&*selector.compound_selectors, element, parent_bf, &mut false))
Expand All @@ -479,8 +483,9 @@ pub fn matches<E:TElement, N:TNode<E>>(selector_list: &SelectorList, element: &N
/// `shareable` to false unless you are willing to update the style sharing logic. Otherwise things
/// will almost certainly break as nodes will start mistakenly sharing styles. (See the code in
/// `main/css/matching.rs`.)
fn matches_compound_selector<E:TElement,
N:TNode<E>>(
fn matches_compound_selector<'a,
E:TElement<'a>,
N:TNode<'a, E>>(
selector: &CompoundSelector,
element: &N,
parent_bf: &Option<BloomFilter>,
Expand Down Expand Up @@ -544,7 +549,7 @@ enum SelectorMatchingResult {
/// Quickly figures out whether or not the compound selector is worth doing more
/// work on. If the simple selectors don't match, or there's a child selector
/// that does not appear in the bloom parent bloom filter, we can exit early.
fn can_fast_reject<E: TElement, N: TNode<E>>(
fn can_fast_reject<'a, E: TElement<'a>, N: TNode<'a, E>>(
mut selector: &CompoundSelector,
element: &N,
parent_bf: &Option<BloomFilter>,
Expand Down Expand Up @@ -605,8 +610,9 @@ fn can_fast_reject<E: TElement, N: TNode<E>>(
return None;
}

fn matches_compound_selector_internal<E:TElement,
N:TNode<E>>(
fn matches_compound_selector_internal<'a,
E:TElement<'a>,
N:TNode<'a, E>>(
selector: &CompoundSelector,
element: &N,
parent_bf: &Option<BloomFilter>,
Expand Down Expand Up @@ -680,8 +686,8 @@ fn matches_compound_selector_internal<E:TElement,
/// will almost certainly break as nodes will start mistakenly sharing styles. (See the code in
/// `main/css/matching.rs`.)
#[inline]
pub fn matches_simple_selector<E:TElement,
N:TNode<E>>(
pub fn matches_simple_selector<'a, E:TElement<'a>,
N:TNode<'a, E>>(
selector: &SimpleSelector,
element: &N,
shareable: &mut bool)
Expand Down Expand Up @@ -863,8 +869,8 @@ fn url_is_visited(_url: &str) -> bool {

#[inline]
fn matches_generic_nth_child<'a,
E:TElement,
N:TNode<E>>(
E:TElement<'a>,
N:TNode<'a, E>>(
element: &N,
a: i32,
b: i32,
Expand Down Expand Up @@ -919,15 +925,15 @@ fn matches_generic_nth_child<'a,
}

#[inline]
fn matches_root<E:TElement,N:TNode<E>>(element: &N) -> bool {
fn matches_root<'a, E:TElement<'a>,N:TNode<'a, E>>(element: &N) -> bool {
match element.parent_node() {
Some(parent) => parent.is_document(),
None => false
}
}

#[inline]
fn matches_first_child<E:TElement,N:TNode<E>>(element: &N) -> bool {
fn matches_first_child<'a, E:TElement<'a>,N:TNode<'a, E>>(element: &N) -> bool {
let mut node = element.clone();
loop {
match node.prev_sibling() {
Expand All @@ -949,7 +955,7 @@ fn matches_first_child<E:TElement,N:TNode<E>>(element: &N) -> bool {
}

#[inline]
fn matches_last_child<E:TElement,N:TNode<E>>(element: &N) -> bool {
fn matches_last_child<'a, E:TElement<'a>,N:TNode<'a, E>>(element: &N) -> bool {
let mut node = element.clone();
loop {
match node.next_sibling() {
Expand Down

0 comments on commit 61ae80e

Please sign in to comment.