From c0cfba610aab7803df06258665fc6f576cd04c86 Mon Sep 17 00:00:00 2001 From: Steve Hancock Date: Tue, 20 Oct 2020 18:06:07 -0700 Subject: [PATCH] unroll loop to speedup sub K_previous_nonblank --- lib/Perl/Tidy/Formatter.pm | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lib/Perl/Tidy/Formatter.pm b/lib/Perl/Tidy/Formatter.pm index 25a5167c..c8c4edcf 100644 --- a/lib/Perl/Tidy/Formatter.pm +++ b/lib/Perl/Tidy/Formatter.pm @@ -5536,6 +5536,14 @@ sub K_previous_nonblank { ); } my $Kpnb = $KK - 1; + return unless ($Kpnb >= 0); + return $Kpnb if ( $rLL->[$Kpnb]->[_TYPE_] ne 'b' ); + return unless ( --$Kpnb >= 0 ); + return $Kpnb if ( $rLL->[$Kpnb]->[_TYPE_] ne 'b' ); + + # Backup loop. We should not get here unless some routine + # slipped repeated blanks into the token stream. + return unless ( --$Kpnb >= 0 ); while ( $Kpnb >= 0 ) { if ( $rLL->[$Kpnb]->[_TYPE_] ne 'b' ) { return $Kpnb } $Kpnb--; @@ -5543,6 +5551,7 @@ sub K_previous_nonblank { return; } + sub get_old_line_index { # return index of the original line that token K was on -- 2.39.5