aboutsummaryrefslogtreecommitdiffstats
path: root/src/construct/label_end.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/label_end.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/label_end.rs')
-rw-r--r--src/construct/label_end.rs44
1 files changed, 29 insertions, 15 deletions
diff --git a/src/construct/label_end.rs b/src/construct/label_end.rs
index 7f80415..8921fcc 100644
--- a/src/construct/label_end.rs
+++ b/src/construct/label_end.rs
@@ -362,11 +362,15 @@ pub fn resource_start(tokenizer: &mut Tokenizer) -> State {
/// ^
/// ```
pub fn resource_before(tokenizer: &mut Tokenizer) -> State {
- tokenizer.attempt(
- State::Next(StateName::LabelEndResourceOpen),
- State::Next(StateName::LabelEndResourceOpen),
- );
- State::Retry(space_or_tab_eol(tokenizer))
+ if matches!(tokenizer.current, Some(b'\t' | b'\n' | b' ')) {
+ tokenizer.attempt(
+ State::Next(StateName::LabelEndResourceOpen),
+ State::Next(StateName::LabelEndResourceOpen),
+ );
+ State::Retry(space_or_tab_eol(tokenizer))
+ } else {
+ State::Retry(StateName::LabelEndResourceOpen)
+ }
}
/// In resource, after optional whitespace, at `)` or a destination.
@@ -407,11 +411,16 @@ pub fn resource_destination_after(tokenizer: &mut Tokenizer) -> State {
tokenizer.tokenize_state.token_4 = Name::Data;
tokenizer.tokenize_state.token_5 = Name::Data;
tokenizer.tokenize_state.size_b = 0;
- tokenizer.attempt(
- State::Next(StateName::LabelEndResourceBetween),
- State::Next(StateName::LabelEndResourceEnd),
- );
- State::Retry(space_or_tab_eol(tokenizer))
+
+ if matches!(tokenizer.current, Some(b'\t' | b'\n' | b' ')) {
+ tokenizer.attempt(
+ State::Next(StateName::LabelEndResourceBetween),
+ State::Next(StateName::LabelEndResourceEnd),
+ );
+ State::Retry(space_or_tab_eol(tokenizer))
+ } else {
+ State::Retry(StateName::LabelEndResourceEnd)
+ }
}
/// At invalid destination.
@@ -462,11 +471,16 @@ pub fn resource_title_after(tokenizer: &mut Tokenizer) -> State {
tokenizer.tokenize_state.token_1 = Name::Data;
tokenizer.tokenize_state.token_2 = Name::Data;
tokenizer.tokenize_state.token_3 = Name::Data;
- tokenizer.attempt(
- State::Next(StateName::LabelEndResourceEnd),
- State::Next(StateName::LabelEndResourceEnd),
- );
- State::Retry(space_or_tab_eol(tokenizer))
+
+ if matches!(tokenizer.current, Some(b'\t' | b'\n' | b' ')) {
+ tokenizer.attempt(
+ State::Next(StateName::LabelEndResourceBetween),
+ State::Next(StateName::LabelEndResourceEnd),
+ );
+ State::Retry(space_or_tab_eol(tokenizer))
+ } else {
+ State::Retry(StateName::LabelEndResourceEnd)
+ }
}
/// In resource, at `)`.