From: Steve Hancock Date: Thu, 26 Jan 2023 18:38:16 +0000 (-0800) Subject: improved efficiency of token loop X-Git-Tag: 20221112.05~5 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=f9ff4391f80bdb252d63398db2297c9d9a4932be;p=perltidy.git improved efficiency of token loop --- diff --git a/lib/Perl/Tidy/Formatter.pm b/lib/Perl/Tidy/Formatter.pm index 69b728e3..cb00573a 100644 --- a/lib/Perl/Tidy/Formatter.pm +++ b/lib/Perl/Tidy/Formatter.pm @@ -5724,7 +5724,7 @@ EOM return; } - my $line_number = $line_of_tokens_old->{_line_number}; + my $line_index = $line_of_tokens_old->{_line_number} - 1; my $rtoken_type = $line_of_tokens_old->{_rtoken_type}; my $rblock_type = $line_of_tokens_old->{_rblock_type}; my $rtype_sequence = $line_of_tokens_old->{_rtype_sequence}; @@ -5737,7 +5737,7 @@ EOM DEVEL_MODE && check_sequence_numbers( $rtokens, $rtoken_type, - $rtype_sequence, $line_number ); + $rtype_sequence, $line_index + 1 ); # Find the starting nesting depth ... # It must be the value of variable 'level' of the first token @@ -5751,20 +5751,26 @@ EOM $rdepth_of_opening_seqno->[SEQ_ROOT] = $nesting_depth - 1; } - foreach my $j ( 0 .. $jmax ) { + my $j = -1; + + # NOTE: coding efficiency is critical in this loop over all tokens + foreach my $token ( @{$rtokens} ) { # Do not clip the 'level' variable yet. We will do this # later, in sub 'store_token_to_go'. The reason is that in # files with level errors, the logic in 'weld_cuddled_else' # uses a stack logic that will give bad welds if we clip # levels here. + ## $j++; ## if ( $rlevels->[$j] < 0 ) { $rlevels->[$j] = 0 } + my $seqno = EMPTY_STRING; + # Handle tokens with sequence numbers ... - my $seqno = $rtype_sequence->[$j]; - if ($seqno) { - my $token = $rtokens->[$j]; - my $sign = 1; + # note the ++ increment hidden here for efficiency + if ( $rtype_sequence->[ ++$j ] ) { + $seqno = $rtype_sequence->[$j]; + my $sign = 1; if ( $is_opening_token{$token} ) { $self->[_K_opening_container_]->{$seqno} = @{$rLL}; $rdepth_of_opening_seqno->[$seqno] = $nesting_depth; @@ -5832,28 +5838,36 @@ EOM my $level = $rlevels->[$j]; if ( $level > $self->[_maximum_level_] ) { $self->[_maximum_level_] = $level; - $self->[_maximum_level_at_line_] = $line_number; + $self->[_maximum_level_at_line_] = $line_index + 1; } } else { $self->[_Iss_closing_]->[$seqno] = @{$rSS} } push @{$rSS}, $sign * $seqno; } - else { - $seqno = EMPTY_STRING unless ( defined($seqno) ); - } my @tokary; @tokary[ - _TOKEN_, _TYPE_, _TYPE_SEQUENCE_, - _LEVEL_, _CI_LEVEL_, _LINE_INDEX_, - ] - = ( - $rtokens->[$j], $rtoken_type->[$j], $seqno, $rlevels->[$j], - $rci_levels->[$j], $line_number - 1, + + _TOKEN_, + _TYPE_, + _TYPE_SEQUENCE_, + _LEVEL_, + _CI_LEVEL_, + _LINE_INDEX_, + + ] = ( + + $token, + $rtoken_type->[$j], + $seqno, + $rlevels->[$j], + $rci_levels->[$j], + $line_index, + ); push @{$rLL}, \@tokary; - } ## end foreach my $j ( 0 .. $jmax ) + } ## end token loop # Need to remember if we can trim the input line $line_of_tokens->{_ended_in_blank_token} = $rtoken_type->[$jmax] eq 'b'; diff --git a/local-docs/Release-Checklist.md b/local-docs/Release-Checklist.md index a08212d0..556415b2 100644 --- a/local-docs/Release-Checklist.md +++ b/local-docs/Release-Checklist.md @@ -5,10 +5,10 @@ - run 'devbin/run__convergence_tests.pl' for all commit candidates - Run perlcritic - run NYTProf and check the activity and performance of all changed code - - suggested random testing minimum test duration without irregularities: + - IMPORTANT: random testing minimum test duration without irregularities: - 3 cpu hours for a commit candidate - 24 cpu hours for a +0.01 version bump candidate - - 100 cpu hours for a new release candidate + - 100 cpu hours for a new integer release candidate for CPAN - run 'author tests' on a much larger body of code than is covered by the .t files. - compare results of the current version with previous version