aboutsummaryrefslogtreecommitdiffstats
path: root/src/construct/partial_space_or_tab_eol.rs
diff options
context:
space:
mode:
authorLibravatar Titus Wormer <tituswormer@gmail.com>2022-08-12 19:04:31 +0200
committerLibravatar Titus Wormer <tituswormer@gmail.com>2022-08-12 19:04:31 +0200
commit395b13daf6dd6da0204302d344caa710ea891d62 (patch)
tree4a7c688af7a70c7e3b694d87ba66e01dd0670cf6 /src/construct/partial_space_or_tab_eol.rs
parent6dc2011d69c85820feddf6799142d304cc2eeb29 (diff)
downloadmarkdown-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/partial_space_or_tab_eol.rs')
-rw-r--r--src/construct/partial_space_or_tab_eol.rs61
1 files changed, 33 insertions, 28 deletions
diff --git a/src/construct/partial_space_or_tab_eol.rs b/src/construct/partial_space_or_tab_eol.rs
index b38bc64..427cb11 100644
--- a/src/construct/partial_space_or_tab_eol.rs
+++ b/src/construct/partial_space_or_tab_eol.rs
@@ -54,21 +54,25 @@ pub fn space_or_tab_eol_with_options(tokenizer: &mut Tokenizer, options: Options
/// | ␠␠b
/// ```
pub fn start(tokenizer: &mut Tokenizer) -> State {
- tokenizer.attempt(
- State::Next(StateName::SpaceOrTabEolAfterFirst),
- State::Next(StateName::SpaceOrTabEolAtEol),
- );
+ if matches!(tokenizer.current, Some(b'\t' | b'\n' | b' ')) {
+ tokenizer.attempt(
+ State::Next(StateName::SpaceOrTabEolAfterFirst),
+ State::Next(StateName::SpaceOrTabEolAtEol),
+ );
- State::Retry(space_or_tab_with_options(
- tokenizer,
- SpaceOrTabOptions {
- kind: Name::SpaceOrTab,
- min: 1,
- max: usize::MAX,
- content: tokenizer.tokenize_state.space_or_tab_eol_content.clone(),
- connect: tokenizer.tokenize_state.space_or_tab_eol_connect,
- },
- ))
+ State::Retry(space_or_tab_with_options(
+ tokenizer,
+ SpaceOrTabOptions {
+ kind: Name::SpaceOrTab,
+ min: 1,
+ max: usize::MAX,
+ content: tokenizer.tokenize_state.space_or_tab_eol_content.clone(),
+ connect: tokenizer.tokenize_state.space_or_tab_eol_connect,
+ },
+ ))
+ } else {
+ State::Nok
+ }
}
/// After initial whitespace, at optional eol.
@@ -151,20 +155,21 @@ pub fn at_eol(tokenizer: &mut Tokenizer) -> State {
/// ^
/// ```
pub fn after_eol(tokenizer: &mut Tokenizer) -> State {
- tokenizer.attempt(
- State::Next(StateName::SpaceOrTabEolAfterMore),
- State::Next(StateName::SpaceOrTabEolAfterMore),
- );
- State::Retry(space_or_tab_with_options(
- tokenizer,
- SpaceOrTabOptions {
- kind: Name::SpaceOrTab,
- min: 1,
- max: usize::MAX,
- content: tokenizer.tokenize_state.space_or_tab_eol_content.clone(),
- connect: tokenizer.tokenize_state.space_or_tab_eol_connect,
- },
- ))
+ if matches!(tokenizer.current, Some(b'\t' | b' ')) {
+ tokenizer.attempt(State::Next(StateName::SpaceOrTabEolAfterMore), State::Nok);
+ State::Retry(space_or_tab_with_options(
+ tokenizer,
+ SpaceOrTabOptions {
+ kind: Name::SpaceOrTab,
+ min: 1,
+ max: usize::MAX,
+ content: tokenizer.tokenize_state.space_or_tab_eol_content.clone(),
+ connect: tokenizer.tokenize_state.space_or_tab_eol_connect,
+ },
+ ))
+ } else {
+ State::Retry(StateName::SpaceOrTabEolAfterMore)
+ }
}
/// After optional final whitespace.