From 0c93098dfce9f14a2ce87b0b52809f7afa10ca27 Mon Sep 17 00:00:00 2001 From: Steve Hancock Date: Sun, 19 Sep 2021 08:10:25 -0700 Subject: [PATCH] minor code cleanups --- MANIFEST | 1 - MANIFEST.SKIP | 2 ++ bin/perltidy | 4 +-- lib/Perl/Tidy/Formatter.pm | 46 ++++++++++++++++++----------- t/snippets/dump_negated_switches.pl | 1 + 5 files changed, 34 insertions(+), 20 deletions(-) diff --git a/MANIFEST b/MANIFEST index 3e7239d7..4a47753a 100644 --- a/MANIFEST +++ b/MANIFEST @@ -1,4 +1,3 @@ -.github/workflows/perltest.yml .pre-commit-hooks.yaml bin/perltidy BUGS.md diff --git a/MANIFEST.SKIP b/MANIFEST.SKIP index 883dc63e..b01027e5 100644 --- a/MANIFEST.SKIP +++ b/MANIFEST.SKIP @@ -84,7 +84,9 @@ -[\d\.\_]+\.tar -[\d\.\_]+\.tar\.gz + # Github files +\.github \.travis\.yml # Jekyl file diff --git a/bin/perltidy b/bin/perltidy index 05956e10..8a50fb44 100755 --- a/bin/perltidy +++ b/bin/perltidy @@ -4724,8 +4724,8 @@ The following list shows all short parameter names which allow a prefix osbc osbr otr ple pod pvl q sac sbc sbl scbb schb scp scsb sct se sfp sfs skp sob sobb sohb sop sosb sot ssc st sts t tac - tbc toc tp tqw trp ts tsc tso vmll w - wn x xci xs + tbc toc tp tqw trp ts tsc tso vbc vc + vmll vsc w wn x xci xs Equivalently, the prefix 'no' or 'no-' on the corresponding long names may be used. diff --git a/lib/Perl/Tidy/Formatter.pm b/lib/Perl/Tidy/Formatter.pm index 99e37ba1..b5baf84e 100644 --- a/lib/Perl/Tidy/Formatter.pm +++ b/lib/Perl/Tidy/Formatter.pm @@ -11534,8 +11534,6 @@ EOM my $token = $rtoken_vars->[_TOKEN_]; my $type = $rtoken_vars->[_TYPE_]; my $type_sequence = $rtoken_vars->[_TYPE_SEQUENCE_]; - my $block_type = - $type_sequence ? $rblock_type_of_seqno->{$type_sequence} : undef; # If we are continuing after seeing a right curly brace, flush # buffer unless we see what we are looking for, as in @@ -11548,6 +11546,26 @@ EOM $rbrace_follower = undef; } + my ( $block_type, $is_opening_BLOCK, $is_closing_BLOCK ); + if ($type_sequence) { + + $block_type = $rblock_type_of_seqno->{$type_sequence}; + + if ( $block_type + && $token eq $type + && $block_type ne 't' + && !$rshort_nested->{$type_sequence} ) + { + + if ( $type eq '{' ) { + $is_opening_BLOCK = 1; + } + elsif ( $type eq '}' ) { + $is_closing_BLOCK = 1; + } + } + } + # Get next nonblank on this line my $next_nonblank_token = ''; my $next_nonblank_token_type = 'b'; @@ -11568,18 +11586,6 @@ EOM # or closing BLOCK, followed by a side comment, those sections # of code will handle this flag separately. $side_comment_follows = ( $next_nonblank_token_type eq '#' ); - my $is_opening_BLOCK = - ( $type eq '{' - && $token eq '{' - && $block_type - && !$rshort_nested->{$type_sequence} - && $block_type ne 't' ); - my $is_closing_BLOCK = - ( $type eq '}' - && $token eq '}' - && $block_type - && !$rshort_nested->{$type_sequence} - && $block_type ne 't' ); if ( $side_comment_follows && !$is_opening_BLOCK @@ -21432,8 +21438,9 @@ sub pad_token { } } - # Lines with just 1 token do not have alignments - # so we can process them immediately. + # ---------------------------------------------------------- + # Shortcut 1: Lines with just 1 token do not have alignments + # ---------------------------------------------------------- if ( $iend == $ibeg ) { @tokens = (); @fields = ( $tokens_to_go[$ibeg] ); @@ -21452,7 +21459,9 @@ sub pad_token { } } - # Optimization: process lines without alignments immediately + # ------------------------------------------- + # Shortcut 2: handle lines without alignments + # ------------------------------------------- if ( !$has_alignment ) { @tokens = (); @fields = ( join( '', @tokens_to_go[ $ibeg .. $iend ] ) ); @@ -21462,6 +21471,9 @@ sub pad_token { return ( \@tokens, \@fields, \@patterns, \@field_lengths ); } + # -------------------- + # Loop over all tokens + # -------------------- my $j = 0; # field index $patterns[0] = ""; diff --git a/t/snippets/dump_negated_switches.pl b/t/snippets/dump_negated_switches.pl index 4c5d6577..a74dd95e 100755 --- a/t/snippets/dump_negated_switches.pl +++ b/t/snippets/dump_negated_switches.pl @@ -81,6 +81,7 @@ foreach my $word ( sort (@short_list, @special) ) { $line .= $word; $count++; if ( $count == $WORDS_PER_LINE ) { + $line =~ s/\s+$//; print "$line\n"; $count = 0; $line = " "; -- 2.39.5