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 { | ||||
|     ($target:ident) => { | ||||
|         move |context| move |i| $target(&context, i) | ||||
|         move |context| move |i| $target(context, i) | ||||
|     }; | ||||
| } | ||||
| pub(crate) use parser_with_context; | ||||
|  | ||||
| @ -107,7 +107,7 @@ where | ||||
| pub fn document(input: &str) -> Res<&str, Vec<(Vec<TextElement>, &str)>> { | ||||
|     let initial_context: ContextTree<'_, '_> = ContextTree::new(); | ||||
|     let paragraph_parser = parser_with_context!(paragraph); | ||||
|     let ret = many1(paragraph_parser(initial_context))(input); | ||||
|     let ret = many1(paragraph_parser(&initial_context))(input); | ||||
|     ret | ||||
| } | ||||
| 
 | ||||
| @ -157,8 +157,8 @@ fn flat_text_element<'s, 'r>( | ||||
| ) -> Res<&'s str, TextElement<'s>> { | ||||
|     not(|i| context.check_fail_matcher(i))(i)?; | ||||
| 
 | ||||
|     let bold_matcher = parser_with_context!(flat_bold)(context.clone()); | ||||
|     let link_matcher = parser_with_context!(flat_link)(context.clone()); | ||||
|     let bold_matcher = parser_with_context!(flat_bold)(&context); | ||||
|     let link_matcher = parser_with_context!(flat_link)(&context); | ||||
| 
 | ||||
|     alt(( | ||||
|         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>> { | ||||
|     let bold_start = parser_with_context!(context_bold_start)(context.clone()); | ||||
|     let bold_start = parser_with_context!(context_bold_start)(&context); | ||||
|     let nom_context = | ||||
|         context.with_additional_node(ContextElement::FailMatcherNode(FailMatcherNode { | ||||
|             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)), | ||||
|         })); | ||||
|     // 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(( | ||||
|         link_start, | ||||
|         many_till(text_element_parser, link_end), | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Tom Alexander
						Tom Alexander