Issue 2181: intern file-names to save memory
authorpankrat <pankrat@fdb21ef1-2011-0410-befe-b5e4ea1792b1>
Mon, 9 Feb 2009 21:17:56 +0000 (21:17 +0000)
committerpankrat <pankrat@fdb21ef1-2011-0410-befe-b5e4ea1792b1>
Mon, 9 Feb 2009 21:17:56 +0000 (21:17 +0000)
git-svn-id: http://scons.tigris.org/svn/scons/trunk@3991 fdb21ef1-2011-0410-befe-b5e4ea1792b1

src/engine/SCons/Node/FS.py
src/engine/SCons/Scanner/__init__.py

index 5a2e1aa7808b65f3ab9b23c1ebc25b2fdb852e10..fa0a9ed286a86079819837163927238c97623582 100644 (file)
@@ -552,22 +552,24 @@ class Base(SCons.Node.Node):
         if __debug__: logInstanceCreation(self, 'Node.FS.Base')
         SCons.Node.Node.__init__(self)
 
-        self.name = name
-        self.suffix = SCons.Util.splitext(name)[1]
+        # Filenames and paths are probably reused and are intern'ed to
+        # save some memory.
+        self.name = intern(name)
+        self.suffix = intern(SCons.Util.splitext(name)[1])
         self.fs = fs
 
         assert directory, "A directory must be provided"
 
-        self.abspath = directory.entry_abspath(name)
-        self.labspath = directory.entry_labspath(name)
+        self.abspath = intern(directory.entry_abspath(name))
+        self.labspath = intern(directory.entry_labspath(name))
         if directory.path == '.':
-            self.path = name
+            self.path = intern(name)
         else:
-            self.path = directory.entry_path(name)
+            self.path = intern(directory.entry_path(name))
         if directory.tpath == '.':
-            self.tpath = name
+            self.tpath = intern(name)
         else:
-            self.tpath = directory.entry_tpath(name)
+            self.tpath = intern(directory.entry_tpath(name))
         self.path_elements = directory.path_elements + [self]
 
         self.dir = directory
@@ -612,7 +614,7 @@ class Base(SCons.Node.Node):
         except KeyError:
             pass
         result = self._get_str()
-        self._memo['_save_str'] = result
+        self._memo['_save_str'] = intern(result)
         return result
 
     def _get_str(self):
index 0ba94b7bfd3b9af4f35d248e2a50a2e9def80181..6863aa14ce9e6a8d11507c4165a1646470b42659 100644 (file)
@@ -356,7 +356,12 @@ class Classic(Current):
             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.
+            try:
+                node.includes = map(intern, includes)
+            except TypeError:
+                node.includes = includes
 
         # This is a hand-coded DSU (decorate-sort-undecorate, or
         # Schwartzian transform) pattern.  The sort key is the raw name
@@ -400,7 +405,7 @@ class ClassicCPP(Classic):
 
         n = SCons.Node.FS.find_file(include[1], paths)
 
-        return n, include[1]
+        return n, intern(include[1])
 
     def sort_key(self, include):
         return SCons.Node.FS._my_normcase(string.join(include))