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.
This commit is contained in:
Tom Alexander 2023-08-29 11:14:50 -04:00
parent 8051c3d2b7
commit 27a9b5aeb1
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
7 changed files with 26 additions and 26 deletions

View File

@ -102,7 +102,7 @@ fn global_prefix<'r, 's>(
} }
fn global_prefix_end( 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>, OrgSource<'s>> { ) -> impl for<'r, 's> Fn(Context<'r, 's>, OrgSource<'s>) -> Res<OrgSource<'s>, OrgSource<'s>> {
move |context: Context, input: OrgSource<'_>| { move |context: Context, input: OrgSource<'_>| {
_global_prefix_end(context, input, starting_bracket_depth) _global_prefix_end(context, input, starting_bracket_depth)
@ -113,7 +113,7 @@ fn global_prefix_end(
fn _global_prefix_end<'r, 's>( fn _global_prefix_end<'r, 's>(
context: Context<'r, 's>, context: Context<'r, 's>,
input: OrgSource<'s>, input: OrgSource<'s>,
starting_bracket_depth: i32, starting_bracket_depth: i16,
) -> Res<OrgSource<'s>, OrgSource<'s>> { ) -> Res<OrgSource<'s>, OrgSource<'s>> {
let current_depth = input.get_bracket_depth() - starting_bracket_depth; let current_depth = input.get_bracket_depth() - starting_bracket_depth;
if current_depth < 0 { if current_depth < 0 {
@ -154,7 +154,7 @@ fn global_suffix<'r, 's>(
} }
fn global_suffix_end( 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>, OrgSource<'s>> { ) -> impl for<'r, 's> Fn(Context<'r, 's>, OrgSource<'s>) -> Res<OrgSource<'s>, OrgSource<'s>> {
move |context: Context, input: OrgSource<'_>| { move |context: Context, input: OrgSource<'_>| {
_global_suffix_end(context, input, starting_bracket_depth) _global_suffix_end(context, input, starting_bracket_depth)
@ -165,7 +165,7 @@ fn global_suffix_end(
fn _global_suffix_end<'r, 's>( fn _global_suffix_end<'r, 's>(
context: Context<'r, 's>, context: Context<'r, 's>,
input: OrgSource<'s>, input: OrgSource<'s>,
starting_bracket_depth: i32, starting_bracket_depth: i16,
) -> Res<OrgSource<'s>, OrgSource<'s>> { ) -> Res<OrgSource<'s>, OrgSource<'s>> {
let current_depth = input.get_bracket_depth() - starting_bracket_depth; let current_depth = input.get_bracket_depth() - starting_bracket_depth;
if current_depth < 0 { if current_depth < 0 {

View File

@ -109,7 +109,7 @@ fn key_suffix<'r, 's>(
} }
fn key_prefix_end( 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>, OrgSource<'s>> { ) -> impl for<'r, 's> Fn(Context<'r, 's>, OrgSource<'s>) -> Res<OrgSource<'s>, OrgSource<'s>> {
move |context: Context, input: OrgSource<'_>| { move |context: Context, input: OrgSource<'_>| {
_key_prefix_end(context, input, starting_bracket_depth) _key_prefix_end(context, input, starting_bracket_depth)
@ -120,7 +120,7 @@ fn key_prefix_end(
fn _key_prefix_end<'r, 's>( fn _key_prefix_end<'r, 's>(
context: Context<'r, 's>, context: Context<'r, 's>,
input: OrgSource<'s>, input: OrgSource<'s>,
starting_bracket_depth: i32, starting_bracket_depth: i16,
) -> Res<OrgSource<'s>, OrgSource<'s>> { ) -> Res<OrgSource<'s>, OrgSource<'s>> {
let current_depth = input.get_bracket_depth() - starting_bracket_depth; let current_depth = input.get_bracket_depth() - starting_bracket_depth;
if current_depth < 0 { if current_depth < 0 {
@ -140,7 +140,7 @@ fn _key_prefix_end<'r, 's>(
} }
fn key_suffix_end( 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>, OrgSource<'s>> { ) -> impl for<'r, 's> Fn(Context<'r, 's>, OrgSource<'s>) -> Res<OrgSource<'s>, OrgSource<'s>> {
move |context: Context, input: OrgSource<'_>| { move |context: Context, input: OrgSource<'_>| {
_key_suffix_end(context, input, starting_bracket_depth) _key_suffix_end(context, input, starting_bracket_depth)
@ -151,7 +151,7 @@ fn key_suffix_end(
fn _key_suffix_end<'r, 's>( fn _key_suffix_end<'r, 's>(
_context: Context<'r, 's>, _context: Context<'r, 's>,
input: OrgSource<'s>, input: OrgSource<'s>,
starting_bracket_depth: i32, starting_bracket_depth: i16,
) -> Res<OrgSource<'s>, OrgSource<'s>> { ) -> Res<OrgSource<'s>, OrgSource<'s>> {
let current_depth = input.get_bracket_depth() - starting_bracket_depth; let current_depth = input.get_bracket_depth() - starting_bracket_depth;
if current_depth < 0 { if current_depth < 0 {

View File

@ -121,7 +121,7 @@ fn footnote_reference_only<'r, 's>(
} }
fn footnote_definition_end( 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>, OrgSource<'s>> { ) -> impl for<'r, 's> Fn(Context<'r, 's>, OrgSource<'s>) -> Res<OrgSource<'s>, OrgSource<'s>> {
move |context: Context, input: OrgSource<'_>| { move |context: Context, input: OrgSource<'_>| {
_footnote_definition_end(context, input, starting_bracket_depth) _footnote_definition_end(context, input, starting_bracket_depth)
@ -132,7 +132,7 @@ fn footnote_definition_end(
fn _footnote_definition_end<'r, 's>( fn _footnote_definition_end<'r, 's>(
_context: Context<'r, 's>, _context: Context<'r, 's>,
input: OrgSource<'s>, input: OrgSource<'s>,
starting_bracket_depth: i32, starting_bracket_depth: i16,
) -> Res<OrgSource<'s>, OrgSource<'s>> { ) -> Res<OrgSource<'s>, OrgSource<'s>> {
let current_depth = input.get_bracket_depth() - starting_bracket_depth; let current_depth = input.get_bracket_depth() - starting_bracket_depth;
if current_depth > 0 { if current_depth > 0 {

View File

@ -91,7 +91,7 @@ fn header<'r, 's>(
} }
fn header_end( fn header_end(
starting_bracket_depth: i32, starting_bracket_depth: i16,
) -> impl for<'r, 's> Fn(Context<'r, 's>, OrgSource<'s>) -> Res<OrgSource<'s>, OrgSource<'s>> { ) -> impl for<'r, 's> Fn(Context<'r, 's>, OrgSource<'s>) -> Res<OrgSource<'s>, OrgSource<'s>> {
move |context: Context, input: OrgSource<'_>| { move |context: Context, input: OrgSource<'_>| {
_header_end(context, input, starting_bracket_depth) _header_end(context, input, starting_bracket_depth)
@ -102,7 +102,7 @@ fn header_end(
fn _header_end<'r, 's>( fn _header_end<'r, 's>(
_context: Context<'r, 's>, _context: Context<'r, 's>,
input: OrgSource<'s>, input: OrgSource<'s>,
starting_bracket_depth: i32, starting_bracket_depth: i16,
) -> Res<OrgSource<'s>, OrgSource<'s>> { ) -> Res<OrgSource<'s>, OrgSource<'s>> {
let current_depth = input.get_bracket_depth() - starting_bracket_depth; let current_depth = input.get_bracket_depth() - starting_bracket_depth;
if current_depth > 0 { if current_depth > 0 {
@ -141,7 +141,7 @@ fn argument<'r, 's>(
} }
fn argument_end( fn argument_end(
starting_parenthesis_depth: i32, starting_parenthesis_depth: i16,
) -> impl for<'r, 's> Fn(Context<'r, 's>, OrgSource<'s>) -> Res<OrgSource<'s>, OrgSource<'s>> { ) -> impl for<'r, 's> Fn(Context<'r, 's>, OrgSource<'s>) -> Res<OrgSource<'s>, OrgSource<'s>> {
move |context: Context, input: OrgSource<'_>| { move |context: Context, input: OrgSource<'_>| {
_argument_end(context, input, starting_parenthesis_depth) _argument_end(context, input, starting_parenthesis_depth)
@ -152,7 +152,7 @@ fn argument_end(
fn _argument_end<'r, 's>( fn _argument_end<'r, 's>(
_context: Context<'r, 's>, _context: Context<'r, 's>,
input: OrgSource<'s>, input: OrgSource<'s>,
starting_parenthesis_depth: i32, starting_parenthesis_depth: i16,
) -> Res<OrgSource<'s>, OrgSource<'s>> { ) -> Res<OrgSource<'s>, OrgSource<'s>> {
let current_depth = input.get_parenthesis_depth() - starting_parenthesis_depth; let current_depth = input.get_parenthesis_depth() - starting_parenthesis_depth;
if current_depth > 0 { if current_depth > 0 {

View File

@ -92,7 +92,7 @@ fn header<'r, 's>(
} }
fn header_end( fn header_end(
starting_bracket_depth: i32, starting_bracket_depth: i16,
) -> impl for<'r, 's> Fn(Context<'r, 's>, OrgSource<'s>) -> Res<OrgSource<'s>, OrgSource<'s>> { ) -> impl for<'r, 's> Fn(Context<'r, 's>, OrgSource<'s>) -> Res<OrgSource<'s>, OrgSource<'s>> {
move |context: Context, input: OrgSource<'_>| { move |context: Context, input: OrgSource<'_>| {
_header_end(context, input, starting_bracket_depth) _header_end(context, input, starting_bracket_depth)
@ -103,7 +103,7 @@ fn header_end(
fn _header_end<'r, 's>( fn _header_end<'r, 's>(
_context: Context<'r, 's>, _context: Context<'r, 's>,
input: OrgSource<'s>, input: OrgSource<'s>,
starting_bracket_depth: i32, starting_bracket_depth: i16,
) -> Res<OrgSource<'s>, OrgSource<'s>> { ) -> Res<OrgSource<'s>, OrgSource<'s>> {
let current_depth = input.get_bracket_depth() - starting_bracket_depth; let current_depth = input.get_bracket_depth() - starting_bracket_depth;
if current_depth > 0 { if current_depth > 0 {
@ -152,7 +152,7 @@ fn body<'r, 's>(
} }
fn body_end( fn body_end(
starting_brace_depth: i32, starting_brace_depth: i16,
) -> impl for<'r, 's> Fn(Context<'r, 's>, OrgSource<'s>) -> Res<OrgSource<'s>, OrgSource<'s>> { ) -> impl for<'r, 's> Fn(Context<'r, 's>, OrgSource<'s>) -> Res<OrgSource<'s>, OrgSource<'s>> {
move |context: Context, input: OrgSource<'_>| _body_end(context, input, starting_brace_depth) move |context: Context, input: OrgSource<'_>| _body_end(context, input, starting_brace_depth)
} }
@ -161,7 +161,7 @@ fn body_end(
fn _body_end<'r, 's>( fn _body_end<'r, 's>(
_context: Context<'r, 's>, _context: Context<'r, 's>,
input: OrgSource<'s>, input: OrgSource<'s>,
starting_brace_depth: i32, starting_brace_depth: i16,
) -> Res<OrgSource<'s>, OrgSource<'s>> { ) -> Res<OrgSource<'s>, OrgSource<'s>> {
let current_depth = input.get_brace_depth() - starting_brace_depth; let current_depth = input.get_brace_depth() - starting_brace_depth;
if current_depth > 0 { if current_depth > 0 {

View File

@ -17,10 +17,10 @@ pub struct OrgSource<'s> {
start: usize, start: usize,
end: usize, // exclusive end: usize, // exclusive
start_of_line: usize, start_of_line: usize,
bracket_depth: i16, // []
brace_depth: i16, // {}
parenthesis_depth: i16, // ()
preceding_character: Option<char>, preceding_character: Option<char>,
bracket_depth: i32, // []
brace_depth: i32, // {}
parenthesis_depth: i32, // ()
} }
impl<'s> std::fmt::Debug for OrgSource<'s> { impl<'s> std::fmt::Debug for OrgSource<'s> {
@ -71,15 +71,15 @@ impl<'s> OrgSource<'s> {
self.slice(..(other.start - self.start)) self.slice(..(other.start - self.start))
} }
pub fn get_bracket_depth(&self) -> i32 { pub fn get_bracket_depth(&self) -> i16 {
self.bracket_depth self.bracket_depth
} }
pub fn get_brace_depth(&self) -> i32 { pub fn get_brace_depth(&self) -> i16 {
self.brace_depth self.brace_depth
} }
pub fn get_parenthesis_depth(&self) -> i32 { pub fn get_parenthesis_depth(&self) -> i16 {
self.parenthesis_depth self.parenthesis_depth
} }
} }

View File

@ -170,7 +170,7 @@ fn script_with_braces<'r, 's>(
} }
fn script_with_braces_end( 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>, OrgSource<'s>> { ) -> impl for<'r, 's> Fn(Context<'r, 's>, OrgSource<'s>) -> Res<OrgSource<'s>, OrgSource<'s>> {
move |context: Context, input: OrgSource<'_>| { move |context: Context, input: OrgSource<'_>| {
_script_with_braces_end(context, input, starting_brace_depth) _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>( fn _script_with_braces_end<'r, 's>(
_context: Context<'r, 's>, _context: Context<'r, 's>,
input: OrgSource<'s>, input: OrgSource<'s>,
starting_brace_depth: i32, starting_brace_depth: i16,
) -> Res<OrgSource<'s>, OrgSource<'s>> { ) -> Res<OrgSource<'s>, OrgSource<'s>> {
let current_depth = input.get_brace_depth() - starting_brace_depth; let current_depth = input.get_brace_depth() - starting_brace_depth;
if current_depth > 0 { if current_depth > 0 {