From 0eeff9148e327183e532752f46421a75506dd7a6 Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Fri, 29 Jul 2022 18:22:59 +0200 Subject: Refactor to improve states * Remove custom kind wrappers, use plain bytes instead * Remove `Into`s, use the explicit expected types instead * Refactor to use `slice.as_str` in most places * Remove unneeded unique check before adding a definition * Use a shared CDATA prefix in constants * Inline byte checks into matches * Pass bytes back from parser instead of whole parse state * Refactor to work more often on bytes * Rename custom `size` to `len` --- src/construct/label_end.rs | 47 +++++++++++++++++++++++----------------------- 1 file changed, 23 insertions(+), 24 deletions(-) (limited to 'src/construct/label_end.rs') diff --git a/src/construct/label_end.rs b/src/construct/label_end.rs index 6399f81..a1ec8d9 100644 --- a/src/construct/label_end.rs +++ b/src/construct/label_end.rs @@ -214,16 +214,14 @@ pub fn start(tokenizer: &mut Tokenizer) -> State { media: Media { start: label_start.start, end: (label_end_start, label_end_start + 3), - // To do: virtual spaces not needed, create a `to_str`? id: normalize_identifier( - &Slice::from_position( + // We don’t care about virtual spaces, so `indices` and `as_str` are fine. + Slice::from_indices( tokenizer.parse_state.bytes, - &Position { - start: &tokenizer.events[label_start.start.1].point, - end: &tokenizer.events[label_end_start - 1].point, - }, + tokenizer.events[label_start.start.1].point.index, + tokenizer.events[label_end_start - 1].point.index, ) - .serialize(), + .as_str(), ), }, }; @@ -366,11 +364,11 @@ fn ok(tokenizer: &mut Tokenizer, mut info: Info) -> State { /// ^ /// ``` fn nok(tokenizer: &mut Tokenizer, label_start_index: usize) -> State { - let label_start = tokenizer + tokenizer .label_start_stack .get_mut(label_start_index) - .unwrap(); - label_start.balanced = true; + .unwrap() + .balanced = true; State::Nok } @@ -529,23 +527,24 @@ fn full_reference(tokenizer: &mut Tokenizer) -> State { /// ^ /// ``` fn full_reference_after(tokenizer: &mut Tokenizer) -> State { - let end = skip::to_back( - &tokenizer.events, - tokenizer.events.len() - 1, - &[Token::ReferenceString], - ); - - // To do: virtual spaces not needed, create a `to_str`? - let id = Slice::from_position( - tokenizer.parse_state.bytes, - &Position::from_exit_event(&tokenizer.events, end), - ) - .serialize(); - if tokenizer .parse_state .definitions - .contains(&normalize_identifier(&id)) + // We don’t care about virtual spaces, so `as_str` is fine. + .contains(&normalize_identifier( + Slice::from_position( + tokenizer.parse_state.bytes, + &Position::from_exit_event( + &tokenizer.events, + skip::to_back( + &tokenizer.events, + tokenizer.events.len() - 1, + &[Token::ReferenceString], + ), + ), + ) + .as_str(), + )) { State::Ok } else { -- cgit