@@ -222,12 +222,12 @@ impl<'a, 'b> InternalDelphiLogicalLineParser<'a, 'b> {
222222 }
223223 fn parse_structures ( & mut self ) {
224224 while let Some ( token_type) = self . get_current_token_type ( ) {
225- if let Some ( context ) = self . context . get_ending_context ( self ) {
225+ if let Some ( ending_context ) = self . context . get_ending_context_idx ( self ) {
226226 trace ! (
227227 "Context ended, returning from parse_structures with {:?}" ,
228228 token_type
229229 ) ;
230- self . context . update_statuses ( & context ) ;
230+ self . context . update_statuses ( ending_context ) ;
231231 return ;
232232 }
233233 trace ! ( "parse_structures with {:?}" , token_type) ;
@@ -876,12 +876,12 @@ impl<'a, 'b> InternalDelphiLogicalLineParser<'a, 'b> {
876876 fn parse_statement ( & mut self ) {
877877 while let Some ( token_type) = self . get_current_token_type ( ) {
878878 if let Some ( context) = self . get_last_context ( ) {
879- if let Some ( context ) = self . context . get_ending_context ( self ) {
879+ if let Some ( ending_context ) = self . context . get_ending_context_idx ( self ) {
880880 trace ! (
881881 "Context ended, returning from parse_statement with {:?}" ,
882882 token_type
883883 ) ;
884- self . context . update_statuses ( & context ) ;
884+ self . context . update_statuses ( ending_context ) ;
885885 return ;
886886 }
887887 if self . is_at_start_of_line ( ) {
@@ -1229,7 +1229,7 @@ impl<'a, 'b> InternalDelphiLogicalLineParser<'a, 'b> {
12291229 self . finish_logical_line ( ) ;
12301230 // With no unfinished line, this will add the separators to the last child line
12311231 self . take_separators_on_last_line ( ) ;
1232- if self . context . get_ending_context ( self ) . is_some ( )
1232+ if self . context . get_ending_context_idx ( self ) . is_some ( )
12331233 || self . get_current_token_type ( ) . is_none ( )
12341234 {
12351235 // If the parent context above the `Statement` is over, return.
@@ -1750,7 +1750,7 @@ impl<'a, 'b> InternalDelphiLogicalLineParser<'a, 'b> {
17501750 ) {
17511751 while self . get_current_token_type ( ) . is_some ( )
17521752 && !predicate ( self )
1753- && self . context . get_ending_context ( self ) . is_none ( )
1753+ && self . context . get_ending_context_idx ( self ) . is_none ( )
17541754 && matches ! ( next_token_op( self ) , OpResult :: Continue )
17551755 { }
17561756 }
@@ -2120,7 +2120,7 @@ fn predicate_or(a: impl Fn(&LLP) -> bool, b: impl Fn(&LLP) -> bool) -> impl Fn(&
21202120 move |parser| a ( parser) || b ( parser)
21212121}
21222122
2123- #[ derive( Debug , Clone , Copy , PartialEq ) ]
2123+ #[ derive( Debug , Clone , Copy ) ]
21242124enum ContextEndingPredicate {
21252125 Opaque ( fn ( & LLP ) -> bool ) ,
21262126 Transparent ( fn ( & LLP ) -> bool ) ,
@@ -2358,7 +2358,7 @@ impl ParserContextLevel {
23582358 }
23592359}
23602360
2361- #[ derive( Debug , Clone , PartialEq ) ]
2361+ #[ derive( Debug , Clone ) ]
23622362struct ParserContext {
23632363 context_type : ContextType ,
23642364 context_ending_predicate : ContextEndingPredicate ,
@@ -2384,35 +2384,31 @@ impl ParserContexts {
23842384 self . is_ended . pop ( ) ;
23852385 }
23862386
2387- fn get_ending_context ( & self , parser : & LLP ) -> Option < ParserContext > {
2388- for ( context, & is_ended) in self . contexts . iter ( ) . zip ( & self . is_ended ) . rev ( ) {
2387+ fn get_ending_context_idx ( & self , parser : & LLP ) -> Option < usize > {
2388+ for ( idx, ( context, & is_ended) ) in
2389+ self . contexts . iter ( ) . zip ( & self . is_ended ) . enumerate ( ) . rev ( )
2390+ {
23892391 if is_ended {
2390- return Some ( context . clone ( ) ) ;
2392+ return Some ( idx ) ;
23912393 }
23922394 match context. context_ending_predicate {
2393- CEP :: Opaque ( predicate) => {
2394- return if predicate ( parser) {
2395- Some ( context. clone ( ) )
2396- } else {
2397- None
2398- }
2399- }
2395+ CEP :: Opaque ( predicate) => return if predicate ( parser) { Some ( idx) } else { None } ,
24002396 CEP :: Transparent ( predicate) => {
24012397 if predicate ( parser) {
2402- return Some ( context . clone ( ) ) ;
2398+ return Some ( idx ) ;
24032399 }
24042400 }
24052401 }
24062402 }
24072403 None
24082404 }
2409- fn update_statuses ( & mut self , ending_context : & ParserContext ) {
2405+ fn update_statuses ( & mut self , ending_context_idx : usize ) {
24102406 for ( _, is_ended) in self
24112407 . contexts
24122408 . iter ( )
24132409 . zip ( self . is_ended . iter_mut ( ) )
24142410 . rev ( )
2415- . take_while_inclusive ( | ( context , _ ) | * context != ending_context )
2411+ . take ( self . contexts . len ( ) . saturating_sub ( ending_context_idx ) )
24162412 {
24172413 * is_ended = true ;
24182414 }
0 commit comments