Skip to content

Commit

Permalink
Switch tokenizer to use a pointer rather than index for position trac…
Browse files Browse the repository at this point in the history
…king.

Fixes #210. Posted for posterity since it seems a regression at least in
some of our benchmarks, and would need more work.
  • Loading branch information
emilio committed Apr 7, 2024
1 parent 8962f5b commit 083acaf
Show file tree
Hide file tree
Showing 3 changed files with 168 additions and 146 deletions.
8 changes: 4 additions & 4 deletions src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ use std::ops::Range;
/// Should only be used with the `Parser` instance it came from.
#[derive(Debug, Clone)]
pub struct ParserState {
pub(crate) position: usize,
pub(crate) current_line_start_position: usize,
pub(crate) position: SourcePosition,
pub(crate) current_line_start_position: SourcePosition,
pub(crate) current_line_number: u32,
pub(crate) at_start_of: Option<BlockType>,
}
Expand All @@ -26,15 +26,15 @@ impl ParserState {
/// The position from the start of the input, counted in UTF-8 bytes.
#[inline]
pub fn position(&self) -> SourcePosition {
SourcePosition(self.position)
self.position
}

/// The line number and column number
#[inline]
pub fn source_location(&self) -> SourceLocation {
SourceLocation {
line: self.current_line_number,
column: (self.position - self.current_line_start_position + 1) as u32,
column: (self.position.0 - self.current_line_start_position.0 + 1) as u32,
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/size_of_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ size_of_test!(token, Token, 32);
size_of_test!(std_cow_str, std::borrow::Cow<'static, str>, 24, 32);
size_of_test!(cow_rc_str, CowRcStr, 16);

size_of_test!(tokenizer, crate::tokenizer::Tokenizer, 72);
size_of_test!(parser_input, crate::parser::ParserInput, 136);
size_of_test!(tokenizer, crate::tokenizer::Tokenizer, 80);
size_of_test!(parser_input, crate::parser::ParserInput, 144);
size_of_test!(parser, crate::parser::Parser, 16);
size_of_test!(source_position, crate::SourcePosition, 8);
size_of_test!(parser_state, crate::ParserState, 24);
Expand Down
Loading

0 comments on commit 083acaf

Please sign in to comment.