From: Steve Hancock Date: Thu, 7 Apr 2022 18:20:05 +0000 (-0700) Subject: minor optimizations X-Git-Tag: 20220217.03~14 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=0693d9a30ad4c07e898a81353f47f77fd813f696;p=perltidy.git minor optimizations --- diff --git a/lib/Perl/Tidy/Formatter.pm b/lib/Perl/Tidy/Formatter.pm index 104e895b..4e9b2dfc 100644 --- a/lib/Perl/Tidy/Formatter.pm +++ b/lib/Perl/Tidy/Formatter.pm @@ -5815,7 +5815,6 @@ sub set_CODE_type { # require Exporter; our $VERSION = $Exporter::VERSION; # where both statements must be on a single line for MakeMaker - my $is_VERSION_statement = 0; if ( !$Saw_VERSION_in_this_file && $jmax < 80 && $input_line =~ @@ -12607,10 +12606,9 @@ EOM $CODE_type eq 'SBCX'; $is_static_block_comment = $CODE_type eq 'SBC' || $is_static_block_comment_without_leading_space; - my $is_hanging_side_comment = $CODE_type eq 'HSC'; - my $is_VERSION_statement = $CODE_type eq 'VER'; - if ($is_VERSION_statement) { + # check for a $VERSION statement + if ( $CODE_type eq 'VER' ) { $self->[_saw_VERSION_in_this_file_] = 1; $no_internal_newlines = 2; } @@ -12708,12 +12706,14 @@ EOM return; } - # compare input/output indentation except for continuation lines - # (because they have an unknown amount of initial blank space) - # and lines which are quotes (because they may have been outdented) + # Compare input/output indentation except for: + # - hanging side comments + # - continuation lines (habe unknown amount of initial blank space) + # - and lines which are quotes (because they may have been outdented) my $guessed_indentation_level = $line_of_tokens->{_guessed_indentation_level}; - unless ( $is_hanging_side_comment + + unless ( $CODE_type eq 'HSC' || $rtok_first->[_CI_LEVEL_] > 0 || $guessed_indentation_level == 0 && $rtok_first->[_TYPE_] eq 'Q' ) { @@ -13304,76 +13304,82 @@ EOM } ## end of loop over all tokens in this line - my $type = $rLL->[$K_last]->[_TYPE_]; - my $break_flag = $self->[_rbreak_after_Klast_]->{$K_last}; + # if there is anything left in the output buffer ... + if ( $max_index_to_go >= 0 ) { - # we have to flush .. - if ( + my $type = $rLL->[$K_last]->[_TYPE_]; + my $break_flag = $self->[_rbreak_after_Klast_]->{$K_last}; - # if there is a side comment... - $type eq '#' - - # if this line ends in a quote - # NOTE: This is critically important for insuring that quoted lines - # do not get processed by things like -sot and -sct - || $in_quote - - # if this is a VERSION statement - || $is_VERSION_statement - - # to keep a label at the end of a line - || ( $type eq 'J' && $rOpts_break_after_labels != 2 ) - - # if we have a hard break request - || $break_flag && $break_flag != 2 - - # if we are instructed to keep all old line breaks - || !$rOpts->{'delete-old-newlines'} - - # if this is a line of the form 'use overload'. A break here - # in the input file is a good break because it will allow - # the operators which follow to be formatted well. Without - # this break the formatting with -ci=4 -xci is poor, for example. - - # use overload - # '+' => sub { - # print length $_[2], "\n"; - # my ( $x, $y ) = _order(@_); - # Number::Roman->new( int $x + $y ); - # }, - # '-' => sub { - # my ( $x, $y ) = _order(@_); - # Number::Roman->new( int $x - $y ); - # }; - || ( $max_index_to_go == 2 - && $types_to_go[0] eq 'k' - && $tokens_to_go[0] eq 'use' - && $tokens_to_go[$max_index_to_go] eq 'overload' ) - ) - { - destroy_one_line_block(); - $self->end_batch() if ( $max_index_to_go >= 0 ); - } - - # Check for a soft break request - if ( $max_index_to_go >= 0 && $break_flag && $break_flag == 2 ) { - $self->set_forced_breakpoint($max_index_to_go); - } + # we have to flush .. + if ( - # mark old line breakpoints in current output stream - if ( - $max_index_to_go >= 0 - && ( !$rOpts_ignore_old_breakpoints - || $self->[_ris_essential_old_breakpoint_]->{$K_last} ) - ) - { - my $jobp = $max_index_to_go; - if ( $types_to_go[$max_index_to_go] eq 'b' && $max_index_to_go > 0 ) + # if there is a side comment... + $type eq '#' + + # if this line ends in a quote + # NOTE: This is critically important for insuring that quoted + # lines do not get processed by things like -sot and -sct + || $in_quote + + # if this is a VERSION statement + || $CODE_type eq 'VER' + + # to keep a label at the end of a line + || ( $type eq 'J' && $rOpts_break_after_labels != 2 ) + + # if we have a hard break request + || $break_flag && $break_flag != 2 + + # if we are instructed to keep all old line breaks + || !$rOpts->{'delete-old-newlines'} + + # if this is a line of the form 'use overload'. A break here in + # the input file is a good break because it will allow the + # operators which follow to be formatted well. Without this + # break the formatting with -ci=4 -xci is poor, for example. + + # use overload + # '+' => sub { + # print length $_[2], "\n"; + # my ( $x, $y ) = _order(@_); + # Number::Roman->new( int $x + $y ); + # }, + # '-' => sub { + # my ( $x, $y ) = _order(@_); + # Number::Roman->new( int $x - $y ); + # }; + || ( $max_index_to_go == 2 + && $types_to_go[0] eq 'k' + && $tokens_to_go[0] eq 'use' + && $tokens_to_go[$max_index_to_go] eq 'overload' ) + ) { - $jobp--; + destroy_one_line_block(); + $self->end_batch(); + } + + else { + + # Check for a soft break request + if ( $break_flag && $break_flag == 2 ) { + $self->set_forced_breakpoint($max_index_to_go); + } + + # mark old line breakpoints in current output stream + if ( !$rOpts_ignore_old_breakpoints + || $self->[_ris_essential_old_breakpoint_]->{$K_last} ) + { + my $jobp = $max_index_to_go; + if ( $types_to_go[$max_index_to_go] eq 'b' + && $max_index_to_go > 0 ) + { + $jobp--; + } + $old_breakpoint_to_go[$jobp] = 1; + } } - $old_breakpoint_to_go[$jobp] = 1; } + return; } ## end sub process_line_of_CODE } ## end closure process_line_of_CODE