From b69d6dd7e00bc5482e3858602117c6543c5edfce Mon Sep 17 00:00:00 2001 From: Steve Hancock Date: Sat, 17 Oct 2020 18:41:02 -0700 Subject: [PATCH] unroll loop in sub K_next_nonblank to improve efficiency --- lib/Perl/Tidy/Formatter.pm | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/Perl/Tidy/Formatter.pm b/lib/Perl/Tidy/Formatter.pm index af58bdfb..0e6edec5 100644 --- a/lib/Perl/Tidy/Formatter.pm +++ b/lib/Perl/Tidy/Formatter.pm @@ -5373,7 +5373,8 @@ sub K_next_code { sub K_next_nonblank { my ( $self, $KK, $rLL ) = @_; - # return the index K of the next nonblank token + # return the index K of the next nonblank token, or + # return undef if none return unless ( defined($KK) && $KK >= 0 ); # The third arg allows this routine to be used on any array. This is @@ -5383,6 +5384,14 @@ sub K_next_nonblank { $rLL = $self->[_rLL_] unless ( defined($rLL) ); my $Num = @{$rLL}; my $Knnb = $KK + 1; + return unless ( $Knnb < $Num ); + return $Knnb if ( $rLL->[$Knnb]->[_TYPE_] ne 'b' ); + return unless ( ++$Knnb < $Num ); + return $Knnb if ( $rLL->[$Knnb]->[_TYPE_] ne 'b' ); + + # Backup loop. Very unlikely to get here; it means we have neighboring + # blanks in the token stream. + $Knnb++; while ( $Knnb < $Num ) { # Safety check, this fault shouldn't happen: The $rLL array is the -- 2.39.5