From 39a58ed19af2fd4c27336f7a1f1510cda14dd959 Mon Sep 17 00:00:00 2001 From: Veetaha Date: Sun, 28 Jun 2020 01:30:45 +0300 Subject: [PATCH] Simplify --- crates/rust-analyzer/src/line_endings.rs | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/crates/rust-analyzer/src/line_endings.rs b/crates/rust-analyzer/src/line_endings.rs index 7e6db954e47..9f892f32eab 100644 --- a/crates/rust-analyzer/src/line_endings.rs +++ b/crates/rust-analyzer/src/line_endings.rs @@ -46,19 +46,7 @@ pub(crate) fn normalize(src: String) -> (String, LineEndings) { return (src, LineEndings::Dos); fn find_crlf(src: &[u8]) -> Option { - let mut search_idx = 0; - while let Some(idx) = find_cr(&src[search_idx..]) { - if src[search_idx..].get(idx + 1) != Some(&b'\n') { - search_idx += idx + 1; - continue; - } - return Some(search_idx + idx); - } - None - } - - fn find_cr(src: &[u8]) -> Option { - src.iter().enumerate().find_map(|(idx, &b)| if b == b'\r' { Some(idx) } else { None }) + src.iter().zip(src.iter().skip(1)).position(|it| it == (&b'\r', &b'\n')) } } }