From: Steve Hancock Date: Tue, 15 Aug 2023 05:15:45 +0000 (-0700) Subject: optimize pretoken search order X-Git-Tag: 20230701.03~16 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=c2cb582a916fbe78fb034d474c9d15058d291c70;p=perltidy.git optimize pretoken search order Benchmarking shows that this simple change speeds up perltidy about 0.5% --- diff --git a/lib/Perl/Tidy/Tokenizer.pm b/lib/Perl/Tidy/Tokenizer.pm index d46e9b20..9e38e794 100644 --- a/lib/Perl/Tidy/Tokenizer.pm +++ b/lib/Perl/Tidy/Tokenizer.pm @@ -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 );