Merge branch 'lesser_block_memory_optimization'
This commit is contained in:
		
						commit
						10aa0956ee
					
				| @ -1,3 +0,0 @@ | ||||
| foo <<bar>> baz | ||||
| 
 | ||||
| lorem << ipsum >> dolar | ||||
| @ -1576,7 +1576,7 @@ fn compare_example_block<'b, 's>( | ||||
|         [], | ||||
|         ( | ||||
|             EmacsField::Required(":value"), | ||||
|             |r| Some(r.contents.as_str()), | ||||
|             |r| Some(&r.contents), | ||||
|             compare_property_quoted_string | ||||
|         ), | ||||
|         ( | ||||
| @ -1654,7 +1654,7 @@ fn compare_export_block<'b, 's>( | ||||
|         ), | ||||
|         ( | ||||
|             EmacsField::Required(":value"), | ||||
|             |r| Some(r.contents.as_str()), | ||||
|             |r| Some(&r.contents), | ||||
|             compare_property_quoted_string | ||||
|         ) | ||||
|     ) { | ||||
| @ -1702,7 +1702,7 @@ fn compare_src_block<'b, 's>( | ||||
|         ), | ||||
|         ( | ||||
|             EmacsField::Required(":value"), | ||||
|             |r| Some(r.contents.as_str()), | ||||
|             |r| Some(&r.contents), | ||||
|             compare_property_quoted_string | ||||
|         ), | ||||
|         ( | ||||
|  | ||||
| @ -1,3 +1,5 @@ | ||||
| use std::borrow::Cow; | ||||
| 
 | ||||
| use nom::branch::alt; | ||||
| use nom::bytes::complete::is_not; | ||||
| use nom::bytes::complete::tag; | ||||
| @ -651,6 +653,11 @@ fn switch_word<'s>(input: OrgSource<'s>) -> Res<OrgSource<'s>, OrgSource<'s>> { | ||||
|     ))(input) | ||||
| } | ||||
| 
 | ||||
| enum ContentState { | ||||
|     Normal, | ||||
|     Modified(String), | ||||
| } | ||||
| 
 | ||||
| #[cfg_attr(
 | ||||
|     feature = "tracing", | ||||
|     tracing::instrument(ret, level = "debug", skip(context)) | ||||
| @ -658,8 +665,8 @@ fn switch_word<'s>(input: OrgSource<'s>) -> Res<OrgSource<'s>, OrgSource<'s>> { | ||||
| pub(crate) fn content<'b, 'g, 'r, 's>( | ||||
|     context: RefContext<'b, 'g, 'r, 's>, | ||||
|     input: OrgSource<'s>, | ||||
| ) -> Res<OrgSource<'s>, String> { | ||||
|     let mut ret = String::new(); | ||||
| ) -> Res<OrgSource<'s>, Cow<'s, str>> { | ||||
|     let mut state = ContentState::Normal; | ||||
|     let mut remaining = input; | ||||
|     let exit_matcher_parser = parser_with_context!(exit_matcher_parser)(context); | ||||
|     loop { | ||||
| @ -669,13 +676,28 @@ pub(crate) fn content<'b, 'g, 'r, 's>( | ||||
| 
 | ||||
|         let (remain, (pre_escape_whitespace, line)) = content_line(remaining)?; | ||||
|         if let Some(val) = pre_escape_whitespace { | ||||
|             ret.push_str(Into::<&str>::into(val)); | ||||
|             if let ContentState::Modified(ref mut ret) = state { | ||||
|                 ret.push_str(Into::<&str>::into(val)); | ||||
|             } else { | ||||
|                 let mut ret = String::new(); | ||||
|                 ret.push_str(Into::<&str>::into(input.get_until(remaining))); | ||||
|                 ret.push_str(Into::<&str>::into(val)); | ||||
|                 state = ContentState::Modified(ret); | ||||
|             } | ||||
|         } | ||||
|         if let ContentState::Modified(ref mut ret) = state { | ||||
|             ret.push_str(line.into()); | ||||
|         } | ||||
|         ret.push_str(line.into()); | ||||
|         remaining = remain; | ||||
|     } | ||||
| 
 | ||||
|     Ok((remaining, ret)) | ||||
|     match state { | ||||
|         ContentState::Normal => Ok(( | ||||
|             remaining, | ||||
|             Cow::Borrowed(Into::<&str>::into(input.get_until(remaining))), | ||||
|         )), | ||||
|         ContentState::Modified(ret) => Ok((remaining, Cow::Owned(ret))), | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] | ||||
|  | ||||
| @ -1,3 +1,5 @@ | ||||
| use std::borrow::Cow; | ||||
| 
 | ||||
| use super::object::Object; | ||||
| use super::AffiliatedKeywords; | ||||
| use super::GetAffiliatedKeywords; | ||||
| @ -59,7 +61,7 @@ pub struct ExampleBlock<'s> { | ||||
|     pub retain_labels: RetainLabels, | ||||
|     pub use_labels: bool, | ||||
|     pub label_format: Option<&'s str>, | ||||
|     pub contents: String, | ||||
|     pub contents: Cow<'s, str>, | ||||
| } | ||||
| 
 | ||||
| #[derive(Debug)] | ||||
| @ -68,7 +70,7 @@ pub struct ExportBlock<'s> { | ||||
|     pub affiliated_keywords: AffiliatedKeywords<'s>, | ||||
|     pub export_type: Option<&'s str>, | ||||
|     pub data: Option<&'s str>, | ||||
|     pub contents: String, | ||||
|     pub contents: Cow<'s, str>, | ||||
| } | ||||
| 
 | ||||
| #[derive(Debug)] | ||||
| @ -83,7 +85,7 @@ pub struct SrcBlock<'s> { | ||||
|     pub retain_labels: RetainLabels, | ||||
|     pub use_labels: bool, | ||||
|     pub label_format: Option<&'s str>, | ||||
|     pub contents: String, | ||||
|     pub contents: Cow<'s, str>, | ||||
| } | ||||
| 
 | ||||
| #[derive(Debug)] | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Tom Alexander
						Tom Alexander