aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/htmlcollection.rs
diff options
context:
space:
mode:
authorbors-servo <lbergstrom+bors@mozilla.com>2016-11-03 16:05:14 -0500
committerGitHub <noreply@github.com>2016-11-03 16:05:14 -0500
commit74a3ea9135b13683a9e223790fe573a46cc6a141 (patch)
tree32cda9fd7fdf158c5f95d73e4d292b741a31c451 /components/script/dom/htmlcollection.rs
parent738f0eb97428f6b24c26df7e64a8328e0575b05c (diff)
parent927d44753b249a2716b721d7398f4dc4a208b82f (diff)
downloadservo-74a3ea9135b13683a9e223790fe573a46cc6a141.tar.gz
servo-74a3ea9135b13683a9e223790fe573a46cc6a141.zip
Auto merge of #14027 - frewsxcv:htmlcollection-iter-refactor, r=emilio
Remove unnecessary `Box` around `HTMLCollectionElementsIter::node_iter`. <!-- Reviewable:start --> This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/14027) <!-- Reviewable:end -->
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 3507ec03fe2..3fd73103107 100644
--- a/components/script/dom/htmlcollection.rs
+++ b/components/script/dom/htmlcollection.rs
@@ -206,24 +206,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,
}
@@ -235,13 +235,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> {
@@ -285,13 +285,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