]> git.donarmstrong.com Git - perltidy.git/commitdiff
minor speedup by switching from regex to hash
authorSteve Hancock <perltidy@users.sourceforge.net>
Mon, 19 Oct 2020 15:19:55 +0000 (08:19 -0700)
committerSteve Hancock <perltidy@users.sourceforge.net>
Mon, 19 Oct 2020 15:19:55 +0000 (08:19 -0700)
lib/Perl/Tidy/Formatter.pm

index 768d5aaba0aee911dd3cb11bf101a2a66089c1a0..0fa7cf7f12d2be9b6db37be08db1d5512d40183d 100644 (file)
@@ -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}++;