Skip to content

Commit 2114b21

Browse files
Improve code by using iterator::sum instead of looping
1 parent 851f169 commit 2114b21

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

src/librustdoc/html/highlight.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -921,12 +921,10 @@ fn classify<'src>(
921921
&& let Some(nb_items) = classifier.get_full_ident_path()
922922
{
923923
let start = classifier.byte_pos as usize;
924-
let mut len = 0;
925-
for _ in 0..nb_items {
926-
if let Some((_, text, _)) = classifier.next() {
927-
len += text.len();
928-
}
929-
}
924+
let len: usize = iter::from_fn(|| classifier.next())
925+
.take(nb_items)
926+
.map(|(_, text, _)| text.len())
927+
.sum();
930928
let text = &classifier.src[start..start + len];
931929
classifier.advance(TokenKind::Ident, text, sink, start as u32);
932930
} else if let Some((token, text, before)) = classifier.next() {

0 commit comments

Comments
 (0)