From ee82742b83283a768d5c516ebb6d93e2ed8b4796 Mon Sep 17 00:00:00 2001 From: Steve Hancock Date: Mon, 19 Oct 2020 08:19:55 -0700 Subject: [PATCH] minor speedup by switching from regex to hash --- lib/Perl/Tidy/Formatter.pm | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/Perl/Tidy/Formatter.pm b/lib/Perl/Tidy/Formatter.pm index 768d5aab..0fa7cf7f 100644 --- a/lib/Perl/Tidy/Formatter.pm +++ b/lib/Perl/Tidy/Formatter.pm @@ -178,6 +178,7 @@ my ( %is_closing_token, %is_equal_or_fat_comma, %is_block_with_ci, + %is_comma_or_fat_comma, # Initialized in check_options. These are constants and could # just as well be initialized in a BEGIN block. @@ -524,6 +525,10 @@ BEGIN { @q = qw( = => ); @is_equal_or_fat_comma{@q} = (1) x scalar(@q); + @q = qw( => ); + push @q, ','; + @is_comma_or_fat_comma{@q} = (1) x scalar(@q); + # These block types can take ci. This is used by the -xci option. # Note that the 'sub' in this list is an anonymous sub. To be more correct # we could remove sub and use ASUB pattern to also handle a @@ -4515,7 +4520,7 @@ sub respace_tokens { $nonblank_token_count++; # count selected types - if ( $type =~ /^(=>|,)$/ ) { + if ( $is_comma_or_fat_comma{$type} ) { my $seqno = $seqno_stack{ $depth_next - 1 }; if ( defined($seqno) ) { $rtype_count_by_seqno->{$seqno}->{$type}++; -- 2.39.5