diff options
author | Titus Wormer <tituswormer@gmail.com> | 2022-07-26 16:37:13 +0200 |
---|---|---|
committer | Titus Wormer <tituswormer@gmail.com> | 2022-07-26 16:37:13 +0200 |
commit | a6b317ac7fbc95b8584056b3cebffbf9d1bba2c6 (patch) | |
tree | fd7be2fe6d7355d3aafaf8b731f0e0b48624debc /src/content/string.rs | |
parent | 297784cb925b1196d89479fa24c898703ae598d6 (diff) | |
download | markdown-rs-a6b317ac7fbc95b8584056b3cebffbf9d1bba2c6.tar.gz markdown-rs-a6b317ac7fbc95b8584056b3cebffbf9d1bba2c6.tar.bz2 markdown-rs-a6b317ac7fbc95b8584056b3cebffbf9d1bba2c6.zip |
Refactor to drastically improve perf around whitespace
Diffstat (limited to 'src/content/string.rs')
-rw-r--r-- | src/content/string.rs | 34 |
1 files changed, 15 insertions, 19 deletions
diff --git a/src/content/string.rs b/src/content/string.rs index 6d45f94..c6c0094 100644 --- a/src/content/string.rs +++ b/src/content/string.rs @@ -14,37 +14,33 @@ use crate::construct::{ character_escape::start as character_escape, character_reference::start as character_reference, - partial_data::start as data, partial_whitespace::whitespace, + partial_data::start as data, partial_whitespace::create_resolve_whitespace, }; use crate::tokenizer::{Code, State, Tokenizer}; -const MARKERS: [Code; 5] = [ - Code::VirtualSpace, // `whitespace` - Code::Char('\t'), // `whitespace` - Code::Char(' '), // `hard_break_trailing`, `whitespace` - Code::Char('&'), - Code::Char('\\'), -]; +const MARKERS: [Code; 2] = [Code::Char('&'), Code::Char('\\')]; -/// Before string. +/// Start of string. pub fn start(tokenizer: &mut Tokenizer) -> State { + tokenizer.register_resolver( + "whitespace".to_string(), + Box::new(create_resolve_whitespace(false, false)), + ); + before(tokenizer) +} + +/// Before string. +fn before(tokenizer: &mut Tokenizer) -> State { match tokenizer.current { Code::None => State::Ok, _ => tokenizer.attempt_n( - vec![ - Box::new(character_reference), - Box::new(character_escape), - Box::new(whitespace), - ], - |ok| { - let func = if ok { start } else { before_data }; - Box::new(func) - }, + vec![Box::new(character_reference), Box::new(character_escape)], + |ok| Box::new(if ok { before } else { before_data }), )(tokenizer), } } /// At data. fn before_data(tokenizer: &mut Tokenizer) -> State { - tokenizer.go(|t| data(t, &MARKERS), start)(tokenizer) + tokenizer.go(|t| data(t, &MARKERS), before)(tokenizer) } |