]> git.donarmstrong.com Git - perltidy.git/commitdiff
optimization
authorSteve Hancock <perltidy@users.sourceforge.net>
Sat, 20 Aug 2022 14:42:59 +0000 (07:42 -0700)
committerSteve Hancock <perltidy@users.sourceforge.net>
Sat, 20 Aug 2022 14:42:59 +0000 (07:42 -0700)
lib/Perl/Tidy.pm
lib/Perl/Tidy/Tokenizer.pm

index 0f76aea188037e790e6204ba1e05317554b90c1b..99e8d3791b507993f89004f0247654093813820b 100644 (file)
@@ -4826,7 +4826,7 @@ sub Win_Config_Locs {
 
 sub dump_config_file {
     my ( $fh, $config_file, $rconfig_file_chatter ) = @_;
-    print STDOUT "$$rconfig_file_chatter";
+    print STDOUT "${$rconfig_file_chatter}";
     if ($fh) {
         print STDOUT "# Dump of file: '$config_file'\n";
         while ( my $line = $fh->getline() ) { print STDOUT $line }
index 328a1b4ef18b291e3b54660d4968965843fdf13e..1caee7318a08f45a0e0d50965a0eacb1e7b73fe1 100644 (file)
@@ -4063,7 +4063,6 @@ EOM
             && ( $i_next <= $max_token_index )    # colon on same line
 
             # like 'sub : lvalue' ?
-            ##&& !$sub_attribute_ok_here            # like 'sub : lvalue' ?
             && !sub_attribute_ok_here( $tok_kw, $next_nonblank_token, $i_next )
             && label_ok()
           )
@@ -4144,11 +4143,6 @@ EOM
 
         }
 
-        # Removed to fix b1280.  This is not needed and was causing the
-        # starting type 'qw' to be lost, leading to mis-tokenization of
-        # a trailing block brace in a parenless for stmt 'for .. qw.. {'
-        ##$tok = $quote_character if ($quote_character);
-
         # scan for the end of the quote or pattern
         (
             $i, $in_quote, $quote_character, $quote_pos, $quote_depth,
@@ -8657,6 +8651,12 @@ EOM
 # Tokenizer utility routines which may use CONSTANTS but no other GLOBALS
 #########################################################################
 
+# Decimal values of some ascii characters for quick checks
+use constant ORD_PRINTABLE_MIN => 33;
+use constant ORD_PRINTABLE_MAX => 126;
+use constant ORD_TAB           => 9;
+use constant ORD_SPACE         => 32;
+
 sub find_next_nonblank_token {
     my ( $i, $rtokens, $max_token_index ) = @_;
 
@@ -8672,12 +8672,31 @@ sub find_next_nonblank_token {
     }
 
     my $next_nonblank_token = $rtokens->[ ++$i ];
-    return ( SPACE, $i ) unless defined($next_nonblank_token);
+    return ( SPACE, $i )
+      unless ( defined($next_nonblank_token) && length($next_nonblank_token) );
+
+    # Quick test for nonblank ascii char. Note that we just have to
+    # examine the first character here.
+    my $ord = ord( substr( $next_nonblank_token, 0, 1 ) );
+    if (   $ord >= ORD_PRINTABLE_MIN
+        && $ord <= ORD_PRINTABLE_MAX )
+    {
+        return ( $next_nonblank_token, $i );
+    }
+
+    # Quick test to skip over an ascii space or tab
+    elsif ( $ord == ORD_SPACE || $ord == ORD_TAB ) {
+        $next_nonblank_token = $rtokens->[ ++$i ];
+        return ( SPACE, $i ) unless defined($next_nonblank_token);
+    }
 
-    if ( $next_nonblank_token =~ /^\s*$/ ) {
+    # Slow test to skip over something else identified as whitespace
+    elsif ( $next_nonblank_token =~ /^\s*$/ ) {
         $next_nonblank_token = $rtokens->[ ++$i ];
         return ( SPACE, $i ) unless defined($next_nonblank_token);
     }
+
+    # We should be at a nonblank now
     return ( $next_nonblank_token, $i );
 } ## end sub find_next_nonblank_token