diff options
author | Titus Wormer <tituswormer@gmail.com> | 2022-07-21 16:08:38 +0200 |
---|---|---|
committer | Titus Wormer <tituswormer@gmail.com> | 2022-07-21 16:08:38 +0200 |
commit | 1d48e14b70f59bbb3daa5d8dcce176500400965b (patch) | |
tree | 66469437725e5eda518c6b23d31caa9910acc345 /src/construct | |
parent | c43ad9bfb9467627df1b40266ac7b0d570a55a62 (diff) | |
download | markdown-rs-1d48e14b70f59bbb3daa5d8dcce176500400965b.tar.gz markdown-rs-1d48e14b70f59bbb3daa5d8dcce176500400965b.tar.bz2 markdown-rs-1d48e14b70f59bbb3daa5d8dcce176500400965b.zip |
Refactor to improve performance by passing markers around
Diffstat (limited to '')
-rw-r--r-- | src/construct/partial_data.rs | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/src/construct/partial_data.rs b/src/construct/partial_data.rs index ceeb89b..98b1877 100644 --- a/src/construct/partial_data.rs +++ b/src/construct/partial_data.rs @@ -16,11 +16,11 @@ use crate::util::edit_map::EditMap; /// > | abc /// ^ /// ``` -pub fn start(tokenizer: &mut Tokenizer, code: Code, stop: Vec<Code>) -> StateFnResult { +pub fn start(tokenizer: &mut Tokenizer, code: Code, stop: &'static [Code]) -> StateFnResult { if stop.contains(&code) { tokenizer.enter(Token::Data); tokenizer.consume(code); - (State::Fn(Box::new(|t, c| data(t, c, stop))), None) + (State::Fn(Box::new(move |t, c| data(t, c, stop))), None) } else { at_break(tokenizer, code, stop) } @@ -32,14 +32,14 @@ pub fn start(tokenizer: &mut Tokenizer, code: Code, stop: Vec<Code>) -> StateFnR /// > | abc /// ^ /// ``` -fn at_break(tokenizer: &mut Tokenizer, code: Code, stop: Vec<Code>) -> StateFnResult { +fn at_break(tokenizer: &mut Tokenizer, code: Code, stop: &'static [Code]) -> StateFnResult { match code { Code::None => (State::Ok, None), Code::CarriageReturnLineFeed | Code::Char('\n' | '\r') => { tokenizer.enter(Token::LineEnding); tokenizer.consume(code); tokenizer.exit(Token::LineEnding); - (State::Fn(Box::new(|t, c| at_break(t, c, stop))), None) + (State::Fn(Box::new(move |t, c| at_break(t, c, stop))), None) } _ if stop.contains(&code) => { tokenizer.register_resolver("data".to_string(), Box::new(resolve_data)); @@ -58,7 +58,7 @@ fn at_break(tokenizer: &mut Tokenizer, code: Code, stop: Vec<Code>) -> StateFnRe /// > | abc /// ^^^ /// ``` -fn data(tokenizer: &mut Tokenizer, code: Code, stop: Vec<Code>) -> StateFnResult { +fn data(tokenizer: &mut Tokenizer, code: Code, stop: &'static [Code]) -> StateFnResult { let done = match code { Code::None | Code::CarriageReturnLineFeed | Code::Char('\n' | '\r') => true, _ if stop.contains(&code) => true, @@ -70,7 +70,7 @@ fn data(tokenizer: &mut Tokenizer, code: Code, stop: Vec<Code>) -> StateFnResult at_break(tokenizer, code, stop) } else { tokenizer.consume(code); - (State::Fn(Box::new(|t, c| data(t, c, stop))), None) + (State::Fn(Box::new(move |t, c| data(t, c, stop))), None) } } |