summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLudwig Hähne <pankrat@tigris.org>2009-02-09 21:17:56 (GMT)
committerLudwig Hähne <pankrat@tigris.org>2009-02-09 21:17:56 (GMT)
commit09bbbf9c75c93b3cf73ef3cca2d996fc131cc650 (patch)
tree6440df34ae37d7c67c83e4196d73895dd6fc35fd
parent1e725d35dba7295ec9ee660f60f643abe0308fb3 (diff)
downloadSCons-09bbbf9c75c93b3cf73ef3cca2d996fc131cc650.zip
SCons-09bbbf9c75c93b3cf73ef3cca2d996fc131cc650.tar.gz
SCons-09bbbf9c75c93b3cf73ef3cca2d996fc131cc650.tar.bz2
Issue 2181: intern file-names to save memory
-rw-r--r--src/engine/SCons/Node/FS.py20
-rw-r--r--src/engine/SCons/Scanner/__init__.py9
2 files changed, 18 insertions, 11 deletions
diff --git a/src/engine/SCons/Node/FS.py b/src/engine/SCons/Node/FS.py
index 5a2e1aa..fa0a9ed 100644
--- a/src/engine/SCons/Node/FS.py
+++ b/src/engine/SCons/Node/FS.py
@@ -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):
diff --git a/src/engine/SCons/Scanner/__init__.py b/src/engine/SCons/Scanner/__init__.py
index 0ba94b7..6863aa1 100644
--- a/src/engine/SCons/Scanner/__init__.py
+++ b/src/engine/SCons/Scanner/__init__.py
@@ -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))