http://scons.tigris.org/issues/show_bug.cgi?id=2329
[scons.git] / src / engine / SCons / Scanner / __init__.py
index 0ba94b7bfd3b9af4f35d248e2a50a2e9def80181..3cfe4b7fe0ed2779a3d363b441a51b6170f868f8 100644 (file)
@@ -30,7 +30,6 @@ The Scanner package for the SCons software construction utility.
 __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
 
 import re
-import string
 
 import SCons.Node.FS
 import SCons.Util
@@ -56,9 +55,9 @@ def Scanner(function, *args, **kw):
     patterned on SCons code.
     """
     if SCons.Util.is_Dict(function):
-        return apply(Selector, (function,) + args, kw)
+        return Selector(function, *args, **kw)
     else:
-        return apply(Base, (function,) + args, kw)
+        return Base(function, *args, **kw)
 
 
 
@@ -92,7 +91,9 @@ class Base:
                  argument = _null,
                  skeys = _null,
                  path_function = None,
-                 node_class = SCons.Node.FS.Entry,
+                 # Node.FS.Base so that, by default, it's okay for a
+                 # scanner to return a Dir, File or Entry.
+                 node_class = SCons.Node.FS.Base,
                  node_factory = None,
                  scan_check = None,
                  recursive = None):
@@ -216,7 +217,7 @@ class Base:
         nodes = []
         for l in list:
             if self.node_class and not isinstance(l, self.node_class):
-                l = apply(node_factory, (l,), kw)
+                l = node_factory(l, **kw)
             nodes.append(l)
         return nodes
 
@@ -278,7 +279,7 @@ class Selector(Base):
     for custom modules that may be out there.)
     """
     def __init__(self, dict, *args, **kw):
-        apply(Base.__init__, (self, None,)+args, kw)
+        Base.__init__(self, None, *args, **kw)
         self.dict = dict
         self.skeys = dict.keys()
 
@@ -307,7 +308,7 @@ class Current(Base):
         def current_check(node, env):
             return not node.has_builder() or node.is_up_to_date()
         kw['scan_check'] = current_check
-        apply(Base.__init__, (self,) + args, kw)
+        Base.__init__(self, *args, **kw)
 
 class Classic(Current):
     """
@@ -337,7 +338,7 @@ class Classic(Current):
         kw['skeys'] = suffixes
         kw['name'] = name
 
-        apply(Current.__init__, (self,) + args, kw)
+        Current.__init__(self, *args, **kw)
 
     def find_include(self, include, source_dir, path):
         n = SCons.Node.FS.find_file(include, (source_dir,) + tuple(path))
@@ -352,11 +353,13 @@ class Classic(Current):
     def scan(self, node, path=()):
 
         # cache the includes list in node so we only scan it once:
-        if node.includes != None:
+        if node.includes is not None:
             includes = node.includes
         else:
             includes = self.find_include_names (node)
-            node.includes = includes
+            # Intern the names of the include files. Saves some memory
+            # if the same header is included many times.
+            node.includes = list(map(SCons.Util.silent_intern, includes))
 
         # This is a hand-coded DSU (decorate-sort-undecorate, or
         # Schwartzian transform) pattern.  The sort key is the raw name
@@ -375,12 +378,9 @@ class Classic(Current):
                 SCons.Warnings.warn(SCons.Warnings.DependencyWarning,
                                     "No dependency generated for file: %s (included from: %s) -- file not found" % (i, node))
             else:
-                sortkey = self.sort_key(include)
-                nodes.append((sortkey, n))
+                nodes.append((self.sort_key(include), n))
 
-        nodes.sort()
-        nodes = map(lambda pair: pair[1], nodes)
-        return nodes
+        return [pair[1] for pair in sorted(nodes)]
 
 class ClassicCPP(Classic):
     """
@@ -400,10 +400,11 @@ class ClassicCPP(Classic):
 
         n = SCons.Node.FS.find_file(include[1], paths)
 
-        return n, include[1]
+        i = SCons.Util.silent_intern(include[1])
+        return n, i
 
     def sort_key(self, include):
-        return SCons.Node.FS._my_normcase(string.join(include))
+        return SCons.Node.FS._my_normcase(' '.join(include))
 
 # Local Variables:
 # tab-width:4