Ignore:
Timestamp:
Nov 10, 2009, 3:31:28 AM (10 years ago)
Author:
bruno
Message:
  • Do not add conf files if already present in the list (changing pbconffiles into a hash for that to still keep order as this is mandatory)
  • Small optimisations for pb_conf function usage in pb
File:
1 edited

Legend:

Unmodified
Added
Removed
  • devel/pb-modules/lib/ProjectBuilder/Conf.pm

    r891 r898  
    2424our @EXPORT = qw(pb_conf_init pb_conf_add pb_conf_read pb_conf_read_if pb_conf_get pb_conf_get_if);
    2525
    26 # Global list of conf files
    27 my @pbconffiles = ();
     26# Global hash of conf files
     27# Key is the conf file name
     28# Value is its rank
     29my %pbconffiles;
     30
     31# Global hash of cached values.
     32# We consider that values can not change during the life of pb
     33# my %cachedval;
    2834
    2935=pod
     
    5359=item B<pb_conf_init>
    5460
    55 This function setup the environment PBPROJ for project-builder function usage rfom other projects.
     61This function setup the environment PBPROJ for project-builder function usage from other projects.
    5662The first parameter is the project name.
    57 It sets up environement variables (PBPROJ)
     63It sets up environment variables (PBPROJ)
    5864
    5965=cut
     
    8187
    8288pb_log(2,"DEBUG: pb_conf_add with ".Dumper(@_)."\n");
    83 push(@pbconffiles,@_);
     89
     90foreach my $cf (@_) {
     91    # Skip already used conf files
     92    next if (defined $pbconffiles{$cf});
     93    # Add the new one at the end
     94    my $num = keys %pbconffiles;
     95    $pbconffiles{$cf} = $num;
     96}
    8497}
    8598
     
    191204my $ptr = undef;
    192205
    193 # the most important conf file is first, so read them in revers order
    194 foreach my $f (reverse @pbconffiles) {
     206# the most important conf file is first, so read them in reverse order
     207foreach my $f (reverse sort { $pbconffiles{$a} <=> $pbconffiles{$b} } keys %pbconffiles) {
    195208    $ptr = pb_conf_get_fromfile_if("$f",$ptr,@param);
    196209}
     
    234247foreach my $i (0..$#param) {
    235248    $p1 = $ptr1[$i];
     249    # Optimisation doesn't seem useful
     250    # if ((defined $p1) && (defined $cachedval{$p1})) {
     251    # $ptr1[$i] = $cachedval{$p1};
     252    # next;
     253    # }
    236254    $p2 = $ptr2[$i];
    237255    # Always try to take the param from ptr1
     
    271289    }
    272290    $ptr1[$i] = $p1;
     291    # Cache values to avoid redoing all that analyze when asked again on a known value
     292    # $cachedval{$p1} = $p1;
    273293}
    274294pb_log(2,"DEBUG: pb_conf_get output: ".Dumper(@ptr1)."\n");
Note: See TracChangeset for help on using the changeset viewer.