From 321c1b53abdcbf710e483bb9b05b3514044bd8ac Mon Sep 17 00:00:00 2001 From: Steve Hancock Date: Mon, 3 Jan 2022 07:30:18 -0800 Subject: [PATCH] simplify -vxl logic --- lib/Perl/Tidy/VerticalAligner.pm | 49 +++++++++++++++++++------------- 1 file changed, 30 insertions(+), 19 deletions(-) diff --git a/lib/Perl/Tidy/VerticalAligner.pm b/lib/Perl/Tidy/VerticalAligner.pm index e0647b6b..3da02ef5 100644 --- a/lib/Perl/Tidy/VerticalAligner.pm +++ b/lib/Perl/Tidy/VerticalAligner.pm @@ -188,31 +188,42 @@ sub check_options { # and to configure the control hashes to them. my ($rOpts) = @_; + # All alignments are done by default %valign_control_hash = (); $valign_control_default = 1; - if ( $rOpts->{'valign-inclusion-list'} ) { - my @list = split /\s+/, $rOpts->{'valign-inclusion-list'}; - @valign_control_hash{@list} = (1) x scalar(@list); - } - - # Note that the -vxl list is done after -vil, so -vxl has priority - # in the event of duplicate entries. + # See if the user wants to exclude any alignment types ... if ( $rOpts->{'valign-exclusion-list'} ) { - my @list = split /\s+/, $rOpts->{'valign-exclusion-list'}; - @valign_control_hash{@list} = (0) x scalar(@list); - } - # '$valign_control_default' applies to types not in the hash: - # - If a '*' was entered then set it to be that default type - # - Otherwise, leave it set it to 1 - if ( defined( $valign_control_hash{'*'} ) ) { - $valign_control_default = $valign_control_hash{'*'}; - } + # The inclusion list is only relevant if there is an exclusion list + if ( $rOpts->{'valign-inclusion-list'} ) { + my @vil = split /\s+/, $rOpts->{'valign-inclusion-list'}; + @valign_control_hash{@vil} = (1) x scalar(@vil); + } - # Side comments are controlled separately and not removed by this control - if (%valign_control_hash) { - $valign_control_hash{'#'} = 1; + # Note that the -vxl list is done after -vil, so -vxl has priority + # in the event of duplicate entries. + my @vxl = split /\s+/, $rOpts->{'valign-exclusion-list'}; + @valign_control_hash{@vxl} = (0) x scalar(@vxl); + + # Optimization: revert to defaults if no exclusions. + # This could happen with -vxl=' ' and any -vil list + if ( !@vxl ) { + %valign_control_hash = (); + } + + # '$valign_control_default' applies to types not in the hash: + # - If a '*' was entered then set it to be that default type + # - Otherwise, leave it set it to 1 + if ( defined( $valign_control_hash{'*'} ) ) { + $valign_control_default = $valign_control_hash{'*'}; + } + + # Side comments are controlled separately and must be removed + # if given in a list. + if (%valign_control_hash) { + $valign_control_hash{'#'} = 1; + } } return; -- 2.39.5