From b642e6c6451b21d9b3fc719472a1802ea70a83d8 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Mon, 8 Oct 2018 15:46:14 +0300 Subject: [PATCH] replace loop with iterators --- crates/ra_syntax/src/parser_impl/event.rs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/crates/ra_syntax/src/parser_impl/event.rs b/crates/ra_syntax/src/parser_impl/event.rs index 48f37c57c71..4e6e25cfba2 100644 --- a/crates/ra_syntax/src/parser_impl/event.rs +++ b/crates/ra_syntax/src/parser_impl/event.rs @@ -148,14 +148,15 @@ fn tombstone() -> Event { } 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::(); + self.leaf(kind, len, n_raw_tokens); } Event::Error { msg } => self.sink.error(msg, self.text_pos), }