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.
This commit is contained in:
Tom Alexander 2023-08-29 11:35:54 -04:00
parent f29720e5b9
commit bfc88c1d1b
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE

View File

@ -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>, 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<OrgSource<'s>, ()> {
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>,