rewrote loop in sub resync_lines_and_tokens
authorSteve Hancock <perltidy@users.sourceforge.net>
Fri, 9 Oct 2020 01:17:38 +0000 (18:17 -0700)
committerSteve Hancock <perltidy@users.sourceforge.net>
Fri, 9 Oct 2020 01:17:38 +0000 (18:17 -0700)
lib/Perl/Tidy/Formatter.pm
lib/Perl/Tidy/VerticalAligner.pm

index 00d795ebb4d3f231c9ef3b5c8f21a5d864a327cf..5b989eb1b3432bd9709d2494a0b3a4615a1556b1 100644 (file)
@@ -5524,14 +5524,6 @@ sub resync_lines_and_tokens {
         $inext = $rLL->[$Knext]->[_LINE_INDEX_];
     }
 
-    my $get_inext = sub {
-        if ( $Knext < 0 || $Knext > $Kmax ) { $inext = undef }
-        else {
-            $inext = $rLL->[$Knext]->[_LINE_INDEX_];
-        }
-        return $inext;
-    };
-
     # Remember the most recently output token index
     my $Klast_out;
 
@@ -5543,11 +5535,17 @@ sub resync_lines_and_tokens {
 
             my @K_array;
             my $rK_range;
-            $inext = $get_inext->();
-            while ( defined($inext) && $inext <= $iline ) {
-                push @{K_array}, $Knext;
-                $Knext += 1;
-                $inext = $get_inext->();
+            if ( $Knext <= $Kmax ) {
+                $inext = $rLL->[$Knext]->[_LINE_INDEX_];
+                while ( $inext <= $iline ) {
+                    push @{K_array}, $Knext;
+                    $Knext += 1;
+                    if ( $Knext > $Kmax ) {
+                        $inext = undef;
+                        last;
+                    }
+                    $inext = $rLL->[$Knext]->[_LINE_INDEX_];
+                }
             }
 
             # Delete any terminal blank token
@@ -6680,8 +6678,8 @@ sub non_indenting_braces {
     };
 
     foreach my $KK ( 0 .. $Kmax ) {
+        my $num = @seqno_stack;
         my $seqno = $rLL->[$KK]->[_TYPE_SEQUENCE_];
-        my $num   = @seqno_stack;
         if ($seqno) {
             my $token = $rLL->[$KK]->[_TOKEN_];
             if ( $token eq '{' && $is_non_indenting_brace->($KK) ) {
@@ -6692,6 +6690,7 @@ sub non_indenting_braces {
                 $num -= 1;
             }
         }
+        next unless $num;
         $radjusted_levels->[$KK] -= $num;
     }
     return;
index d7591fd7531b68572609b2e6d08d743ebf80a2f8..55c3fa96e1c73e40d2a56ad5142297f2226b3a94 100644 (file)
@@ -2438,7 +2438,7 @@ EOM
                 my ( $raw_tok, $lev, $tag, $tok_count ) =
                   decode_alignment_token($tok);
 
-                if ( $tok !~ /^[#]$/ ) {
+                if ( $tok ne '#' ) {
                     if ( !defined($lev_min) ) {
                         $lev_min = $lev;
                         $lev_max = $lev;
@@ -2575,6 +2575,7 @@ EOM
                 if ( $token_line_count{$tok} == $nlines ) {
                     if ( $tok =~ /^\?/ || $tok =~ /^\{\d+if/ ) {
                         $is_full_block = 1;
+                        last;
                     }
                 }
             }
@@ -3879,12 +3880,11 @@ sub combine_fields {
 
 sub get_output_line_number {
 
-    # the output line number reported to a caller is the number of items
-    # written plus the number of items in the buffer
-    my $self               = shift;
-    my $nlines             = $self->group_line_count();
-    my $file_writer_object = $self->[_file_writer_object_];
-    return $nlines + $file_writer_object->get_output_line_number();
+    # The output line number reported to a caller = 
+    # the number of items still in the buffer +
+    # the number of items written.
+    return $_[0]->group_line_count() +
+      $_[0]->[_file_writer_object_]->get_output_line_number();
 }
 
 ###############################