diff options
author | Titus Wormer <tituswormer@gmail.com> | 2022-08-12 19:04:31 +0200 |
---|---|---|
committer | Titus Wormer <tituswormer@gmail.com> | 2022-08-12 19:04:31 +0200 |
commit | 395b13daf6dd6da0204302d344caa710ea891d62 (patch) | |
tree | 4a7c688af7a70c7e3b694d87ba66e01dd0670cf6 /src/construct/list.rs | |
parent | 6dc2011d69c85820feddf6799142d304cc2eeb29 (diff) | |
download | markdown-rs-395b13daf6dd6da0204302d344caa710ea891d62.tar.gz markdown-rs-395b13daf6dd6da0204302d344caa710ea891d62.tar.bz2 markdown-rs-395b13daf6dd6da0204302d344caa710ea891d62.zip |
Refactor to attempt less if never needed
Diffstat (limited to 'src/construct/list.rs')
-rw-r--r-- | src/construct/list.rs | 37 |
1 files changed, 24 insertions, 13 deletions
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. |