automake-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

FYI: speed up am_primary_prefixes and check_typo


From: Alexandre Duret-Lutz
Subject: FYI: speed up am_primary_prefixes and check_typo
Date: Sun, 08 Aug 2004 19:10:47 +0200
User-agent: Gnus/5.1003 (Gnus v5.10.3) Emacs/21.3.50 (gnu/linux)

I'm checking this in.

(Running Automake on Coreutils went down from 7.43s to 6.45s.)

2004-08-08  Alexandre Duret-Lutz  <address@hidden>

        * lib/Automake/Variable.pm (%_primary_dict): New hash.
        (_new, variable_delete): Update %_primary_dict.
        (variables): Accept an optional $suffix argument.
        * automake.in (check_typos, am_primary_prefixes): Use that
        optional argument to restrict the loops over the variables we are
        interested in.

Index: automake.in
===================================================================
RCS file: /cvs/automake/automake/automake.in,v
retrieving revision 1.1575
diff -u -r1.1575 automake.in
--- automake.in 5 Aug 2004 22:30:41 -0000       1.1575
+++ automake.in 8 Aug 2004 17:08:50 -0000
@@ -2684,31 +2684,23 @@
   # It is ok if the user sets this particular variable.
   set_seen 'AM_LDFLAGS';
 
-  foreach my $var (variables)
+  foreach my $primary ('SOURCES', 'LIBADD', 'LDADD', 'LDFLAGS', 'DEPENDENCIES')
     {
-      my $varname = $var->name;
-      # A configure variable is always legitimate.
-      next if exists $configure_vars{$varname};
-
-      my $check = 0;
-      foreach my $primary ('_SOURCES', '_LIBADD', '_LDADD', '_LDFLAGS',
-                          '_DEPENDENCIES')
+      foreach my $var (variables $primary)
        {
-         if ($varname =~ /^(.*)$primary$/)
+         my $varname = $var->name;
+         # A configure variable is always legitimate.
+         next if exists $configure_vars{$varname};
+
+         for my $cond ($var->conditions->conds)
            {
-             $check = $1;
-             last;
+             $varname =~ /^(?:nobase_)?(?:dist_|nodist_)?(.*)_[[:alnum:]]+$/;
+             msg_var ('syntax', $var, "variable `$varname' is defined but no"
+                      . " program or\nlibrary has `$1' as canonic name"
+                      . " (possible typo)")
+               unless $var->rdef ($cond)->seen;
            }
        }
-      next unless $check;
-
-      for my $cond ($var->conditions->conds)
-       {
-         msg_var ('syntax', $var, "variable `$varname' is defined but no"
-                  . " program or\nlibrary has `$check' as canonic name"
-                  . " (possible typo)")
-           unless $var->rdef ($cond)->seen;
-       }
     }
 }
 
@@ -6497,7 +6489,7 @@
   local $_;
   my %valid = map { $_ => 0 } @prefixes;
   $valid{'EXTRA'} = 0;
-  foreach my $var (variables)
+  foreach my $var (variables $primary)
     {
       # Automake is allowed to define variables that look like primaries
       # but which aren't.  E.g. INSTALL_sh_DATA.
@@ -6511,7 +6503,7 @@
 
       my $varname = $var->name;
 
-      if ($varname =~ /^(nobase_)?(dist_|nodist_)?(.*)_$primary$/)
+      if ($varname =~ /^(nobase_)?(dist_|nodist_)?(.*)_[[:alnum:]]+$/)
        {
          my ($base, $dist, $X) = ($1 || '', $2 || '', $3 || '');
          if ($dist ne '' && ! $can_dist)
@@ -6539,6 +6531,10 @@
              $valid{"$base$dist$X"} = 1;
            }
        }
+      else
+       {
+         prog_error "unexpected variable name: $varname";
+       }
     }
 
   # Return only those which are actually defined.
Index: lib/Automake/Variable.pm
===================================================================
RCS file: /cvs/automake/automake/lib/Automake/Variable.pm,v
retrieving revision 1.35
diff -u -r1.35 Variable.pm
--- lib/Automake/Variable.pm    11 Jul 2004 22:13:20 -0000      1.35
+++ lib/Automake/Variable.pm    8 Aug 2004 17:08:54 -0000
@@ -295,17 +295,33 @@
   $_hooks{$var} = $fun;
 }
 
-=item C<variables>
+=item C<variables ([$suffix])>
 
 Returns the list of all L<Automake::Variable> instances.  (I.e., all
-variables defined so far.)
+variables defined so far.)  If C<$suffix> is supplied, return only
+the L<Automake::Variable> instances that ends with C<_$suffix>.
 
 =cut
 
-use vars '%_variable_dict';
-sub variables ()
+use vars '%_variable_dict', '%_primary_dict';
+sub variables (;$)
 {
-  return values %_variable_dict;
+  my ($suffix) = @_;
+  if ($suffix)
+    {
+      if (exists $_primary_dict{$suffix})
+       {
+         return values %{$_primary_dict{$suffix}};
+       }
+      else
+       {
+         return ();
+       }
+    }
+  else
+    {
+      return values %_variable_dict;
+    }
 }
 
 =item C<Automake::Variable::reset>
@@ -318,6 +334,7 @@
 sub reset ()
 {
   %_variable_dict = ();
+  %_primary_dict = ();
   %_appendvar = ();
   @_var_order = ();
   %_gen_varname = ();
@@ -420,6 +437,10 @@
   my $self = Automake::Item::new ($class, $name);
   $self->{'scanned'} = 0;
   $_variable_dict{$name} = $self;
+  if ($name =~ /_([[:alnum:]]+)$/)
+    {
+      $_primary_dict{$1}{$name} = $self;
+    }
   return $self;
 }
 
@@ -1012,6 +1033,10 @@
          delete $_variable_dict{$var}{'defs'}{$cond};
        }
     }
+  if ($var =~ /_([[:alnum:]]+)$/)
+    {
+      delete $_primary_dict{$1}{$var};
+    }
 }
 
 =item C<$str = variables_dump>
-- 
Alexandre Duret-Lutz





reply via email to

[Prev in Thread] Current Thread [Next in Thread]