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/code_indented.rs | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'src/construct/code_indented.rs') diff --git a/src/construct/code_indented.rs b/src/construct/code_indented.rs index 5805346..cf111f4 100644 --- a/src/construct/code_indented.rs +++ b/src/construct/code_indented.rs @@ -63,7 +63,10 @@ use crate::tokenizer::Tokenizer; /// ``` pub fn start(tokenizer: &mut Tokenizer) -> State { // Do not interrupt paragraphs. - if !tokenizer.interrupt && tokenizer.parse_state.constructs.code_indented { + if !tokenizer.interrupt + && tokenizer.parse_state.constructs.code_indented + && matches!(tokenizer.current, Some(b'\t' | b' ')) + { tokenizer.enter(Name::CodeIndented); tokenizer.attempt(State::Next(StateName::CodeIndentedAtBreak), State::Nok); State::Retry(space_or_tab_min_max(tokenizer, TAB_SIZE, TAB_SIZE)) @@ -158,11 +161,12 @@ pub fn further_start(tokenizer: &mut Tokenizer) -> State { /// ^ /// ``` pub fn further_begin(tokenizer: &mut Tokenizer) -> State { - tokenizer.attempt( - State::Next(StateName::CodeIndentedFurtherAfter), - State::Next(StateName::CodeIndentedFurtherAfter), - ); - State::Retry(space_or_tab(tokenizer)) + if matches!(tokenizer.current, Some(b'\t' | b' ')) { + tokenizer.attempt(State::Next(StateName::CodeIndentedFurtherAfter), State::Nok); + State::Retry(space_or_tab(tokenizer)) + } else { + State::Nok + } } /// After whitespace, not indented enough. -- cgit