From c23c44e50419ed393e436888a8cd45f682fc6988 Mon Sep 17 00:00:00 2001 From: Steve Hancock Date: Sun, 3 Oct 2021 11:57:41 -0700 Subject: [PATCH] optimize processing of block comments --- lib/Perl/Tidy/Formatter.pm | 50 ++++++++++++++++++++++++++++++++------ 1 file changed, 42 insertions(+), 8 deletions(-) diff --git a/lib/Perl/Tidy/Formatter.pm b/lib/Perl/Tidy/Formatter.pm index 20eab4d3..170a60bd 100644 --- a/lib/Perl/Tidy/Formatter.pm +++ b/lib/Perl/Tidy/Formatter.pm @@ -13020,18 +13020,10 @@ EOM sub grind_batch_of_CODE { my ($self) = @_; - my $file_writer_object = $self->[_file_writer_object_]; my $this_batch = $self->[_this_batch_]; $batch_count++; - my $starting_in_quote = $this_batch->[_starting_in_quote_]; - my $ending_in_quote = $this_batch->[_ending_in_quote_]; - my $is_static_block_comment = $this_batch->[_is_static_block_comment_]; - my $ris_seqno_controlling_ci = $self->[_ris_seqno_controlling_ci_]; - - my $rLL = $self->[_rLL_]; - # This routine is only called from sub flush_batch_of_code, so that # routine is a better spot for debugging. DEBUG_GRIND && do { @@ -13056,6 +13048,46 @@ EOM ); } + #---------------------------- + # Shortcut for block comments + #---------------------------- + if ( + $max_index_to_go == 0 + && $types_to_go[0] eq '#' + + # this shortcut does not work for -lp yet + && !$rOpts_line_up_parentheses + ) + { + my $ibeg = 0; + my $Kbeg = my $Kend = $K_to_go[$ibeg]; + $this_batch->[_rlines_K_] = [ [ $Kbeg, $Kend ] ]; + $this_batch->[_ibeg0_] = $ibeg; + $this_batch->[_peak_batch_size_] = $peak_batch_size; + $this_batch->[_do_not_pad_] = 0; + $this_batch->[_batch_count_] = $batch_count; + $this_batch->[_rix_seqno_controlling_ci_] = []; + $self->send_lines_to_vertical_aligner(); + my $level = $levels_to_go[$ibeg]; + $self->[_last_last_line_leading_level_] = + $self->[_last_line_leading_level_]; + $self->[_last_line_leading_type_] = $types_to_go[$ibeg]; + $self->[_last_line_leading_level_] = $level; + $nonblank_lines_at_depth[$level] = 1; + return; + } + + #------------- + # Normal route + #------------- + + my $rLL = $self->[_rLL_]; + my $ris_seqno_controlling_ci = $self->[_ris_seqno_controlling_ci_]; + + my $starting_in_quote = $this_batch->[_starting_in_quote_]; + my $ending_in_quote = $this_batch->[_ending_in_quote_]; + my $is_static_block_comment = $this_batch->[_is_static_block_comment_]; + # Initialize some batch variables my $comma_count_in_batch = 0; my $ilast_nonblank = -1; @@ -13252,6 +13284,7 @@ EOM # future: send blank line down normal path to VerticalAligner $self->flush_vertical_aligner(); + my $file_writer_object = $self->[_file_writer_object_]; $file_writer_object->require_blank_code_lines($want_blank); } } @@ -13492,6 +13525,7 @@ EOM { my $nblanks = $rOpts->{'blank-lines-after-opening-block'}; $self->flush_vertical_aligner(); + my $file_writer_object = $self->[_file_writer_object_]; $file_writer_object->require_blank_code_lines($nblanks); } } -- 2.39.5