From 395b13daf6dd6da0204302d344caa710ea891d62 Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Fri, 12 Aug 2022 19:04:31 +0200 Subject: Refactor to attempt less if never needed --- src/construct/list.rs | 37 ++++++++++++++++++++++++------------- 1 file changed, 24 insertions(+), 13 deletions(-) (limited to 'src/construct/list.rs') diff --git a/src/construct/list.rs b/src/construct/list.rs index 076ff58..596330c 100644 --- a/src/construct/list.rs +++ b/src/construct/list.rs @@ -64,16 +64,21 @@ use crate::util::{ pub fn start(tokenizer: &mut Tokenizer) -> State { if tokenizer.parse_state.constructs.list { tokenizer.enter(Name::ListItem); - tokenizer.attempt(State::Next(StateName::ListBefore), State::Nok); - State::Retry(space_or_tab_min_max( - tokenizer, - 0, - if tokenizer.parse_state.constructs.code_indented { - TAB_SIZE - 1 - } else { - usize::MAX - }, - )) + + if matches!(tokenizer.current, Some(b'\t' | b' ')) { + tokenizer.attempt(State::Next(StateName::ListBefore), State::Nok); + State::Retry(space_or_tab_min_max( + tokenizer, + 0, + if tokenizer.parse_state.constructs.code_indented { + TAB_SIZE - 1 + } else { + usize::MAX + }, + )) + } else { + State::Retry(StateName::ListBefore) + } } else { State::Nok } @@ -319,9 +324,11 @@ pub fn cont_blank(tokenizer: &mut Tokenizer) -> State { if container.blank_initial { State::Nok - } else { + } else if matches!(tokenizer.current, Some(b'\t' | b' ')) { // Consume, optionally, at most `size`. State::Retry(space_or_tab_min_max(tokenizer, 0, size)) + } else { + State::Ok } } @@ -339,8 +346,12 @@ pub fn cont_filled(tokenizer: &mut Tokenizer) -> State { container.blank_initial = false; - // Consume exactly `size`. - State::Retry(space_or_tab_min_max(tokenizer, size, size)) + if matches!(tokenizer.current, Some(b'\t' | b' ')) { + // Consume exactly `size`. + State::Retry(space_or_tab_min_max(tokenizer, size, size)) + } else { + State::Nok + } } /// Find adjacent list items with the same marker. -- cgit