From 71f54af1ec72e841e8e5b207cdddb19642ab57f9 Mon Sep 17 00:00:00 2001 From: Steve Hancock Date: Thu, 12 Oct 2023 08:07:05 -0700 Subject: [PATCH] avoid needless vertical alignment operations --- lib/Perl/Tidy/Formatter.pm | 36 +++++++++++++++++++++++------------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/lib/Perl/Tidy/Formatter.pm b/lib/Perl/Tidy/Formatter.pm index e08b8808..975e34c5 100644 --- a/lib/Perl/Tidy/Formatter.pm +++ b/lib/Perl/Tidy/Formatter.pm @@ -612,6 +612,7 @@ BEGIN { _rmax_vertical_tightness_ => $i++, _no_vertical_tightness_flags_ => $i++, + _last_vt_type_ => $i++, _LAST_SELF_INDEX_ => $i - 1, }; @@ -1082,6 +1083,7 @@ sub new { $self->[_rmax_vertical_tightness_] = {}; $self->[_no_vertical_tightness_flags_] = 0; + $self->[_last_vt_type_] = 0; # This flag will be updated later by a call to get_save_logfile() $self->[_save_logfile_] = defined($logger_object); @@ -5920,7 +5922,7 @@ EOM # Be sure that sequence numbers start with 2. If not, # there is a programming error in the tokenizer. - if ( $initial_seqno ne 2 ) { + if ( $initial_seqno != 2 ) { Fault(<[_Klimit_]; - my $rLL = $self->[_rLL_]; - my $radjusted_levels = $self->[_radjusted_levels_]; - - return unless ( defined($Klimit) ); + my $rLL = $self->[_rLL_]; + return unless ( @{$rLL} ); # Initialize the adjusted levels to be the structural levels - foreach my $KK ( 0 .. $Klimit ) { - $radjusted_levels->[$KK] = $rLL->[$KK]->[_LEVEL_]; - } + my @adjusted_levels; + foreach ( @{$rLL} ) { push @adjusted_levels, $_->[_LEVEL_] } + $self->[_radjusted_levels_] = \@adjusted_levels; # First set adjusted levels for any non-indenting braces. $self->do_non_indenting_braces(); @@ -31728,9 +31727,21 @@ sub set_vertical_tightness_flags { else { $vt_seqno_end = EMPTY_STRING } } - if ( !defined($vt_seqno) ) { $vt_seqno = EMPTY_STRING } + # Optional simple return if this line is not involved in vertical + # tightness, for efficiency. + my $last_vt_type = $self->[_last_vt_type_]; + $self->[_last_vt_type_] = $vt_type; + if ( !$vt_type + && !$vt_seqno_beg + && !$vt_seqno_end + && !$last_vt_type ) + { + return; + } - my $rvertical_tightness_flags = { + # Otherwise, return the full data structure + if ( !defined($vt_seqno) ) { $vt_seqno = EMPTY_STRING } + return { _vt_type => $vt_type, _vt_opening_flag => $vt_opening_flag, _vt_closing_flag => $vt_closing_flag, @@ -31742,7 +31753,6 @@ sub set_vertical_tightness_flags { _vt_max_lines => $vt_max_lines, }; - return ($rvertical_tightness_flags); } ## end sub set_vertical_tightness_flags ########################################################## -- 2.39.5