From: Steve Hancock Date: Fri, 2 Feb 2024 18:21:41 +0000 (-0800) Subject: optimization - eliminate sub store_block_type X-Git-Tag: 20240202.01~9 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=fadbe16f77f4d73e75f7d886dfbf0567eec25d85;p=perltidy.git optimization - eliminate sub store_block_type --- diff --git a/lib/Perl/Tidy/Formatter.pm b/lib/Perl/Tidy/Formatter.pm index 03cb6b7e..48625d74 100644 --- a/lib/Perl/Tidy/Formatter.pm +++ b/lib/Perl/Tidy/Formatter.pm @@ -6029,28 +6029,6 @@ EOM return; } ## end sub check_sequence_numbers - sub store_block_type { - my ( $self, $block_type, $seqno ) = @_; - - return if ( !$block_type ); - - # Save the type of a block in a hash using sequence number as key - $self->[_rblock_type_of_seqno_]->{$seqno} = $block_type; - - # and save named subs and anynymous subs in separate hashes so that - # we only have to do the pattern tests once. - if ( $matches_ASUB{$block_type} ) { - $self->[_ris_asub_block_]->{$seqno} = 1; - } - elsif ( $block_type =~ /$SUB_PATTERN/ ) { - $self->[_ris_sub_block_]->{$seqno} = 1; - } - else { - # not a sub type - } - return; - } ## end sub store_block_type - # hash keys which are common to old and new line_of_tokens my @common_keys; @@ -6236,8 +6214,28 @@ EOM # Save a sequenced block type at its opening token. # Note that unsequenced block types can occur in # unbalanced code with errors but are ignored here. - $self->store_block_type( $rblock_type->[$j], $seqno ) - if ( $rblock_type->[$j] ); + if ( $rblock_type->[$j] ) { + my $block_type = $rblock_type->[$j]; + + # Store the block type with sequence number as hash key + $self->[_rblock_type_of_seqno_]->{$seqno} = $block_type; + + # and save anynymous subs and named subs in separate + # hashes to avoid future pattern tests + if ( $matches_ASUB{$block_type} ) { + $self->[_ris_asub_block_]->{$seqno} = 1; + } + + # The pre-check on space speeds up this test: + elsif ($block_type =~ /\s/ + && $block_type =~ /$SUB_PATTERN/ ) + { + $self->[_ris_sub_block_]->{$seqno} = 1; + } + else { + # not a sub type + } + } } elsif ( $is_closing_token{$token} ) {