[tbb-commits] [rbm/master] Bug 40005: Optimize the config function

gk at torproject.org gk at torproject.org
Fri Sep 11 17:14:09 UTC 2020


commit ee2d60d8274fe3b88454683eb11b1d76981b6c46
Author: Nicolas Vigier <boklm at torproject.org>
Date:   Thu Sep 10 19:03:09 2020 +0200

    Bug 40005: Optimize the config function
    
    Optimize the config function by reducing the number of calls to
    config_p.
---
 lib/RBM.pm | 35 ++++++++++++++++++++++-------------
 1 file changed, 22 insertions(+), 13 deletions(-)

diff --git a/lib/RBM.pm b/lib/RBM.pm
index c4d5a82..6277de4 100644
--- a/lib/RBM.pm
+++ b/lib/RBM.pm
@@ -141,38 +141,47 @@ sub config {
     my @targets = @{get_targets($project, $options, \@_)};
     my @step = ('steps', get_step($project, $options, $config->{step}, \@_));
     my $as_array = $options->{as_array};
+    my %ok_config = ( HASH => 1, CODE => 1 );
     foreach my $path (@_) {
+        my $config_path = config_p($config, $project, $options, @$path);
+        next unless $ok_config{ref $config_path};
         my @l;
-        push @l, config_p($config, $project, $options, @$path, "override.$name->[0]")
+        push @l, config_p($config_path, $project, $options, "override.$name->[0]")
                 if @$name == 1;
         if (!$as_array) {
             @l = grep { defined $_ } @l;
             return $l[0] if @l;
         }
         # 1st priority: targets + step matching
-        foreach my $t (@targets) {
-            push @l, config_p($config, $project, $options, @$path, @step, 'targets', $t, @$name);
-            if (!$as_array) {
-                @l = grep { defined $_ } @l;
-                return $l[0] if @l;
+        my $config_step_targets = config_p($config_path, $project, $options, @step, 'targets');
+        if ($ok_config{ref $config_step_targets}) {
+            foreach my $t (@targets) {
+                push @l, config_p($config_step_targets, $project, $options, $t, @$name);
+                if (!$as_array) {
+                    @l = grep { defined $_ } @l;
+                    return $l[0] if @l;
+                }
             }
         }
         # 2nd priority: step maching
-        push @l, config_p($config, $project, $options, @$path, @step, @$name);
+        push @l, config_p($config_path, $project, $options, @step, @$name);
         if (!$as_array) {
             @l = grep { defined $_ } @l;
             return $l[0] if @l;
         }
         # 3rd priority: target matching
-        foreach my $t (@targets) {
-            push @l, config_p($config, $project, $options, @$path, 'targets', $t, @$name);
-            if (!$as_array) {
-                @l = grep { defined $_ } @l;
-                return $l[0] if @l;
+        my $config_targets = config_p($config_path, $project, $options, 'targets');
+        if ($ok_config{ref $config_targets}) {
+            foreach my $t (@targets) {
+                push @l, config_p($config_targets, $project, $options, $t, @$name);
+                if (!$as_array) {
+                    @l = grep { defined $_ } @l;
+                    return $l[0] if @l;
+                }
             }
         }
         # last priority: no target and no step matching
-        push @l, config_p($config, $project, $options, @$path, @$name);
+        push @l, config_p($config_path, $project, $options, @$name);
         if (!$as_array) {
             @l = grep { defined $_ } @l;
             return $l[0] if @l;



More information about the tbb-commits mailing list