From fafe51a438c87f0e70e4dfb4927b367fd9887a84 Mon Sep 17 00:00:00 2001 From: stevenknight Date: Fri, 5 Apr 2002 09:39:27 +0000 Subject: [PATCH] Various performance enhancements. (Anthony Roach) git-svn-id: http://scons.tigris.org/svn/scons/trunk@321 fdb21ef1-2011-0410-befe-b5e4ea1792b1 --- src/CHANGES.txt | 6 ++++++ src/engine/SCons/Builder.py | 8 +++----- src/engine/SCons/Node/__init__.py | 6 +----- src/engine/SCons/Util.py | 23 +++++++++++++++++++++++ src/engine/SCons/UtilTests.py | 5 +++++ 5 files changed, 38 insertions(+), 10 deletions(-) diff --git a/src/CHANGES.txt b/src/CHANGES.txt index fee76427..da541f33 100644 --- a/src/CHANGES.txt +++ b/src/CHANGES.txt @@ -20,6 +20,12 @@ RELEASE 0.07 - - Significant internal restructuring of Scanners and Taskmaster. + - Added new --debug=dtree option. + + - Fixes for --profile option. + + - Performance improvement in construction variable substitution. + RELEASE 0.06 - Thu, 28 Mar 2002 01:24:29 -0600 diff --git a/src/engine/SCons/Builder.py b/src/engine/SCons/Builder.py index e7af01ce..2ccba000 100644 --- a/src/engine/SCons/Builder.py +++ b/src/engine/SCons/Builder.py @@ -64,7 +64,7 @@ def _init_nodes(builder, env, tlist, slist): the proper Builder information. """ for s in slist: - src_key = slist[0].scanner_key() # the file suffix + src_key = s.scanner_key() # the file suffix scanner = env.get_scanner(src_key) if scanner: s.source_scanner = scanner @@ -115,10 +115,8 @@ class BuilderBase: """ def adjustixes(files, pre, suf): ret = [] - if SCons.Util.is_String(files): - files = string.split(files) - if not SCons.Util.is_List(files): - files = [files] + files = SCons.Util.argmunge(files) + for f in files: if SCons.Util.is_String(f): if pre and f[:len(pre)] != pre: diff --git a/src/engine/SCons/Node/__init__.py b/src/engine/SCons/Node/__init__.py index 67ad7431..9c39d25c 100644 --- a/src/engine/SCons/Node/__init__.py +++ b/src/engine/SCons/Node/__init__.py @@ -347,11 +347,7 @@ def arg2nodes(arg, node_factory=None): in the list are not split at spaces. In all cases, the function returns a list of Node instances.""" - narg = arg - if SCons.Util.is_String(arg): - narg = string.split(arg) - elif not SCons.Util.is_List(arg): - narg = [arg] + narg = SCons.Util.argmunge(arg) nodes = [] for v in narg: diff --git a/src/engine/SCons/Util.py b/src/engine/SCons/Util.py index ef998a94..e31b1b08 100644 --- a/src/engine/SCons/Util.py +++ b/src/engine/SCons/Util.py @@ -196,6 +196,12 @@ def scons_subst(strSubst, globals, locals, remove=None): surrounded by curly braces to separate the name from trailing characters. """ + + # Make the common case (i.e. nothing to do) fast: + if string.find(strSubst, "$") == -1 \ + and (remove is None or remove.search(strSubst) is None): + return strSubst + cmd_list = scons_subst_list(strSubst, globals, locals, remove) return string.join(map(string.join, cmd_list), '\n') @@ -238,6 +244,23 @@ def is_Dict(e): def is_List(e): return type(e) is types.ListType or isinstance(e, UserList.UserList) +def argmunge(arg): + """This function converts a string or list into a list of strings or Nodes. + It follows the rules outlined in the SCons design document by accepting + any of the following inputs: + - A single string containing names separated by spaces. These will be + split apart at the spaces. + - A single None instance + - A list containing either strings or Node instances. Any strings + in the list are not split at spaces. + In all cases, the function returns a list of Nodes and strings.""" + if is_List(arg): + return arg + elif is_String(arg): + return string.split(arg) + else: + return [arg] + if hasattr(types, 'UnicodeType'): def is_String(e): return type(e) is types.StringType \ diff --git a/src/engine/SCons/UtilTests.py b/src/engine/SCons/UtilTests.py index d230a08d..60d7d4d2 100644 --- a/src/engine/SCons/UtilTests.py +++ b/src/engine/SCons/UtilTests.py @@ -208,6 +208,11 @@ class UtilTestCase(unittest.TestCase): if hasattr(types, 'UnicodeType'): exec "assert not is_List(u'')" + def test_argmunge(self): + assert argmunge("foo bar") == ["foo", "bar"] + assert argmunge(["foo", "bar"]) == ["foo", "bar"] + assert argmunge("foo") == ["foo"] + def test_is_String(self): assert is_String("") if hasattr(types, 'UnicodeType'): -- 2.26.2