From 0ba84aeb4ecba8e7265e848592376b5291c76de2 Mon Sep 17 00:00:00 2001 From: Steve Hancock Date: Thu, 8 Oct 2020 18:17:38 -0700 Subject: [PATCH] rewrote loop in sub resync_lines_and_tokens --- lib/Perl/Tidy/Formatter.pm | 27 +++++++++++++-------------- lib/Perl/Tidy/VerticalAligner.pm | 14 +++++++------- 2 files changed, 20 insertions(+), 21 deletions(-) diff --git a/lib/Perl/Tidy/Formatter.pm b/lib/Perl/Tidy/Formatter.pm index 00d795eb..5b989eb1 100644 --- a/lib/Perl/Tidy/Formatter.pm +++ b/lib/Perl/Tidy/Formatter.pm @@ -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; diff --git a/lib/Perl/Tidy/VerticalAligner.pm b/lib/Perl/Tidy/VerticalAligner.pm index d7591fd7..55c3fa96 100644 --- a/lib/Perl/Tidy/VerticalAligner.pm +++ b/lib/Perl/Tidy/VerticalAligner.pm @@ -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(); } ############################### -- 2.39.5