From 91d7a1cc848b811725ad96da073ccf9542fb8e30 Mon Sep 17 00:00:00 2001 From: Steve Hancock Date: Sat, 20 Aug 2022 07:42:59 -0700 Subject: [PATCH] optimization --- lib/Perl/Tidy.pm | 2 +- lib/Perl/Tidy/Tokenizer.pm | 35 +++++++++++++++++++++++++++-------- 2 files changed, 28 insertions(+), 9 deletions(-) diff --git a/lib/Perl/Tidy.pm b/lib/Perl/Tidy.pm index 0f76aea1..99e8d379 100644 --- a/lib/Perl/Tidy.pm +++ b/lib/Perl/Tidy.pm @@ -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 } diff --git a/lib/Perl/Tidy/Tokenizer.pm b/lib/Perl/Tidy/Tokenizer.pm index 328a1b4e..1caee731 100644 --- a/lib/Perl/Tidy/Tokenizer.pm +++ b/lib/Perl/Tidy/Tokenizer.pm @@ -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 -- 2.39.5