aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/htmlcollection.rs
diff options
context:
space:
mode:
authorCorey Farwell <coreyf@rwell.org>2016-11-02 15:57:12 -0400
committerCorey Farwell <coreyf@rwell.org>2016-11-02 16:53:00 -0400
commit927d44753b249a2716b721d7398f4dc4a208b82f (patch)
treecba2307ecbb74845ed197254596e97286ae47faf /components/script/dom/htmlcollection.rs
parent25e3ae6915bce0446a4bd1b1b89b2f0faaef2e02 (diff)
downloadservo-927d44753b249a2716b721d7398f4dc4a208b82f.tar.gz
servo-927d44753b249a2716b721d7398f4dc4a208b82f.zip
Remove unnecessary `Box` around `HTMLCollectionElementsIter::node_iter`.
Diffstat (limited to 'components/script/dom/htmlcollection.rs')
-rw-r--r--components/script/dom/htmlcollection.rs22
1 files changed, 12 insertions, 10 deletions
diff --git a/components/script/dom/htmlcollection.rs b/components/script/dom/htmlcollection.rs
index 230102bd423..d87230a42dc 100644
--- a/components/script/dom/htmlcollection.rs
+++ b/components/script/dom/htmlcollection.rs
@@ -205,24 +205,24 @@ impl HTMLCollection {
HTMLCollection::create(window, root, box ElementChildFilter)
}
- pub fn elements_iter_after(&self, after: &Node) -> HTMLCollectionElementsIter {
+ pub fn elements_iter_after<'a>(&'a self, after: &'a Node) -> impl Iterator<Item=Root<Element>> + 'a {
// Iterate forwards from a node.
HTMLCollectionElementsIter {
- node_iter: box after.following_nodes(&self.root),
+ node_iter: after.following_nodes(&self.root),
root: Root::from_ref(&self.root),
filter: &self.filter,
}
}
- pub fn elements_iter(&self) -> HTMLCollectionElementsIter {
+ pub fn elements_iter<'a>(&'a self) -> impl Iterator<Item=Root<Element>> + 'a {
// Iterate forwards from the root.
self.elements_iter_after(&*self.root)
}
- pub fn elements_iter_before(&self, before: &Node) -> HTMLCollectionElementsIter {
+ pub fn elements_iter_before<'a>(&'a self, before: &'a Node) -> impl Iterator<Item=Root<Element>> + 'a {
// Iterate backwards from a node.
HTMLCollectionElementsIter {
- node_iter: box before.preceding_nodes(&self.root),
+ node_iter: before.preceding_nodes(&self.root),
root: Root::from_ref(&self.root),
filter: &self.filter,
}
@@ -234,13 +234,13 @@ impl HTMLCollection {
}
// TODO: Make this generic, and avoid code duplication
-pub struct HTMLCollectionElementsIter<'a> {
- node_iter: Box<Iterator<Item = Root<Node>>>,
+struct HTMLCollectionElementsIter<'a, I> {
+ node_iter: I,
root: Root<Node>,
filter: &'a Box<CollectionFilter>,
}
-impl<'a> Iterator for HTMLCollectionElementsIter<'a> {
+impl<'a, I: Iterator<Item=Root<Node>>> Iterator for HTMLCollectionElementsIter<'a, I> {
type Item = Root<Element>;
fn next(&mut self) -> Option<Self::Item> {
@@ -284,13 +284,15 @@ impl HTMLCollectionMethods for HTMLCollection {
// Iterate forwards, starting at the cursor.
let offset = index - (cached_index + 1);
let node: Root<Node> = Root::upcast(element);
- self.set_cached_cursor(index, self.elements_iter_after(&node).nth(offset as usize))
+ let mut iter = self.elements_iter_after(&node);
+ self.set_cached_cursor(index, iter.nth(offset as usize))
} else {
// The cursor is after the element we're looking for
// Iterate backwards, starting at the cursor.
let offset = cached_index - (index + 1);
let node: Root<Node> = Root::upcast(element);
- self.set_cached_cursor(index, self.elements_iter_before(&node).nth(offset as usize))
+ let mut iter = self.elements_iter_before(&node);
+ self.set_cached_cursor(index, iter.nth(offset as usize))
}
} else {
// Cache miss