]> git.donarmstrong.com Git - perltidy.git/commitdiff
eliminate needless call to sub K_end_Q
authorSteve Hancock <perltidy@users.sourceforge.net>
Sat, 28 Nov 2020 16:13:49 +0000 (08:13 -0800)
committerSteve Hancock <perltidy@users.sourceforge.net>
Sat, 28 Nov 2020 16:13:49 +0000 (08:13 -0800)
lib/Perl/Tidy/Formatter.pm

index 8fe58fbb00a7e7a8f0bcd4c09d2a112ce9d3a3c2..396df42f8a2c47dd36473bd6fc37ee61e2c9f548 100644 (file)
@@ -4865,12 +4865,19 @@ sub respace_tokens {
 
     my $K_end_q = sub {
         my ($KK)  = @_;
+        my $Num   = @{$rLL};
         my $K_end = $KK;
-        my $Kn    = $self->K_next_nonblank($KK);
-        while ( defined($Kn) && $rLL->[$Kn]->[_TYPE_] eq 'q' ) {
+
+        my $Kn = $KK + 1;
+        if ( $Kn < $Num && $rLL->[$Kn]->[_TYPE_] eq 'b' ) { $Kn += 1 }
+
+        while ( $Kn < $Num && $rLL->[$Kn]->[_TYPE_] eq 'q' ) {
             $K_end = $Kn;
-            $Kn    = $self->K_next_nonblank($Kn);
+
+            $Kn += 1;
+            if ( $Kn < $Num && $rLL->[$Kn]->[_TYPE_] eq 'b' ) { $Kn += 1 }
         }
+
         return $K_end;
     };
 
@@ -5399,7 +5406,7 @@ sub respace_tokens {
 
                 # clean up spaces in package identifiers, like
                 #   "package        Bob::Dog;"
-                if ($token =~ /^package\s/) {
+                if ( $token =~ /^package\s/ ) {
                     $token =~ s/\s+/ /g;
                     $rtoken_vars->[_TOKEN_] = $token;
                 }
@@ -5534,31 +5541,34 @@ sub respace_tokens {
                 else {
 
                     # we are encountered new qw token...see if multiline
-                    my $K_end = $K_end_q->($KK);
-                    if ( $ALLOW_BREAK_MULTILINE_QW && $K_end != $KK ) {
-
-                        # Starting multiline qw...
-                        # set flag equal to the ending K
-                        $in_multiline_qw = $K_end;
-
-                        # Split off the leading part so that the formatter can
-                        # put a line break there if necessary
-                        if ( $token =~ /^(qw\s*.)(.*)$/ ) {
-                            my $part1 = $1;
-                            my $part2 = $2;
-                            if ($part2) {
-                                my $rcopy =
-                                  copy_token_as_type( $rtoken_vars, 'q',
-                                    $part1 );
-                                $store_token_and_space->(
-                                    $rcopy, $rwhitespace_flags->[$KK] == WS_YES
-                                );
-                                $token = $part2;
-                                $rtoken_vars->[_TOKEN_] = $token;
-
-                                # Second part goes without intermediate blank
-                                $store_token->($rtoken_vars);
-                                next;
+                    if ($ALLOW_BREAK_MULTILINE_QW) {
+                        my $K_end = $K_end_q->($KK);
+                        if ( $K_end != $KK ) {
+
+                            # Starting multiline qw...
+                            # set flag equal to the ending K
+                            $in_multiline_qw = $K_end;
+
+                          # Split off the leading part so that the formatter can
+                          # put a line break there if necessary
+                            if ( $token =~ /^(qw\s*.)(.*)$/ ) {
+                                my $part1 = $1;
+                                my $part2 = $2;
+                                if ($part2) {
+                                    my $rcopy =
+                                      copy_token_as_type( $rtoken_vars, 'q',
+                                        $part1 );
+                                    $store_token_and_space->(
+                                        $rcopy,
+                                        $rwhitespace_flags->[$KK] == WS_YES
+                                    );
+                                    $token = $part2;
+                                    $rtoken_vars->[_TOKEN_] = $token;
+
+                                   # Second part goes without intermediate blank
+                                    $store_token->($rtoken_vars);
+                                    next;
+                                }
                             }
                         }
                     }