From: Steve Hancock Date: Fri, 19 Aug 2022 01:40:01 +0000 (-0700) Subject: eliminate some goto statements X-Git-Tag: 20220613.05~41 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=dd66634c22b61c05817f31d28d74da1173e19b8d;p=perltidy.git eliminate some goto statements --- diff --git a/lib/Perl/Tidy/Formatter.pm b/lib/Perl/Tidy/Formatter.pm index 9227cc3d..64679828 100644 --- a/lib/Perl/Tidy/Formatter.pm +++ b/lib/Perl/Tidy/Formatter.pm @@ -10483,63 +10483,66 @@ sub break_before_list_opening_containers { && $rOpts_continuation_indentation > $rOpts_indent_columns ); # Always ok to change ci for permanently broken containers - if ( $ris_permanently_broken->{$seqno} ) { - goto OK; - } + if ( $ris_permanently_broken->{$seqno} ) { } # Always OK if this list contains a broken sub-container with # a non-terminal line-ending comma - if ($has_list_with_lec) { goto OK } + elsif ($has_list_with_lec) { } - # From here on we are considering a single container... + # Otherwise, we are considering a single container... + else { - # A single container must have at least 1 line-ending comma: - next unless ( $rlec_count_by_seqno->{$seqno} ); + # A single container must have at least 1 line-ending comma: + next unless ( $rlec_count_by_seqno->{$seqno} ); - # Since it has a line-ending comma, it will stay broken if the -boc - # flag is set - if ($rOpts_break_at_old_comma_breakpoints) { goto OK } + my $OK; - # OK if the container contains multiple fat commas - # Better: multiple lines with fat commas - if ( !$rOpts_ignore_old_breakpoints ) { - my $rtype_count = $rtype_count_by_seqno->{$seqno}; - next unless ($rtype_count); - my $fat_comma_count = $rtype_count->{'=>'}; - DEBUG_BBX - && print STDOUT "BBX: fat comma count=$fat_comma_count\n"; - if ( $fat_comma_count && $fat_comma_count >= 2 ) { goto OK } - } - - # The last check we can make is to see if this container could fit on a - # single line. Use the least possible indentation estimate, ci=0, - # so we are not subtracting $ci * $rOpts_continuation_indentation from - # tabulated $maximum_text_length value. - my $maximum_text_length = $maximum_text_length_at_level[$level]; - my $K_closing = $K_closing_container->{$seqno}; - my $length = $self->cumulative_length_before_K($K_closing) - - $self->cumulative_length_before_K($KK); - my $excess_length = $length - $maximum_text_length; - DEBUG_BBX - && print STDOUT + # Since it has a line-ending comma, it will stay broken if the + # -boc flag is set + if ($rOpts_break_at_old_comma_breakpoints) { $OK = 1 } + + # OK if the container contains multiple fat commas + # Better: multiple lines with fat commas + if ( !$OK && !$rOpts_ignore_old_breakpoints ) { + my $rtype_count = $rtype_count_by_seqno->{$seqno}; + next unless ($rtype_count); + my $fat_comma_count = $rtype_count->{'=>'}; + DEBUG_BBX + && print STDOUT "BBX: fat comma count=$fat_comma_count\n"; + if ( $fat_comma_count && $fat_comma_count >= 2 ) { $OK = 1 } + } + + # The last check we can make is to see if this container could + # fit on a single line. Use the least possible indentation + # estimate, ci=0, so we are not subtracting $ci * + # $rOpts_continuation_indentation from tabulated + # $maximum_text_length value. + if ( !$OK ) { + my $maximum_text_length = $maximum_text_length_at_level[$level]; + my $K_closing = $K_closing_container->{$seqno}; + my $length = $self->cumulative_length_before_K($K_closing) - + $self->cumulative_length_before_K($KK); + my $excess_length = $length - $maximum_text_length; + DEBUG_BBX + && print STDOUT "BBX: excess=$excess_length: maximum_text_length=$maximum_text_length, length=$length, ci=$ci\n"; - # OK if the net container definitely breaks on length - if ( $excess_length > $length_tol ) { - DEBUG_BBX - && print STDOUT "BBX: excess_length=$excess_length\n"; - goto OK; - } + # OK if the net container definitely breaks on length + if ( $excess_length > $length_tol ) { + $OK = 1; + DEBUG_BBX + && print STDOUT "BBX: excess_length=$excess_length\n"; + } - # Otherwise skip it - next; + # Otherwise skip it + else { next } + } + } #------------------------------------------------------------ # Part 3: Looks OK: apply -bbx=n and any related -bbxi=n flag #------------------------------------------------------------ - OK: - DEBUG_BBX && print STDOUT "BBX: OK to break\n"; # -bbhbi=n diff --git a/lib/Perl/Tidy/HtmlWriter.pm b/lib/Perl/Tidy/HtmlWriter.pm index d7774963..af32cfae 100644 --- a/lib/Perl/Tidy/HtmlWriter.pm +++ b/lib/Perl/Tidy/HtmlWriter.pm @@ -753,7 +753,7 @@ sub pod_to_html { # this error shouldn't happen ... we just used this filename Perl::Tidy::Warn( "unable to open temporary file $tmpfile; cannot use pod2html\n"); - goto RETURN; + return $success_flag; } my $html_fh = $self->{_html_fh}; @@ -949,7 +949,6 @@ sub pod_to_html { $success_flag = 0; } - RETURN: close_object($html_fh); # note that we have to unlink tmpfile before making frames diff --git a/lib/Perl/Tidy/VerticalAligner.pm b/lib/Perl/Tidy/VerticalAligner.pm index fb9cb7da..2866e650 100644 --- a/lib/Perl/Tidy/VerticalAligner.pm +++ b/lib/Perl/Tidy/VerticalAligner.pm @@ -4322,14 +4322,16 @@ sub is_good_side_comment_column { # a previous side comment should be forgotten. This involves # checking several rules. - # Return true to keep old comment location - # Return false to forget old comment location + # Return true to KEEP old comment location + # Return false to FORGET old comment location + my $KEEP = 1; + my $FORGET = 0; my $rfields = $line->{'rfields'}; my $is_hanging_side_comment = $line->{'is_hanging_side_comment'}; # RULE1: Never forget comment before a hanging side comment - goto KEEP if ($is_hanging_side_comment); + return $KEEP if ($is_hanging_side_comment); # RULE2: Forget a side comment after a short line difference, # where 'short line difference' is computed from a formula. @@ -4358,14 +4360,14 @@ sub is_good_side_comment_column { my $short_diff = SC_LONG_LINE_DIFF / ( 1 + $alev_diff * $num5 ); - goto FORGET + return $FORGET if ( $line_diff > $short_diff || !$self->[_rOpts_valign_side_comments_] ); # RULE3: Forget a side comment if this line is at lower level and # ends a block my $last_sc_level = $self->[_last_side_comment_level_]; - goto FORGET + return $FORGET if ( $level < $last_sc_level && $is_closing_block_type{ substr( $rfields->[0], 0, 1 ) } ); @@ -4384,18 +4386,12 @@ sub is_good_side_comment_column { # [0, 3, 6], [1, 4, 7], [2, 5, 8], # columns # [0, 4, 8], [2, 4, 6] # ) # diagonals - goto FORGET + return $FORGET if ( $cached_line_type == 2 || $cached_line_type == 4 ); } # Otherwise, keep it alive - goto KEEP; - - FORGET: - return 0; - - KEEP: - return 1; + return $KEEP; } sub align_side_comments {