Skip to content

Commit d683e22

Browse files
committed
Use u32 more
1 parent 8012acc commit d683e22

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

lib/line-index/src/lib.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ impl WideChar {
6666
}
6767

6868
/// Returns the length in UTF-16 or UTF-32 code units.
69-
fn wide_len(&self, enc: WideEncoding) -> usize {
69+
fn wide_len(&self, enc: WideEncoding) -> u32 {
7070
match enc {
7171
WideEncoding::Utf16 => {
7272
if self.len() == TextSize::from(4) {
@@ -75,7 +75,6 @@ impl WideChar {
7575
1
7676
}
7777
}
78-
7978
WideEncoding::Utf32 => 1,
8079
}
8180
}
@@ -157,20 +156,19 @@ impl LineIndex {
157156

158157
/// Transforms the `LineCol` with the given `WideEncoding` into a `WideLineCol`.
159158
pub fn to_wide(&self, enc: WideEncoding, line_col: LineCol) -> Option<WideLineCol> {
160-
let col: TextSize = line_col.col.into();
161-
let mut res: usize = col.into();
159+
let mut col = line_col.col;
162160
if let Some(wide_chars) = self.line_wide_chars.get(&line_col.line) {
163161
for c in wide_chars.iter() {
164162
if u32::from(c.end) <= line_col.col {
165-
res -= usize::from(c.len()) - c.wide_len(enc);
163+
col -= u32::from(c.len()) - c.wide_len(enc);
166164
} else {
167165
// From here on, all utf16 characters come *after* the character we are mapping,
168166
// so we don't need to take them into account
169167
break;
170168
}
171169
}
172170
}
173-
Some(WideLineCol { line: line_col.line, col: res as u32 })
171+
Some(WideLineCol { line: line_col.line, col })
174172
}
175173

176174
/// Transforms the `WideLineCol` with the given `WideEncoding` into a `LineCol`.

0 commit comments

Comments
 (0)