]> git.donarmstrong.com Git - perltidy.git/commitdiff
optimize pretoken search order
authorSteve Hancock <perltidy@users.sourceforge.net>
Tue, 15 Aug 2023 05:15:45 +0000 (22:15 -0700)
committerSteve Hancock <perltidy@users.sourceforge.net>
Tue, 15 Aug 2023 05:15:45 +0000 (22:15 -0700)
Benchmarking shows that this simple change speeds up perltidy about 0.5%

lib/Perl/Tidy/Tokenizer.pm

index d46e9b20498dfe54cf3f38ecaa61e8e69845c9b1..9e38e79427a0b21f64a14831ca120c72b3cdda59 100644 (file)
@@ -9968,19 +9968,18 @@ sub pre_tokenize {
 
     do {
 
-        # whitespace
+        # whitespace - this must come before \W
         if ( $str =~ /\G(\s+)/gc ) { push @type, 'b'; }
 
-        # numbers
-        # note that this must come before words!
+        # non-whitespace single-character punctuation
+        elsif ( $str =~ /\G(\W)/gc ) { push @type, $1; }
+
+        # sequence of digits - this must come before \w
         elsif ( $str =~ /\G(\d+)/gc ) { push @type, 'd'; }
 
-        # words
+        # words not starting with a digit
         elsif ( $str =~ /\G(\w+)/gc ) { push @type, 'w'; }
 
-        # single-character punctuation
-        elsif ( $str =~ /\G(\W)/gc ) { push @type, $1; }
-
         # that's all..
         else {
             return ( \@tokens, \@token_map, \@type );