diff options
author | Titus Wormer <tituswormer@gmail.com> | 2022-07-25 15:29:11 +0200 |
---|---|---|
committer | Titus Wormer <tituswormer@gmail.com> | 2022-07-25 15:29:11 +0200 |
commit | 11304728b6607bc2a8d41a640308f3379a25b933 (patch) | |
tree | c49fb64a64e1c39b889a40f48dcd44f87aaea7b1 /src/construct | |
parent | 9c18ff7858730f0c7782206129375c7efcb7d77f (diff) | |
download | markdown-rs-11304728b6607bc2a8d41a640308f3379a25b933.tar.gz markdown-rs-11304728b6607bc2a8d41a640308f3379a25b933.tar.bz2 markdown-rs-11304728b6607bc2a8d41a640308f3379a25b933.zip |
Improve performance w/ a single feed loop
Diffstat (limited to '')
-rw-r--r-- | src/construct/attention.rs | 2 | ||||
-rw-r--r-- | src/construct/blank_line.rs | 4 | ||||
-rw-r--r-- | src/construct/block_quote.rs | 2 | ||||
-rw-r--r-- | src/construct/code_fenced.rs | 6 | ||||
-rw-r--r-- | src/construct/code_indented.rs | 8 | ||||
-rw-r--r-- | src/construct/code_text.rs | 2 | ||||
-rw-r--r-- | src/construct/definition.rs | 6 | ||||
-rw-r--r-- | src/construct/hard_break_escape.rs | 2 | ||||
-rw-r--r-- | src/construct/hard_break_trailing.rs | 2 | ||||
-rw-r--r-- | src/construct/heading_atx.rs | 2 | ||||
-rw-r--r-- | src/construct/heading_setext.rs | 2 | ||||
-rw-r--r-- | src/construct/html_flow.rs | 4 | ||||
-rw-r--r-- | src/construct/label_end.rs | 8 | ||||
-rw-r--r-- | src/construct/list.rs | 10 | ||||
-rw-r--r-- | src/construct/paragraph.rs | 2 | ||||
-rw-r--r-- | src/construct/partial_data.rs | 2 | ||||
-rw-r--r-- | src/construct/partial_destination.rs | 4 | ||||
-rw-r--r-- | src/construct/partial_non_lazy_continuation.rs | 4 | ||||
-rw-r--r-- | src/construct/partial_space_or_tab.rs | 8 | ||||
-rw-r--r-- | src/construct/partial_whitespace.rs | 4 | ||||
-rw-r--r-- | src/construct/thematic_break.rs | 2 |
21 files changed, 41 insertions, 45 deletions
diff --git a/src/construct/attention.rs b/src/construct/attention.rs index 1aa25c0..eb93810 100644 --- a/src/construct/attention.rs +++ b/src/construct/attention.rs @@ -193,7 +193,7 @@ fn inside(tokenizer: &mut Tokenizer, code: Code, marker: MarkerKind) -> State { _ => { tokenizer.exit(Token::AttentionSequence); tokenizer.register_resolver("attention".to_string(), Box::new(resolve_attention)); - State::Ok(if matches!(code, Code::None) { 0 } else { 1 }) + State::Ok(0) } } } diff --git a/src/construct/blank_line.rs b/src/construct/blank_line.rs index 1121b81..dc36784 100644 --- a/src/construct/blank_line.rs +++ b/src/construct/blank_line.rs @@ -59,9 +59,7 @@ pub fn start(tokenizer: &mut Tokenizer, code: Code) -> State { /// ``` fn after(_tokenizer: &mut Tokenizer, code: Code) -> State { match code { - Code::None | Code::CarriageReturnLineFeed | Code::Char('\n' | '\r') => { - State::Ok(if matches!(code, Code::None) { 0 } else { 1 }) - } + Code::None | Code::CarriageReturnLineFeed | Code::Char('\n' | '\r') => State::Ok(0), _ => State::Nok, } } diff --git a/src/construct/block_quote.rs b/src/construct/block_quote.rs index da21add..9925a5a 100644 --- a/src/construct/block_quote.rs +++ b/src/construct/block_quote.rs @@ -128,7 +128,7 @@ fn cont_after(tokenizer: &mut Tokenizer, code: Code) -> State { } _ => { tokenizer.exit(Token::BlockQuotePrefix); - State::Ok(if matches!(code, Code::None) { 0 } else { 1 }) + State::Ok(0) } } } diff --git a/src/construct/code_fenced.rs b/src/construct/code_fenced.rs index 3923ba0..a814142 100644 --- a/src/construct/code_fenced.rs +++ b/src/construct/code_fenced.rs @@ -506,7 +506,7 @@ fn close_sequence_after(tokenizer: &mut Tokenizer, code: Code) -> State { match code { Code::None | Code::CarriageReturnLineFeed | Code::Char('\n' | '\r') => { tokenizer.exit(Token::CodeFencedFence); - State::Ok(if matches!(code, Code::None) { 0 } else { 1 }) + State::Ok(0) } _ => State::Nok, } @@ -589,11 +589,11 @@ fn content_continue(tokenizer: &mut Tokenizer, code: Code, info: Info) -> State /// > | ~~~ /// ^ /// ``` -fn after(tokenizer: &mut Tokenizer, code: Code) -> State { +fn after(tokenizer: &mut Tokenizer, _code: Code) -> State { tokenizer.exit(Token::CodeFenced); // Feel free to interrupt. tokenizer.interrupt = false; // No longer concrete. tokenizer.concrete = false; - State::Ok(if matches!(code, Code::None) { 0 } else { 1 }) + State::Ok(0) } diff --git a/src/construct/code_indented.rs b/src/construct/code_indented.rs index 512a816..6c528ff 100644 --- a/src/construct/code_indented.rs +++ b/src/construct/code_indented.rs @@ -115,11 +115,11 @@ fn content(tokenizer: &mut Tokenizer, code: Code) -> State { /// > | aaa /// ^ /// ``` -fn after(tokenizer: &mut Tokenizer, code: Code) -> State { +fn after(tokenizer: &mut Tokenizer, _code: Code) -> State { tokenizer.exit(Token::CodeIndented); // Feel free to interrupt. tokenizer.interrupt = false; - State::Ok(if matches!(code, Code::None) { 0 } else { 1 }) + State::Ok(0) } /// Right at a line ending, trying to parse another indent. @@ -154,8 +154,8 @@ fn further_start(tokenizer: &mut Tokenizer, code: Code) -> State { /// > | bbb /// ^ /// ``` -fn further_end(_tokenizer: &mut Tokenizer, code: Code) -> State { - State::Ok(if matches!(code, Code::None) { 0 } else { 1 }) +fn further_end(_tokenizer: &mut Tokenizer, _code: Code) -> State { + State::Ok(0) } /// At the beginning of a line that is not indented enough. diff --git a/src/construct/code_text.rs b/src/construct/code_text.rs index e68d489..451ef45 100644 --- a/src/construct/code_text.rs +++ b/src/construct/code_text.rs @@ -190,7 +190,7 @@ fn sequence_close(tokenizer: &mut Tokenizer, code: Code, size_open: usize, size: _ if size_open == size => { tokenizer.exit(Token::CodeTextSequence); tokenizer.exit(Token::CodeText); - State::Ok(if matches!(code, Code::None) { 0 } else { 1 }) + State::Ok(0) } _ => { let index = tokenizer.events.len(); diff --git a/src/construct/definition.rs b/src/construct/definition.rs index 9e43d18..766bd8a 100644 --- a/src/construct/definition.rs +++ b/src/construct/definition.rs @@ -237,7 +237,7 @@ fn after_whitespace(tokenizer: &mut Tokenizer, code: Code) -> State { tokenizer.exit(Token::Definition); // You’d be interrupting. tokenizer.interrupt = true; - State::Ok(if matches!(code, Code::None) { 0 } else { 1 }) + State::Ok(0) } _ => State::Nok, } @@ -297,9 +297,7 @@ fn title_after(tokenizer: &mut Tokenizer, code: Code) -> State { /// ``` fn title_after_after_optional_whitespace(_tokenizer: &mut Tokenizer, code: Code) -> State { match code { - Code::None | Code::CarriageReturnLineFeed | Code::Char('\n' | '\r') => { - State::Ok(if matches!(code, Code::None) { 0 } else { 1 }) - } + Code::None | Code::CarriageReturnLineFeed | Code::Char('\n' | '\r') => State::Ok(0), _ => State::Nok, } } diff --git a/src/construct/hard_break_escape.rs b/src/construct/hard_break_escape.rs index 617b0ce..2ac693e 100644 --- a/src/construct/hard_break_escape.rs +++ b/src/construct/hard_break_escape.rs @@ -74,7 +74,7 @@ fn inside(tokenizer: &mut Tokenizer, code: Code) -> State { match code { Code::CarriageReturnLineFeed | Code::Char('\n' | '\r') => { tokenizer.exit(Token::HardBreakEscape); - State::Ok(if matches!(code, Code::None) { 0 } else { 1 }) + State::Ok(0) } _ => State::Nok, } diff --git a/src/construct/hard_break_trailing.rs b/src/construct/hard_break_trailing.rs index 8ce4201..35097ec 100644 --- a/src/construct/hard_break_trailing.rs +++ b/src/construct/hard_break_trailing.rs @@ -81,7 +81,7 @@ fn inside(tokenizer: &mut Tokenizer, code: Code, size: usize) -> State { { tokenizer.exit(Token::HardBreakTrailingSpace); tokenizer.exit(Token::HardBreakTrailing); - State::Ok(if matches!(code, Code::None) { 0 } else { 1 }) + State::Ok(0) } _ => State::Nok, } diff --git a/src/construct/heading_atx.rs b/src/construct/heading_atx.rs index 1eabb56..4ef1192 100644 --- a/src/construct/heading_atx.rs +++ b/src/construct/heading_atx.rs @@ -134,7 +134,7 @@ fn at_break(tokenizer: &mut Tokenizer, code: Code) -> State { tokenizer.register_resolver("heading_atx".to_string(), Box::new(resolve)); // Feel free to interrupt. tokenizer.interrupt = false; - State::Ok(if matches!(code, Code::None) { 0 } else { 1 }) + State::Ok(0) } Code::VirtualSpace | Code::Char('\t' | ' ') => { tokenizer.go(space_or_tab(), at_break)(tokenizer, code) diff --git a/src/construct/heading_setext.rs b/src/construct/heading_setext.rs index 7aa0054..83c41e2 100644 --- a/src/construct/heading_setext.rs +++ b/src/construct/heading_setext.rs @@ -189,7 +189,7 @@ fn after(tokenizer: &mut Tokenizer, code: Code) -> State { // Feel free to interrupt. tokenizer.interrupt = false; tokenizer.register_resolver("heading_setext".to_string(), Box::new(resolve)); - State::Ok(if matches!(code, Code::None) { 0 } else { 1 }) + State::Ok(0) } _ => State::Nok, } diff --git a/src/construct/html_flow.rs b/src/construct/html_flow.rs index 7a7c25f..add2308 100644 --- a/src/construct/html_flow.rs +++ b/src/construct/html_flow.rs @@ -924,13 +924,13 @@ fn continuation_close(tokenizer: &mut Tokenizer, code: Code, info: Info) -> Stat /// > | <!doctype> /// ^ /// ``` -fn continuation_after(tokenizer: &mut Tokenizer, code: Code) -> State { +fn continuation_after(tokenizer: &mut Tokenizer, _code: Code) -> State { tokenizer.exit(Token::HtmlFlow); // Feel free to interrupt. tokenizer.interrupt = false; // No longer concrete. tokenizer.concrete = false; - State::Ok(if matches!(code, Code::None) { 0 } else { 1 }) + State::Ok(0) } /// Before a line ending, expecting a blank line. diff --git a/src/construct/label_end.rs b/src/construct/label_end.rs index 35dfcdf..13af833 100644 --- a/src/construct/label_end.rs +++ b/src/construct/label_end.rs @@ -320,7 +320,7 @@ fn reference_not_full(tokenizer: &mut Tokenizer, code: Code, info: Info) -> Stat /// > | [a] b /// ^ /// ``` -fn ok(tokenizer: &mut Tokenizer, code: Code, mut info: Info) -> State { +fn ok(tokenizer: &mut Tokenizer, _code: Code, mut info: Info) -> State { // Remove this one and everything after it. let mut left = tokenizer .label_start_stack @@ -345,7 +345,7 @@ fn ok(tokenizer: &mut Tokenizer, code: Code, mut info: Info) -> State { info.media.end.1 = tokenizer.events.len() - 1; tokenizer.media_list.push(info.media); tokenizer.register_resolver_before("media".to_string(), Box::new(resolve_media)); - State::Ok(if matches!(code, Code::None) { 0 } else { 1 }) + State::Ok(0) } /// Done, it’s nothing. @@ -526,7 +526,7 @@ fn full_reference(tokenizer: &mut Tokenizer, code: Code) -> State { /// > | [a][b] d /// ^ /// ``` -fn full_reference_after(tokenizer: &mut Tokenizer, code: Code) -> State { +fn full_reference_after(tokenizer: &mut Tokenizer, _code: Code) -> State { let events = &tokenizer.events; let mut index = events.len() - 1; let mut start: Option<usize> = None; @@ -558,7 +558,7 @@ fn full_reference_after(tokenizer: &mut Tokenizer, code: Code) -> State { false, ))) { - State::Ok(if matches!(code, Code::None) { 0 } else { 1 }) + State::Ok(0) } else { State::Nok } diff --git a/src/construct/list.rs b/src/construct/list.rs index 7437d4a..ae3fc34 100644 --- a/src/construct/list.rs +++ b/src/construct/list.rs @@ -276,7 +276,7 @@ fn whitespace_after(_tokenizer: &mut Tokenizer, code: Code) -> State { if matches!(code, Code::VirtualSpace | Code::Char('\t' | ' ')) { State::Nok } else { - State::Ok(if matches!(code, Code::None) { 0 } else { 1 }) + State::Ok(0) } } @@ -304,7 +304,7 @@ fn prefix_other(tokenizer: &mut Tokenizer, code: Code) -> State { /// > | * a /// ^ /// ``` -fn after(tokenizer: &mut Tokenizer, code: Code, blank: bool) -> State { +fn after(tokenizer: &mut Tokenizer, _code: Code, blank: bool) -> State { if blank && tokenizer.interrupt { State::Nok } else { @@ -322,7 +322,7 @@ fn after(tokenizer: &mut Tokenizer, code: Code, blank: bool) -> State { tokenizer.exit(Token::ListItemPrefix); tokenizer.register_resolver_before("list_item".to_string(), Box::new(resolve_list_item)); - State::Ok(if matches!(code, Code::None) { 0 } else { 1 }) + State::Ok(0) } } @@ -377,8 +377,8 @@ pub fn not_blank_cont(tokenizer: &mut Tokenizer, code: Code) -> State { } /// A state fn to yield [`State::Ok`]. -pub fn ok(_tokenizer: &mut Tokenizer, code: Code) -> State { - State::Ok(if matches!(code, Code::None) { 0 } else { 1 }) +pub fn ok(_tokenizer: &mut Tokenizer, _code: Code) -> State { + State::Ok(0) } /// A state fn to yield [`State::Nok`]. diff --git a/src/construct/paragraph.rs b/src/construct/paragraph.rs index 5409532..bc980b2 100644 --- a/src/construct/paragraph.rs +++ b/src/construct/paragraph.rs @@ -69,7 +69,7 @@ fn inside(tokenizer: &mut Tokenizer, code: Code) -> State { tokenizer.register_resolver_before("paragraph".to_string(), Box::new(resolve)); // You’d be interrupting. tokenizer.interrupt = true; - State::Ok(if matches!(code, Code::None) { 0 } else { 1 }) + State::Ok(0) } _ => { tokenizer.consume(code); diff --git a/src/construct/partial_data.rs b/src/construct/partial_data.rs index d60ef36..ce10763 100644 --- a/src/construct/partial_data.rs +++ b/src/construct/partial_data.rs @@ -42,7 +42,7 @@ fn at_break(tokenizer: &mut Tokenizer, code: Code, stop: &'static [Code]) -> Sta } _ if stop.contains(&code) => { tokenizer.register_resolver("data".to_string(), Box::new(resolve_data)); - State::Ok(if matches!(code, Code::None) { 0 } else { 1 }) + State::Ok(0) } _ => { tokenizer.enter(Token::Data); diff --git a/src/construct/partial_destination.rs b/src/construct/partial_destination.rs index f898eb5..4a43ec2 100644 --- a/src/construct/partial_destination.rs +++ b/src/construct/partial_destination.rs @@ -224,7 +224,7 @@ fn raw(tokenizer: &mut Tokenizer, code: Code, mut info: Info) -> State { tokenizer.exit(info.options.string.clone()); tokenizer.exit(info.options.raw.clone()); tokenizer.exit(info.options.destination); - State::Ok(if matches!(code, Code::None) { 0 } else { 1 }) + State::Ok(0) } else { tokenizer.consume(code); info.balance -= 1; @@ -242,7 +242,7 @@ fn raw(tokenizer: &mut Tokenizer, code: Code, mut info: Info) -> State { tokenizer.exit(info.options.string.clone()); tokenizer.exit(info.options.raw.clone()); tokenizer.exit(info.options.destination); - State::Ok(if matches!(code, Code::None) { 0 } else { 1 }) + State::Ok(0) } } Code::Char(char) if char.is_ascii_control() => State::Nok, diff --git a/src/construct/partial_non_lazy_continuation.rs b/src/construct/partial_non_lazy_continuation.rs index c6ac493..62e8989 100644 --- a/src/construct/partial_non_lazy_continuation.rs +++ b/src/construct/partial_non_lazy_continuation.rs @@ -39,10 +39,10 @@ pub fn start(tokenizer: &mut Tokenizer, code: Code) -> State { /// > | b /// ^ /// ``` -fn after(tokenizer: &mut Tokenizer, code: Code) -> State { +fn after(tokenizer: &mut Tokenizer, _code: Code) -> State { if tokenizer.lazy { State::Nok } else { - State::Ok(if matches!(code, Code::None) { 0 } else { 1 }) + State::Ok(0) } } diff --git a/src/construct/partial_space_or_tab.rs b/src/construct/partial_space_or_tab.rs index 6eb3f1d..f13414a 100644 --- a/src/construct/partial_space_or_tab.rs +++ b/src/construct/partial_space_or_tab.rs @@ -149,7 +149,7 @@ fn start(tokenizer: &mut Tokenizer, code: Code, mut info: Info) -> State { } _ => { if info.options.min == 0 { - State::Ok(if matches!(code, Code::None) { 0 } else { 1 }) + State::Ok(0) } else { State::Nok } @@ -173,7 +173,7 @@ fn inside(tokenizer: &mut Tokenizer, code: Code, mut info: Info) -> State { _ => { tokenizer.exit(info.options.kind.clone()); if info.size >= info.options.min { - State::Ok(if matches!(code, Code::None) { 0 } else { 1 }) + State::Ok(0) } else { State::Nok } @@ -204,7 +204,7 @@ fn after_space_or_tab(tokenizer: &mut Tokenizer, code: Code, mut info: EolInfo) tokenizer.exit(Token::LineEnding); State::Fn(Box::new(|t, c| after_eol(t, c, info))) } - _ if info.ok => State::Ok(if matches!(code, Code::None) { 0 } else { 1 }), + _ if info.ok => State::Ok(0), _ => State::Nok, } } @@ -245,6 +245,6 @@ fn after_more_space_or_tab(_tokenizer: &mut Tokenizer, code: Code) -> State { ) { State::Nok } else { - State::Ok(if matches!(code, Code::None) { 0 } else { 1 }) + State::Ok(0) } } diff --git a/src/construct/partial_whitespace.rs b/src/construct/partial_whitespace.rs index 4fc013e..acdd4d1 100644 --- a/src/construct/partial_whitespace.rs +++ b/src/construct/partial_whitespace.rs @@ -57,6 +57,6 @@ fn at_eol(tokenizer: &mut Tokenizer, code: Code) -> State { } /// Fine. -fn ok(_tokenizer: &mut Tokenizer, code: Code) -> State { - State::Ok(if matches!(code, Code::None) { 0 } else { 1 }) +fn ok(_tokenizer: &mut Tokenizer, _code: Code) -> State { + State::Ok(0) } diff --git a/src/construct/thematic_break.rs b/src/construct/thematic_break.rs index 4159146..66edaf8 100644 --- a/src/construct/thematic_break.rs +++ b/src/construct/thematic_break.rs @@ -183,7 +183,7 @@ fn at_break(tokenizer: &mut Tokenizer, code: Code, info: Info) -> State { tokenizer.exit(Token::ThematicBreak); // Feel free to interrupt. tokenizer.interrupt = false; - State::Ok(if matches!(code, Code::None) { 0 } else { 1 }) + State::Ok(0) } Code::Char(char) if char == info.kind.as_char() => { tokenizer.enter(Token::ThematicBreakSequence); |