Skip to content

Commit

Permalink
Refactor: convert_offset take owned u32
Browse files Browse the repository at this point in the history
  • Loading branch information
overlookmotel committed Jan 24, 2025
1 parent 7f57ad9 commit 981e5d9
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions crates/oxc_ast/src/utf8_to_utf16.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,18 @@ impl Utf8ToUtf16 {
}

fn convert_span(&self, span: &mut Span) {
self.convert_offset(&mut span.start);
self.convert_offset(&mut span.end);
span.start = self.convert_offset(span.start);
span.end = self.convert_offset(span.end);
}

fn convert_offset(&self, utf8_offset: &mut u32) {
fn convert_offset(&self, utf8_offset: u32) -> u32 {
// FIXME:
let index = self.utf8_offsets.partition_point(|offset| offset < utf8_offset);
if let Some(utf16_difference) = self.utf16_differences.get(index) {
*utf8_offset -= utf16_difference;
let mut utf16_offset = utf8_offset;
let index = self.utf8_offsets.partition_point(|&offset| offset < utf8_offset);
if let Some(&utf16_difference) = self.utf16_differences.get(index) {
utf16_offset -= utf16_difference;
}
utf16_offset
}
}

Expand Down

0 comments on commit 981e5d9

Please sign in to comment.