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.
This commit is contained in:
Noah Lev 2021-11-18 23:04:51 -05:00
parent f4687d5381
commit a792234388
2 changed files with 2 additions and 2 deletions

View File

@ -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))
}

View File

@ -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;
}