Skip to content

Commit a792234

Browse files
committed
rustdoc: Avoid using Iterator::count() where possible
`count()` iterates over the whole collection. Using `len()` instead, or `.next().is_none()` when comparing to zero, should be faster.
1 parent f4687d5 commit a792234

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

src/librustdoc/html/markdown.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -656,7 +656,7 @@ impl<'a, I> Footnotes<'a, I> {
656656
}
657657

658658
fn get_entry(&mut self, key: &str) -> &mut (Vec<Event<'a>>, u16) {
659-
let new_id = self.footnotes.keys().count() + 1;
659+
let new_id = self.footnotes.len() + 1;
660660
let key = key.to_owned();
661661
self.footnotes.entry(key).or_insert((Vec::new(), new_id as u16))
662662
}

src/librustdoc/passes/unindent_comments.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ fn unindent_fragments(docs: &mut Vec<DocFragment>) {
8787
};
8888

8989
for fragment in docs {
90-
if fragment.doc.as_str().lines().count() == 0 {
90+
if fragment.doc.as_str().lines().next().is_none() {
9191
continue;
9292
}
9393

0 commit comments

Comments
 (0)