From 1d48e14b70f59bbb3daa5d8dcce176500400965b Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Thu, 21 Jul 2022 16:08:38 +0200 Subject: Refactor to improve performance by passing markers around --- src/construct/partial_data.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'src/construct') 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) -> 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) -> StateFnR /// > | abc /// ^ /// ``` -fn at_break(tokenizer: &mut Tokenizer, code: Code, stop: Vec) -> 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) -> StateFnRe /// > | abc /// ^^^ /// ``` -fn data(tokenizer: &mut Tokenizer, code: Code, stop: Vec) -> 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) -> 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) } } -- cgit