From: Alexandre Duret-Lutz Date: Sun, 8 Aug 2004 20:14:34 +0000 (+0000) Subject: * lib/Automake/DisjConditions.pm (new): Precompute 'string' and 'conds' X-Git-Tag: v1.10.2~488 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=d7b81c1ed1405fdef10ee7e83c8aa2f6fb50756e;p=platform%2Fupstream%2Fautomake.git * lib/Automake/DisjConditions.pm (new): Precompute 'string' and 'conds' in place instead of as a side-effect of calling ->string and ->conds. This saves method-lookup time, simplify ->string and ->conds, and allows to create the object only when necessary. (string, conds): Simplify, now that the result is precomputed. --- diff --git a/ChangeLog b/ChangeLog index 59caab1..f9b76cc 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,11 @@ 2004-08-08 Alexandre Duret-Lutz + * lib/Automake/DisjConditions.pm (new): Precompute 'string' and 'conds' + in place instead of as a side-effect of calling ->string and ->conds. + This saves method-lookup time, simplify ->string and ->conds, and + allows to create the object only when necessary. + (string, conds): Simplify, now that the result is precomputed. + * automake.in (%am_file_cache): New hash. (make_paragraphs): Cache .am files with comments stripped to save some useless input and substitutions. diff --git a/lib/Automake/DisjConditions.pm b/lib/Automake/DisjConditions.pm index 45745c4..7e80e11 100644 --- a/lib/Automake/DisjConditions.pm +++ b/lib/Automake/DisjConditions.pm @@ -145,11 +145,7 @@ use vars '%_disjcondition_singletons'; sub new ($;@) { my ($class, @conds) = @_; - my $self = { - hash => {}, - }; - bless $self, $class; - + my @filtered_conds = (); for my $cond (@conds) { confess "`$cond' isn't a reference" unless ref $cond; @@ -161,19 +157,40 @@ sub new ($;@) # DisjConditions as false for this reason. next if $cond->false; - # Store conditions as keys AND as values, because blessed - # objects are converted to string when used as keys (so - # at least we still have the value when we need to call - # a method). - $self->{'hash'}{$cond} = $cond; + push @filtered_conds, $cond; } - my $key = $self->string; - if (exists $_disjcondition_singletons{$key}) + my $string; + if (@filtered_conds) + { + @filtered_conds = sort { $a->string cmp $b->string } @filtered_conds; + $string = join (' | ', map { $_->string } @filtered_conds); + } + else { - return $_disjcondition_singletons{$key}; + $string = 'FALSE'; } - $_disjcondition_singletons{$key} = $self; + + # Return any existing identical DisjConditions. + my $me = $_disjcondition_singletons{$string}; + return $me if $me; + + # Else, create a new DisjConditions. + + # Store conditions as keys AND as values, because blessed + # objects are converted to string when used as keys (so + # at least we still have the value when we need to call + # a method). + my %h = map {$_ => $_} @filtered_conds; + + my $self = { + hash => \%h, + string => $string, + conds => \@filtered_conds, + }; + bless $self, $class; + + $_disjcondition_singletons{$string} = $self; return $self; } @@ -186,11 +203,7 @@ Return the list of C objects involved in C<$set>. sub conds ($ ) { my ($self) = @_; - return @{$self->{'conds'}} if exists $self->{'conds'}; - my @conds = values %{$self->{'hash'}}; - @conds = sort { $a->string cmp $b->string } @conds; - $self->{'conds'} = [@conds]; - return @conds; + return @{$self->{'conds'}}; } =item C<$cond = $set-Eone_cond> @@ -241,21 +254,7 @@ Build a string which denotes the C. sub string ($ ) { my ($self) = @_; - - return $self->{'string'} if defined $self->{'string'}; - - my $res = ''; - if ($self->false) - { - $res = 'FALSE'; - } - else - { - $res = join (' | ', map { $_->string } $self->conds); - } - - $self->{'string'} = $res; - return $res; + return $self->{'string'}; } =item C<$cond-Ehuman>