]> git.donarmstrong.com Git - perltidy.git/commitdiff
optimization to avoid regex
authorSteve Hancock <perltidy@users.sourceforge.net>
Thu, 1 Feb 2024 23:51:13 +0000 (15:51 -0800)
committerSteve Hancock <perltidy@users.sourceforge.net>
Thu, 1 Feb 2024 23:51:13 +0000 (15:51 -0800)
lib/Perl/Tidy/Formatter.pm

index d6f9ba39f9536384f11d3c34d1660f3115a1f615..74140f304e4f426b38852ab654c4a871cb3838a2 100644 (file)
@@ -3929,10 +3929,16 @@ EOM
 
         my $tokenr_leading_ch    = substr( $tokenr, 0, 1 );
         my $tokenr_leading_ch2   = substr( $tokenr, 0, 2 );
-        my $tokenr_is_bareword   = $tokenr =~ /^[^\d\W]/;
         my $tokenr_is_open_paren = $tokenr eq '(';
         my $token_joined         = $tokenl . $tokenr;
         my $tokenl_is_dash       = $tokenl eq '-';
+        my $tokenr_is_bareword   = ord($tokenr_leading_ch) > ORD_PRINTABLE_MAX
+
+          # always correct but slow
+          ? $tokenr =~ /^[^\d\W]/
+
+          # fast but ascii only
+          : ( $tokenr_leading_ch =~ tr/a-zA-Z_/a-zA-Z_/ );
 
         #-------------------
         # Must do full check