]> git.donarmstrong.com Git - perltidy.git/commitdiff
optimize processing of block comments
authorSteve Hancock <perltidy@users.sourceforge.net>
Sun, 3 Oct 2021 18:57:41 +0000 (11:57 -0700)
committerSteve Hancock <perltidy@users.sourceforge.net>
Sun, 3 Oct 2021 18:57:41 +0000 (11:57 -0700)
lib/Perl/Tidy/Formatter.pm

index 20eab4d3d8e5db5be2d32f12ce32c165d41571d8..170a60bdb0d706ea27906ca07a1468ca062042a6 100644 (file)
@@ -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);
                 }
             }