From 27a9b5aeb10b789fb714e0a44aa7165b1e6a30ee Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Tue, 29 Aug 2023 11:14:50 -0400 Subject: [PATCH] Switch to i16 for backet depth count. This is having a measurable performance increase. 32k bracket depth should be enough for any non-malicious document. --- src/parser/citation.rs | 8 ++++---- src/parser/citation_reference.rs | 8 ++++---- src/parser/footnote_reference.rs | 4 ++-- src/parser/inline_babel_call.rs | 8 ++++---- src/parser/inline_source_block.rs | 8 ++++---- src/parser/org_source.rs | 12 ++++++------ src/parser/subscript_and_superscript.rs | 4 ++-- 7 files changed, 26 insertions(+), 26 deletions(-) diff --git a/src/parser/citation.rs b/src/parser/citation.rs index 10c496e..0abb625 100644 --- a/src/parser/citation.rs +++ b/src/parser/citation.rs @@ -102,7 +102,7 @@ fn global_prefix<'r, 's>( } fn global_prefix_end( - starting_bracket_depth: i32, + starting_bracket_depth: i16, ) -> impl for<'r, 's> Fn(Context<'r, 's>, OrgSource<'s>) -> Res, OrgSource<'s>> { move |context: Context, input: OrgSource<'_>| { _global_prefix_end(context, input, starting_bracket_depth) @@ -113,7 +113,7 @@ fn global_prefix_end( fn _global_prefix_end<'r, 's>( context: Context<'r, 's>, input: OrgSource<'s>, - starting_bracket_depth: i32, + starting_bracket_depth: i16, ) -> Res, OrgSource<'s>> { let current_depth = input.get_bracket_depth() - starting_bracket_depth; if current_depth < 0 { @@ -154,7 +154,7 @@ fn global_suffix<'r, 's>( } fn global_suffix_end( - starting_bracket_depth: i32, + starting_bracket_depth: i16, ) -> impl for<'r, 's> Fn(Context<'r, 's>, OrgSource<'s>) -> Res, OrgSource<'s>> { move |context: Context, input: OrgSource<'_>| { _global_suffix_end(context, input, starting_bracket_depth) @@ -165,7 +165,7 @@ fn global_suffix_end( fn _global_suffix_end<'r, 's>( context: Context<'r, 's>, input: OrgSource<'s>, - starting_bracket_depth: i32, + starting_bracket_depth: i16, ) -> Res, OrgSource<'s>> { let current_depth = input.get_bracket_depth() - starting_bracket_depth; if current_depth < 0 { diff --git a/src/parser/citation_reference.rs b/src/parser/citation_reference.rs index a348858..ff560cf 100644 --- a/src/parser/citation_reference.rs +++ b/src/parser/citation_reference.rs @@ -109,7 +109,7 @@ fn key_suffix<'r, 's>( } fn key_prefix_end( - starting_bracket_depth: i32, + starting_bracket_depth: i16, ) -> impl for<'r, 's> Fn(Context<'r, 's>, OrgSource<'s>) -> Res, OrgSource<'s>> { move |context: Context, input: OrgSource<'_>| { _key_prefix_end(context, input, starting_bracket_depth) @@ -120,7 +120,7 @@ fn key_prefix_end( fn _key_prefix_end<'r, 's>( context: Context<'r, 's>, input: OrgSource<'s>, - starting_bracket_depth: i32, + starting_bracket_depth: i16, ) -> Res, OrgSource<'s>> { let current_depth = input.get_bracket_depth() - starting_bracket_depth; if current_depth < 0 { @@ -140,7 +140,7 @@ fn _key_prefix_end<'r, 's>( } fn key_suffix_end( - starting_bracket_depth: i32, + starting_bracket_depth: i16, ) -> impl for<'r, 's> Fn(Context<'r, 's>, OrgSource<'s>) -> Res, OrgSource<'s>> { move |context: Context, input: OrgSource<'_>| { _key_suffix_end(context, input, starting_bracket_depth) @@ -151,7 +151,7 @@ fn key_suffix_end( fn _key_suffix_end<'r, 's>( _context: Context<'r, 's>, input: OrgSource<'s>, - starting_bracket_depth: i32, + starting_bracket_depth: i16, ) -> Res, OrgSource<'s>> { let current_depth = input.get_bracket_depth() - starting_bracket_depth; if current_depth < 0 { diff --git a/src/parser/footnote_reference.rs b/src/parser/footnote_reference.rs index e040dd8..a26610c 100644 --- a/src/parser/footnote_reference.rs +++ b/src/parser/footnote_reference.rs @@ -121,7 +121,7 @@ fn footnote_reference_only<'r, 's>( } fn footnote_definition_end( - starting_bracket_depth: i32, + starting_bracket_depth: i16, ) -> impl for<'r, 's> Fn(Context<'r, 's>, OrgSource<'s>) -> Res, OrgSource<'s>> { move |context: Context, input: OrgSource<'_>| { _footnote_definition_end(context, input, starting_bracket_depth) @@ -132,7 +132,7 @@ fn footnote_definition_end( fn _footnote_definition_end<'r, 's>( _context: Context<'r, 's>, input: OrgSource<'s>, - starting_bracket_depth: i32, + starting_bracket_depth: i16, ) -> Res, OrgSource<'s>> { let current_depth = input.get_bracket_depth() - starting_bracket_depth; if current_depth > 0 { diff --git a/src/parser/inline_babel_call.rs b/src/parser/inline_babel_call.rs index b73064d..c4f2200 100644 --- a/src/parser/inline_babel_call.rs +++ b/src/parser/inline_babel_call.rs @@ -91,7 +91,7 @@ fn header<'r, 's>( } fn header_end( - starting_bracket_depth: i32, + starting_bracket_depth: i16, ) -> impl for<'r, 's> Fn(Context<'r, 's>, OrgSource<'s>) -> Res, OrgSource<'s>> { move |context: Context, input: OrgSource<'_>| { _header_end(context, input, starting_bracket_depth) @@ -102,7 +102,7 @@ fn header_end( fn _header_end<'r, 's>( _context: Context<'r, 's>, input: OrgSource<'s>, - starting_bracket_depth: i32, + starting_bracket_depth: i16, ) -> Res, OrgSource<'s>> { let current_depth = input.get_bracket_depth() - starting_bracket_depth; if current_depth > 0 { @@ -141,7 +141,7 @@ fn argument<'r, 's>( } fn argument_end( - starting_parenthesis_depth: i32, + starting_parenthesis_depth: i16, ) -> impl for<'r, 's> Fn(Context<'r, 's>, OrgSource<'s>) -> Res, OrgSource<'s>> { move |context: Context, input: OrgSource<'_>| { _argument_end(context, input, starting_parenthesis_depth) @@ -152,7 +152,7 @@ fn argument_end( fn _argument_end<'r, 's>( _context: Context<'r, 's>, input: OrgSource<'s>, - starting_parenthesis_depth: i32, + starting_parenthesis_depth: i16, ) -> Res, OrgSource<'s>> { let current_depth = input.get_parenthesis_depth() - starting_parenthesis_depth; if current_depth > 0 { diff --git a/src/parser/inline_source_block.rs b/src/parser/inline_source_block.rs index f70aec4..e07d67d 100644 --- a/src/parser/inline_source_block.rs +++ b/src/parser/inline_source_block.rs @@ -92,7 +92,7 @@ fn header<'r, 's>( } fn header_end( - starting_bracket_depth: i32, + starting_bracket_depth: i16, ) -> impl for<'r, 's> Fn(Context<'r, 's>, OrgSource<'s>) -> Res, OrgSource<'s>> { move |context: Context, input: OrgSource<'_>| { _header_end(context, input, starting_bracket_depth) @@ -103,7 +103,7 @@ fn header_end( fn _header_end<'r, 's>( _context: Context<'r, 's>, input: OrgSource<'s>, - starting_bracket_depth: i32, + starting_bracket_depth: i16, ) -> Res, OrgSource<'s>> { let current_depth = input.get_bracket_depth() - starting_bracket_depth; if current_depth > 0 { @@ -152,7 +152,7 @@ fn body<'r, 's>( } fn body_end( - starting_brace_depth: i32, + starting_brace_depth: i16, ) -> impl for<'r, 's> Fn(Context<'r, 's>, OrgSource<'s>) -> Res, OrgSource<'s>> { move |context: Context, input: OrgSource<'_>| _body_end(context, input, starting_brace_depth) } @@ -161,7 +161,7 @@ fn body_end( fn _body_end<'r, 's>( _context: Context<'r, 's>, input: OrgSource<'s>, - starting_brace_depth: i32, + starting_brace_depth: i16, ) -> Res, OrgSource<'s>> { let current_depth = input.get_brace_depth() - starting_brace_depth; if current_depth > 0 { diff --git a/src/parser/org_source.rs b/src/parser/org_source.rs index 3412ff7..877c556 100644 --- a/src/parser/org_source.rs +++ b/src/parser/org_source.rs @@ -17,10 +17,10 @@ pub struct OrgSource<'s> { start: usize, end: usize, // exclusive start_of_line: usize, + bracket_depth: i16, // [] + brace_depth: i16, // {} + parenthesis_depth: i16, // () preceding_character: Option, - bracket_depth: i32, // [] - brace_depth: i32, // {} - parenthesis_depth: i32, // () } impl<'s> std::fmt::Debug for OrgSource<'s> { @@ -71,15 +71,15 @@ impl<'s> OrgSource<'s> { self.slice(..(other.start - self.start)) } - pub fn get_bracket_depth(&self) -> i32 { + pub fn get_bracket_depth(&self) -> i16 { self.bracket_depth } - pub fn get_brace_depth(&self) -> i32 { + pub fn get_brace_depth(&self) -> i16 { self.brace_depth } - pub fn get_parenthesis_depth(&self) -> i32 { + pub fn get_parenthesis_depth(&self) -> i16 { self.parenthesis_depth } } diff --git a/src/parser/subscript_and_superscript.rs b/src/parser/subscript_and_superscript.rs index a39cd28..93361ab 100644 --- a/src/parser/subscript_and_superscript.rs +++ b/src/parser/subscript_and_superscript.rs @@ -170,7 +170,7 @@ fn script_with_braces<'r, 's>( } fn script_with_braces_end( - starting_brace_depth: i32, + starting_brace_depth: i16, ) -> impl for<'r, 's> Fn(Context<'r, 's>, OrgSource<'s>) -> Res, OrgSource<'s>> { move |context: Context, input: OrgSource<'_>| { _script_with_braces_end(context, input, starting_brace_depth) @@ -181,7 +181,7 @@ fn script_with_braces_end( fn _script_with_braces_end<'r, 's>( _context: Context<'r, 's>, input: OrgSource<'s>, - starting_brace_depth: i32, + starting_brace_depth: i16, ) -> Res, OrgSource<'s>> { let current_depth = input.get_brace_depth() - starting_brace_depth; if current_depth > 0 {