From c2cb582a916fbe78fb034d474c9d15058d291c70 Mon Sep 17 00:00:00 2001 From: Steve Hancock Date: Mon, 14 Aug 2023 22:15:45 -0700 Subject: [PATCH] optimize pretoken search order Benchmarking shows that this simple change speeds up perltidy about 0.5% --- lib/Perl/Tidy/Tokenizer.pm | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) 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 ); -- 2.39.5