From 92ff6c4037b94faedaac2cc60a2f7ef9a27a4577 Mon Sep 17 00:00:00 2001 From: Steve Hancock Date: Sat, 16 Oct 2021 07:37:39 -0700 Subject: [PATCH] convert regex to hash for minor tokenizer speedup --- lib/Perl/Tidy/Tokenizer.pm | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/lib/Perl/Tidy/Tokenizer.pm b/lib/Perl/Tidy/Tokenizer.pm index ea35bfa0..d88b510a 100644 --- a/lib/Perl/Tidy/Tokenizer.pm +++ b/lib/Perl/Tidy/Tokenizer.pm @@ -5910,6 +5910,18 @@ sub report_unexpected { return; } +my %is_sigil_or_paren; +my %is_R_closing_sb; + +BEGIN { + + my @q = qw< $ & % * @ ) >; + @{is_sigil_or_paren}{@q} = (1) x scalar(@q); + + @q = qw(R ]); + @{is_R_closing_sb}{@q} = (1) x scalar(@q); +} + sub is_non_structural_brace { # Decide if a brace or bracket is structural or non-structural @@ -5939,12 +5951,15 @@ sub is_non_structural_brace { # Removed '::' to fix c074 ## $last_nonblank_token =~ /^([\$\@\*\&\%\)]|->|::)/ return ( - $last_nonblank_token =~ /^([\$\@\*\&\%\)]|->)/ + ## $last_nonblank_token =~ /^([\$\@\*\&\%\)]|->)/ + $is_sigil_or_paren{ substr( $last_nonblank_token, 0, 1 ) } + || substr( $last_nonblank_token, 0, 2 ) eq '->' # or if we follow a hash or array closing curly brace or bracket # For example, the second '{' in this is non-structural: $a{'x'}{'y'} # because the first '}' would have been given type 'R' - || $last_nonblank_type =~ /^([R\]])$/ + ##|| $last_nonblank_type =~ /^([R\]])$/ + || $is_R_closing_sb{$last_nonblank_type} ); } -- 2.39.5