replace loop with iterators

This commit is contained in:
Aleksey Kladov 2018-10-08 15:46:14 +03:00
parent 86a7ac2d31
commit b642e6c645

View file

@ -148,14 +148,15 @@ impl<'a, S: Sink> EventProcessor<'a, S> {
}
Event::Token {
kind,
mut n_raw_tokens,
n_raw_tokens,
} => {
self.eat_ws();
let mut len = 0.into();
for _ in 0..n_raw_tokens {
len += self.tokens[self.token_pos].len;
}
self.leaf(kind, len, n_raw_tokens as usize);
let n_raw_tokens = n_raw_tokens as usize;
let len = self.tokens[self.token_pos..self.token_pos + n_raw_tokens]
.iter()
.map(|it| it.len)
.sum::<TextUnit>();
self.leaf(kind, len, n_raw_tokens);
}
Event::Error { msg } => self.sink.error(msg, self.text_pos),
}