mirror of
https://github.com/servo/servo.git
synced 2025-08-05 21:50:18 +01:00
Use a simple Temporary value in TreeIterator
This commit is contained in:
parent
c026825e69
commit
e20d997b37
9 changed files with 156 additions and 133 deletions
|
@ -164,12 +164,13 @@ impl HTMLCollection {
|
|||
HTMLCollection::create(window, root, box ElementChildFilter)
|
||||
}
|
||||
|
||||
fn traverse<'a>(root: JSRef<'a, Node>)
|
||||
-> FilterMap<Skip<TreeIterator<'a>>,
|
||||
fn(JSRef<Node>) -> Option<JSRef<Element>>> {
|
||||
fn traverse(root: JSRef<Node>)
|
||||
-> FilterMap<Skip<TreeIterator>,
|
||||
fn(Temporary<Node>) -> Option<Temporary<Element>>> {
|
||||
root.traverse_preorder()
|
||||
.skip(1)
|
||||
.filter_map(ElementCast::to_ref as fn(JSRef<Node>) -> Option<JSRef<Element>>)
|
||||
.filter_map(ElementCast::to_temporary as
|
||||
fn(Temporary<Node>) -> Option<Temporary<Element>>)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -181,7 +182,7 @@ impl<'a> HTMLCollectionMethods for JSRef<'a, HTMLCollection> {
|
|||
CollectionTypeId::Live(ref root, ref filter) => {
|
||||
let root = root.root();
|
||||
HTMLCollection::traverse(root.r())
|
||||
.filter(|element| filter.filter(*element, root.r()))
|
||||
.filter(|element| filter.filter(element.root().r(), root.r()))
|
||||
.count() as u32
|
||||
}
|
||||
}
|
||||
|
@ -198,10 +199,8 @@ impl<'a> HTMLCollectionMethods for JSRef<'a, HTMLCollection> {
|
|||
CollectionTypeId::Live(ref root, ref filter) => {
|
||||
let root = root.root();
|
||||
HTMLCollection::traverse(root.r())
|
||||
.filter(|element| filter.filter(*element, root.r()))
|
||||
.filter(|element| filter.filter(element.root().r(), root.r()))
|
||||
.nth(index)
|
||||
.clone()
|
||||
.map(Temporary::from_rooted)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -224,11 +223,12 @@ impl<'a> HTMLCollectionMethods for JSRef<'a, HTMLCollection> {
|
|||
CollectionTypeId::Live(ref root, ref filter) => {
|
||||
let root = root.root();
|
||||
HTMLCollection::traverse(root.r())
|
||||
.filter(|element| filter.filter(*element, root.r()))
|
||||
.map(|element| element.root())
|
||||
.filter(|element| filter.filter(element.r(), root.r()))
|
||||
.find(|elem| {
|
||||
elem.get_string_attribute(&atom!("name")) == key ||
|
||||
elem.get_string_attribute(&atom!("id")) == key })
|
||||
.map(Temporary::from_rooted)
|
||||
elem.r().get_string_attribute(&atom!("name")) == key ||
|
||||
elem.r().get_string_attribute(&atom!("id")) == key })
|
||||
.map(|elem| Temporary::from_rooted(elem.r()))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue