From f7690ff64ba6b97334f1e78edc2e9e7f1743b966 Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Fri, 22 Sep 2023 00:55:10 -0400 Subject: [PATCH] Remove an allocation for lesser block end. --- src/parser/lesser_block.rs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/parser/lesser_block.rs b/src/parser/lesser_block.rs index f899c91..507a851 100644 --- a/src/parser/lesser_block.rs +++ b/src/parser/lesser_block.rs @@ -261,11 +261,10 @@ fn data<'s>(input: OrgSource<'s>) -> Res, OrgSource<'s>> { is_not("\r\n")(input) } -fn lesser_block_end(current_name: &str) -> impl ContextMatcher { - let current_name_lower = current_name.to_lowercase(); - move |context, input: OrgSource<'_>| { - _lesser_block_end(context, input, current_name_lower.as_str()) - } +fn lesser_block_end<'c>(current_name: &'c str) -> impl ContextMatcher + 'c { + // Since the lesser block names are statically defined in code, we can simply assert that the name is lowercase instead of causing an allocation by converting to lowercase. + debug_assert!(current_name == current_name.to_lowercase()); + move |context, input: OrgSource<'_>| _lesser_block_end(context, input, current_name) } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]