]> git.donarmstrong.com Git - perltidy.git/commitdiff
only call sub pad_array_to_go if required
authorSteve Hancock <perltidy@users.sourceforge.net>
Mon, 19 Oct 2020 01:37:26 +0000 (18:37 -0700)
committerSteve Hancock <perltidy@users.sourceforge.net>
Mon, 19 Oct 2020 01:37:26 +0000 (18:37 -0700)
lib/Perl/Tidy/Formatter.pm

index a73efcf0cb7cd3d25d68aaad79bec46eb486e732..768d5aaba0aee911dd3cb11bf101a2a66089c1a0 100644 (file)
@@ -9779,8 +9779,12 @@ EOM
             $self->[_last_last_line_leading_level_] =
               $last_last_line_leading_level;
 
-            # add a couple of extra terminal blank tokens
-            $self->pad_array_to_go();
+            # Flag to remember if we called sub 'pad_array_to_go'.
+            # Some routines (scan_list(), set_continuation_breaks() ) need some
+            # extra tokens added at the end of the batch.  Most batches do not
+            # use these routines, so we will avoid calling 'pad_array_to_go'
+            # unless it is needed.
+            my $called_pad_array_to_go;
 
             # set all forced breakpoints for good list formatting
             my $is_long_line = $max_index_to_go > 0
@@ -9813,6 +9817,10 @@ EOM
                     && $rOpts_comma_arrow_breakpoints != 3 )
               )
             {
+                # add a couple of extra terminal blank tokens
+                $self->pad_array_to_go();
+                $called_pad_array_to_go = 1;
+
                 ## This caused problems in one version of perl for unknown reasons:
                 ## $saw_good_break ||= scan_list();
                 my $sgb = $self->scan_list($is_long_line);
@@ -9850,6 +9858,10 @@ EOM
             # otherwise use multiple lines
             else {
 
+               # add a couple of extra terminal blank tokens if we haven't
+               # already done so
+                $self->pad_array_to_go() unless ($called_pad_array_to_go); 
+
                 ( $ri_first, $ri_last ) =
                   $self->set_continuation_breaks( $saw_good_break,
                     \@colon_list );