]> git.donarmstrong.com Git - perltidy.git/commitdiff
simplify -vxl logic
authorSteve Hancock <perltidy@users.sourceforge.net>
Mon, 3 Jan 2022 15:30:18 +0000 (07:30 -0800)
committerSteve Hancock <perltidy@users.sourceforge.net>
Mon, 3 Jan 2022 15:30:18 +0000 (07:30 -0800)
lib/Perl/Tidy/VerticalAligner.pm

index e0647b6b40a5b0ba2e4e26b1a34be713b852f1ce..3da02ef5e02bcc99a89358596396c0f800a1853c 100644 (file)
@@ -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;