From b275d080feda821658e8b769438064293c0c5cd2 Mon Sep 17 00:00:00 2001 From: Steve Hancock Date: Sun, 18 Oct 2020 18:37:26 -0700 Subject: [PATCH] only call sub pad_array_to_go if required --- lib/Perl/Tidy/Formatter.pm | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/lib/Perl/Tidy/Formatter.pm b/lib/Perl/Tidy/Formatter.pm index a73efcf0..768d5aab 100644 --- a/lib/Perl/Tidy/Formatter.pm +++ b/lib/Perl/Tidy/Formatter.pm @@ -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 ); -- 2.39.5