Borrow the context instead of clone it for fewer reference count increments.
This commit is contained in:
parent
9dfca22b86
commit
0bcc3d9dc6
@ -1,6 +1,6 @@
|
|||||||
macro_rules! parser_with_context {
|
macro_rules! parser_with_context {
|
||||||
($target:ident) => {
|
($target:ident) => {
|
||||||
move |context| move |i| $target(&context, i)
|
move |context| move |i| $target(context, i)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
pub(crate) use parser_with_context;
|
pub(crate) use parser_with_context;
|
||||||
|
@ -107,7 +107,7 @@ where
|
|||||||
pub fn document(input: &str) -> Res<&str, Vec<(Vec<TextElement>, &str)>> {
|
pub fn document(input: &str) -> Res<&str, Vec<(Vec<TextElement>, &str)>> {
|
||||||
let initial_context: ContextTree<'_, '_> = ContextTree::new();
|
let initial_context: ContextTree<'_, '_> = ContextTree::new();
|
||||||
let paragraph_parser = parser_with_context!(paragraph);
|
let paragraph_parser = parser_with_context!(paragraph);
|
||||||
let ret = many1(paragraph_parser(initial_context))(input);
|
let ret = many1(paragraph_parser(&initial_context))(input);
|
||||||
ret
|
ret
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -157,8 +157,8 @@ fn flat_text_element<'s, 'r>(
|
|||||||
) -> Res<&'s str, TextElement<'s>> {
|
) -> Res<&'s str, TextElement<'s>> {
|
||||||
not(|i| context.check_fail_matcher(i))(i)?;
|
not(|i| context.check_fail_matcher(i))(i)?;
|
||||||
|
|
||||||
let bold_matcher = parser_with_context!(flat_bold)(context.clone());
|
let bold_matcher = parser_with_context!(flat_bold)(&context);
|
||||||
let link_matcher = parser_with_context!(flat_link)(context.clone());
|
let link_matcher = parser_with_context!(flat_link)(&context);
|
||||||
|
|
||||||
alt((
|
alt((
|
||||||
map(bold_matcher, TextElement::Bold),
|
map(bold_matcher, TextElement::Bold),
|
||||||
@ -177,7 +177,7 @@ fn recognize_bold_end(input: &str) -> Res<&str, &str> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn flat_bold<'s, 'r>(context: Context<'r, 's>, i: &'s str) -> Res<&'s str, Bold<'s>> {
|
fn flat_bold<'s, 'r>(context: Context<'r, 's>, i: &'s str) -> Res<&'s str, Bold<'s>> {
|
||||||
let bold_start = parser_with_context!(context_bold_start)(context.clone());
|
let bold_start = parser_with_context!(context_bold_start)(&context);
|
||||||
let nom_context =
|
let nom_context =
|
||||||
context.with_additional_node(ContextElement::FailMatcherNode(FailMatcherNode {
|
context.with_additional_node(ContextElement::FailMatcherNode(FailMatcherNode {
|
||||||
fail_matcher: ChainBehavior::AndParent(Some(&recognize_bold_end)),
|
fail_matcher: ChainBehavior::AndParent(Some(&recognize_bold_end)),
|
||||||
@ -199,7 +199,7 @@ fn flat_link<'s, 'r>(context: Context<'r, 's>, i: &'s str) -> Res<&'s str, Link<
|
|||||||
fail_matcher: ChainBehavior::AndParent(Some(&recognize_link_end)),
|
fail_matcher: ChainBehavior::AndParent(Some(&recognize_link_end)),
|
||||||
}));
|
}));
|
||||||
// let nom_context = context.with_additional_fail_matcher(&recognize_link_end);
|
// let nom_context = context.with_additional_fail_matcher(&recognize_link_end);
|
||||||
let text_element_parser = parser_with_context!(flat_text_element)(nom_context);
|
let text_element_parser = parser_with_context!(flat_text_element)(&nom_context);
|
||||||
let (remaining, captured) = recognize(tuple((
|
let (remaining, captured) = recognize(tuple((
|
||||||
link_start,
|
link_start,
|
||||||
many_till(text_element_parser, link_end),
|
many_till(text_element_parser, link_end),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user