Skip to content

Commit

Permalink
optimize Tokenizer with unchecked operations
Browse files Browse the repository at this point in the history
  • Loading branch information
gvozdvmozgu committed Oct 15, 2024
1 parent 5b74510 commit 4bcc489
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions crates/mitki-tokenizer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,16 @@ impl<'db> Tokenizer<'db> {
}

fn range(&self) -> TextRange {
let end = self.offset();
let len = self.cursor.pos_within_token();
let end: u32 = self.offset().into();
let len: u32 = self.cursor.pos_within_token().into();
let offset = unsafe { end.unchecked_sub(len) };

TextRange::at(end - len, len)
TextRange::at(offset.into(), len.into())
}

fn text(&self) -> &'db str {
&self.text[self.range()]
let range: std::ops::Range<usize> = self.range().into();
unsafe { self.text.get_unchecked(range) }
}

pub fn next_token(&mut self) -> Token {
Expand Down

0 comments on commit 4bcc489

Please sign in to comment.