From: pankrat Date: Mon, 9 Feb 2009 21:17:56 +0000 (+0000) Subject: Issue 2181: intern file-names to save memory X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=38645835ff9fd1129eef8e5290829330cfb65519;p=scons.git Issue 2181: intern file-names to save memory git-svn-id: http://scons.tigris.org/svn/scons/trunk@3991 fdb21ef1-2011-0410-befe-b5e4ea1792b1 --- diff --git a/src/engine/SCons/Node/FS.py b/src/engine/SCons/Node/FS.py index 5a2e1aa7..fa0a9ed2 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 0ba94b7b..6863aa14 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))