Skip to content

Commit

Permalink
perf: use char_indices
Browse files Browse the repository at this point in the history
  • Loading branch information
SyMind committed Dec 30, 2024
1 parent 43494d3 commit f706b2c
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions src/with_indices.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,20 +62,19 @@ where
// will always lie on UTF-8 sequence boundaries.
self.line.byte_slice_unchecked(byte_index..line_len)
};
for char in slice.chars() {
for (byte_offset, _) in slice.char_indices() {
if char_index == start_char_index {
start_byte_index = Some(byte_index);
start_byte_index = Some(byte_index + byte_offset);
if end_byte_index.is_some() {
break;
}
} else if char_index == end_char_index {
end_byte_index = Some(byte_index);
end_byte_index = Some(byte_index + byte_offset);
self
.last_char_index_to_byte_index
.set((char_index as u32, byte_index as u32));
.set((char_index as u32, (byte_index + byte_offset) as u32));
break;
}
byte_index += char.len_utf8();
char_index += 1;
}
} else {
Expand Down

0 comments on commit f706b2c

Please sign in to comment.