From bfc88c1d1b3fa43d90e209165f02146461f409d4 Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Tue, 29 Aug 2023 11:35:54 -0400 Subject: [PATCH] Use a detect_headline function instead of the full headline parse for the section_end exit matcher. This shaved 2 seconds off the first 800 lines of org-mode/doc/org-guide.org. --- src/parser/document.rs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/parser/document.rs b/src/parser/document.rs index 8fd8624..4d84e5c 100644 --- a/src/parser/document.rs +++ b/src/parser/document.rs @@ -260,11 +260,10 @@ fn section<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn section_end<'r, 's>( - context: Context<'r, 's>, + _context: Context<'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { - let headline_matcher = parser_with_context!(headline)(context); - recognize(headline_matcher)(input) + recognize(detect_headline)(input) } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] @@ -299,6 +298,12 @@ fn heading<'r, 's>( )) } +#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +fn detect_headline<'s>(input: OrgSource<'s>) -> Res, ()> { + tuple((start_of_line, many1(tag("*")), space1))(input)?; + Ok((input, ())) +} + #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn headline<'r, 's>( context: Context<'r, 's>,