Skip to content

Commit 083acaf

Browse files
committed
Switch tokenizer to use a pointer rather than index for position tracking.
Fixes #210. Posted for posterity since it seems a regression at least in some of our benchmarks, and would need more work.
1 parent 8962f5b commit 083acaf

File tree

3 files changed

+168
-146
lines changed

3 files changed

+168
-146
lines changed

src/parser.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ use std::ops::Range;
1616
/// Should only be used with the `Parser` instance it came from.
1717
#[derive(Debug, Clone)]
1818
pub struct ParserState {
19-
pub(crate) position: usize,
20-
pub(crate) current_line_start_position: usize,
19+
pub(crate) position: SourcePosition,
20+
pub(crate) current_line_start_position: SourcePosition,
2121
pub(crate) current_line_number: u32,
2222
pub(crate) at_start_of: Option<BlockType>,
2323
}
@@ -26,15 +26,15 @@ impl ParserState {
2626
/// The position from the start of the input, counted in UTF-8 bytes.
2727
#[inline]
2828
pub fn position(&self) -> SourcePosition {
29-
SourcePosition(self.position)
29+
self.position
3030
}
3131

3232
/// The line number and column number
3333
#[inline]
3434
pub fn source_location(&self) -> SourceLocation {
3535
SourceLocation {
3636
line: self.current_line_number,
37-
column: (self.position - self.current_line_start_position + 1) as u32,
37+
column: (self.position.0 - self.current_line_start_position.0 + 1) as u32,
3838
}
3939
}
4040
}

src/size_of_tests.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ size_of_test!(token, Token, 32);
4242
size_of_test!(std_cow_str, std::borrow::Cow<'static, str>, 24, 32);
4343
size_of_test!(cow_rc_str, CowRcStr, 16);
4444

45-
size_of_test!(tokenizer, crate::tokenizer::Tokenizer, 72);
46-
size_of_test!(parser_input, crate::parser::ParserInput, 136);
45+
size_of_test!(tokenizer, crate::tokenizer::Tokenizer, 80);
46+
size_of_test!(parser_input, crate::parser::ParserInput, 144);
4747
size_of_test!(parser, crate::parser::Parser, 16);
4848
size_of_test!(source_position, crate::SourcePosition, 8);
4949
size_of_test!(parser_state, crate::ParserState, 24);

0 commit comments

Comments
 (0)