Skip to content

Commit 12805c1

Browse files
committed
servo: Merge #17488 - Replace iterator struct with anonymous return iterator type (from frewsxcv:frewsxcv-return-node-list); r=jdm
``` hi servo. it's been some time. here's a pull request. i hope you like it. ``` Source-Repo: https://github.com/servo/servo Source-Revision: bc5e8f89fff9bf1922638b3eb2f4c75148dcad1e UltraBlame original commit: c7135a797d59d6ba87ec006f902c13140ad05f2e
1 parent ee51d1e commit 12805c1

File tree

1 file changed

+3
-20
lines changed

1 file changed

+3
-20
lines changed

servo/components/script/dom/nodelist.rs

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -103,11 +103,9 @@ impl NodeList {
103103
}
104104
}
105105

106-
pub fn iter(&self) -> NodeListIterator {
107-
NodeListIterator {
108-
nodes: self,
109-
offset: 0,
110-
}
106+
pub fn iter<'a>(&'a self) -> impl Iterator<Item=Root<Node>> + 'a {
107+
let len = self.Length();
108+
(0..len).flat_map(move |i| self.Item(i))
111109
}
112110
}
113111

@@ -289,18 +287,3 @@ impl ChildrenList {
289287
self.last_index.set(0u32);
290288
}
291289
}
292-
293-
pub struct NodeListIterator<'a> {
294-
nodes: &'a NodeList,
295-
offset: u32,
296-
}
297-
298-
impl<'a> Iterator for NodeListIterator<'a> {
299-
type Item = Root<Node>;
300-
301-
fn next(&mut self) -> Option<Root<Node>> {
302-
let result = self.nodes.Item(self.offset);
303-
self.offset = self.offset + 1;
304-
result
305-
}
306-
}

0 commit comments

Comments
 (0)