Skip to content

Commit

Permalink
rustdoc: Avoid using Iterator::count() where possible
Browse files Browse the repository at this point in the history
`count()` iterates over the whole collection. Using `len()` instead, or
`.next().is_none()` when comparing to zero, should be faster.
  • Loading branch information
camelid committed Nov 19, 2021
1 parent f4687d5 commit a792234
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/librustdoc/html/markdown.rs
Expand Up @@ -656,7 +656,7 @@ impl<'a, I> Footnotes<'a, I> {
}

fn get_entry(&mut self, key: &str) -> &mut (Vec<Event<'a>>, u16) {
let new_id = self.footnotes.keys().count() + 1;
let new_id = self.footnotes.len() + 1;
let key = key.to_owned();
self.footnotes.entry(key).or_insert((Vec::new(), new_id as u16))
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/passes/unindent_comments.rs
Expand Up @@ -87,7 +87,7 @@ fn unindent_fragments(docs: &mut Vec<DocFragment>) {
};

for fragment in docs {
if fragment.doc.as_str().lines().count() == 0 {
if fragment.doc.as_str().lines().next().is_none() {
continue;
}

Expand Down

0 comments on commit a792234

Please sign in to comment.