From: Steve Hancock Date: Sat, 28 Nov 2020 14:07:27 +0000 (-0800) Subject: minor optimizations X-Git-Tag: 20201202~6 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=488dacb01a73961e980ee6828c5b621a2baa7018;p=perltidy.git minor optimizations --- diff --git a/lib/Perl/Tidy/Formatter.pm b/lib/Perl/Tidy/Formatter.pm index f200d0a2..79ec3533 100644 --- a/lib/Perl/Tidy/Formatter.pm +++ b/lib/Perl/Tidy/Formatter.pm @@ -4315,19 +4315,20 @@ sub make_closing_side_comment_prefix { # lines take a different route, and because lines with deleted HSC # become BL lines. An since we are deleting now, we have to also # handle any tee- requests before the side comments vanish. - goto END_CODE - if ( $CODE_type && $CODE_type ne 'HSC' && $CODE_type ne 'IO' ); - my $delete_side_comment = $rOpts_delete_side_comments && defined($Kfirst) && $rLL->[$Klimit]->[_TYPE_] eq '#' - && ( $Klimit > $Kfirst || $CODE_type eq 'HSC' ); + && ( $Klimit > $Kfirst || $CODE_type eq 'HSC' ) + && ( !$CODE_type || $CODE_type eq 'HSC' || $CODE_type eq 'IO' ); if ( $rOpts_delete_closing_side_comments + && !$delete_side_comment && defined($Kfirst) && $Klimit > $Kfirst - && $rLL->[$Klimit]->[_TYPE_] eq '#' ) + && $rLL->[$Klimit]->[_TYPE_] eq '#' + && ( !$CODE_type || $CODE_type eq 'HSC' || $CODE_type eq 'IO' ) + ) { my $token = $rLL->[$Klimit]->[_TOKEN_]; my $K_m = $Klimit - 1; @@ -4368,8 +4369,6 @@ sub make_closing_side_comment_prefix { } ## end if ( $line_type eq 'CODE') - END_CODE: - # Finish storing line variables if ($tee_output) { my $fh_tee = $self->[_fh_tee_]; @@ -4630,21 +4629,6 @@ EOM $self->[_save_logfile_] = $logger_object->get_save_logfile(); } - # Future: Place to Begin future Iteration Loop - # foreach my $it_count(1..$maxit) { - - # Future: We must reset some things after the first iteration. - # This includes: - # - resetting levels if there was any welding - # - resetting any phantom semicolons - # - dealing with any line numbering issues so we can relate final lines - # line numbers with input line numbers. - # - # If ($it_count>1) { - # Copy {level_raw} to [_LEVEL_] if ($it_count>1) - # Renumber lines - # } - # Make a pass through all tokens, adding or deleting any whitespace as # required. Also make any other changes, such as adding semicolons. # All token changes must be made here so that the token data structure @@ -4667,27 +4651,6 @@ EOM # before continuing with the next stages of formatting. $self->process_all_lines(); - ############################################################ - # A possible future decomposition of 'process_all_lines()' follows. - # Benefits: - # - allow perltidy to do an internal iteration which eliminates - # many unnecessary steps, such as re-parsing and vertical alignment. - # This will allow iterations to be automatic. - # - consolidate all length calculations to allow utf8 alignment - ############################################################ - - # Future: Check for convergence of beginning tokens on CODE lines - - # Future: End of Iteration Loop - - # Future: add_padding($rargs); - - # Future: add_closing_side_comments($rargs); - - # Future: vertical_alignment($rargs); - - # Future: output results - # A final routine to tie up any loose ends $self->wrapup(); return; diff --git a/lib/Perl/Tidy/VerticalAligner/Line.pm b/lib/Perl/Tidy/VerticalAligner/Line.pm index 2e7db014..49044deb 100644 --- a/lib/Perl/Tidy/VerticalAligner/Line.pm +++ b/lib/Perl/Tidy/VerticalAligner/Line.pm @@ -158,12 +158,17 @@ EOM sub current_field_width { my ( $self, $j ) = @_; - if ( $j == 0 ) { - return $self->get_column($j); - } - else { - return $self->get_column($j) - $self->get_column( $j - 1 ); + my $col_j = 0; + my $col_jm = 0; + + my $alignment_j = $self->[_ralignments_]->[$j]; + $col_j = $alignment_j->get_column() if defined($alignment_j); + + if ( $j > 0 ) { + my $alignment_jm = $self->[_ralignments_]->[ $j - 1 ]; + $col_jm = $alignment_jm->get_column() if defined($alignment_jm); } + return $col_j - $col_jm; } sub increase_field_width {