From 88c944f96b426955933b77ca68c92990734769be Mon Sep 17 00:00:00 2001 From: CAD97 Date: Thu, 12 Mar 2020 22:29:44 -0400 Subject: Remove some TextUnit->usize escapees --- crates/ra_ide_db/src/line_index.rs | 14 +++++++------- crates/ra_ide_db/src/line_index_utils.rs | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) (limited to 'crates/ra_ide_db') diff --git a/crates/ra_ide_db/src/line_index.rs b/crates/ra_ide_db/src/line_index.rs index b9db5c276..8ae745ff2 100644 --- a/crates/ra_ide_db/src/line_index.rs +++ b/crates/ra_ide_db/src/line_index.rs @@ -59,7 +59,7 @@ impl LineIndex { } let char_len = TextUnit::of_char(c); - if char_len.to_usize() > 1 { + if char_len > TextUnit::from_usize(1) { utf16_chars.push(Utf16Char { start: curr_col, end: curr_col + char_len }); } @@ -101,12 +101,12 @@ impl LineIndex { .filter(|it| !it.is_empty()) } - fn utf8_to_utf16_col(&self, line: u32, mut col: TextUnit) -> usize { + fn utf8_to_utf16_col(&self, line: u32, col: TextUnit) -> usize { if let Some(utf16_chars) = self.utf16_lines.get(&line) { - let mut correction = TextUnit::from_usize(0); + let mut correction = 0; for c in utf16_chars { if col >= c.end { - correction += c.len() - TextUnit::from_usize(1); + correction += c.len().to_usize() - 1; } else { // From here on, all utf16 characters come *after* the character we are mapping, // so we don't need to take them into account @@ -114,10 +114,10 @@ impl LineIndex { } } - col -= correction; + col.to_usize() - correction + } else { + col.to_usize() } - - col.to_usize() } fn utf16_to_utf8_col(&self, line: u32, col: u32) -> TextUnit { diff --git a/crates/ra_ide_db/src/line_index_utils.rs b/crates/ra_ide_db/src/line_index_utils.rs index 75a498151..2ebbabdc6 100644 --- a/crates/ra_ide_db/src/line_index_utils.rs +++ b/crates/ra_ide_db/src/line_index_utils.rs @@ -145,7 +145,7 @@ impl Iterator for OffsetStepIter<'_> { Some((next, next_offset)) } else { let char_len = TextUnit::of_char(c); - if char_len.to_usize() > 1 { + if char_len > TextUnit::from_usize(1) { let start = self.offset + TextUnit::from_usize(i); let end = start + char_len; let next = Step::Utf16Char(TextRange::from_to(start, end)); -- cgit v1.2.3