From 646d64748ab28dca9e30823ab6472e06cf9bd981 Mon Sep 17 00:00:00 2001 From: William Deegan Date: Fri, 30 Jun 2017 11:48:48 -0700 Subject: Micro optimization "." in string is approx 10x faster than string.find('.') >= 0 according to timeit testing. --- src/engine/SCons/Subst.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/engine/SCons/Subst.py b/src/engine/SCons/Subst.py index 3c9b390..9aa4bbc 100644 --- a/src/engine/SCons/Subst.py +++ b/src/engine/SCons/Subst.py @@ -438,7 +438,7 @@ def scons_subst(strSubst, env, mode=SUBST_RAW, target=None, source=None, gvars={ return s else: key = s[1:] - if key[0] == '{' or key.find('.') >= 0: + if key[0] == '{' or '.' in key: if key[0] == '{': key = key[1:-1] try: -- cgit v0.12 From bb7fd9c6b0348092a6825f3572b557c0b24dd4b5 Mon Sep 17 00:00:00 2001 From: William Deegan Date: Mon, 3 Jul 2017 15:06:02 -0400 Subject: Add an alternative to evaluate lvar vs gvar --- bench/lvars-gvars.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/bench/lvars-gvars.py b/bench/lvars-gvars.py index bdb09ef..1511203 100644 --- a/bench/lvars-gvars.py +++ b/bench/lvars-gvars.py @@ -45,6 +45,12 @@ def Func4(var, gvars, lvars): except NameError: x = '' +def Func5(var, gvars, lvars): + """Chained get with default values""" + for i in IterationList: + x = lvars.get(var,gvars.get(var,'')) + + # Data to pass to the functions on each run. Each entry is a # three-element tuple: # -- cgit v0.12 From 3adbe147e6d8dcf9a9b14fddf62f22e067ca5578 Mon Sep 17 00:00:00 2001 From: William Deegan Date: Mon, 3 Jul 2017 15:10:01 -0400 Subject: PY2/3 test framework changes. POpen will alway set universal_newlines if encoding is set. So we don't set encoding and pass universal_newlines=False. Then we'll need to do the decode explicitly for PY3 --- QMTest/TestCmd.py | 33 ++++++++++++++------------------- 1 file changed, 14 insertions(+), 19 deletions(-) diff --git a/QMTest/TestCmd.py b/QMTest/TestCmd.py index 61da8b9..00d61d3 100644 --- a/QMTest/TestCmd.py +++ b/QMTest/TestCmd.py @@ -1407,29 +1407,22 @@ class TestCmd(object): self.timer = threading.Timer(float(timeout), self._timeout) self.timer.start() - if sys.version_info[0] == 3 and sys.platform == 'win32': + if IS_PY3 and sys.platform == 'win32': # Set this otherwist stdout/stderr pipes default to # windows default locale cp1252 which will throw exception # if using non-ascii characters. # For example test/Install/non-ascii-name.py os.environ['PYTHONIOENCODING'] = 'utf-8' - if sys.version_info[0] == 2 or sys.version_info[0:2] < (3, 6): - p = Popen(cmd, - stdin=stdin, - stdout=subprocess.PIPE, - stderr=stderr_value, - env=os.environ, - universal_newlines=False) - else: - # this will only work on py3.6, encoding - p = Popen(cmd, - stdin=stdin, - stdout=subprocess.PIPE, - stderr=stderr_value, - env=os.environ, - universal_newlines=universal_newlines, - encoding='utf-8') + # It seems that all pythons up to py3.6 still set text mode if you set encoding. + # TODO: File enhancement request on python to propagate universal_newlines even + # if encoding is set.hg c + p = Popen(cmd, + stdin=stdin, + stdout=subprocess.PIPE, + stderr=stderr_value, + env=os.environ, + universal_newlines=False) self.process = p return p @@ -1452,7 +1445,9 @@ class TestCmd(object): if not stream: return stream - elif sys.version_info[0] == 3 and sys.version_info[1] < 6: + # TODO: Run full tests on both platforms and see if this fixes failures + # It seems that py3.6 still sets text mode if you set encoding. + elif sys.version_info[0] == 3:# TODO and sys.version_info[1] < 6: stream = stream.decode('utf-8') stream = stream.replace('\r\n', '\n') elif sys.version_info[0] == 2: @@ -1521,7 +1516,7 @@ class TestCmd(object): if is_List(stdin): stdin = ''.join(stdin) - if stdin and sys.version_info[0] == 3 and sys.version_info[1] < 6: + if stdin and IS_PY3 and sys.version_info[1] < 6: stdin = bytearray(stdin,'utf-8') # TODO(sgk): figure out how to re-use the logic in the .finish() -- cgit v0.12 From 0eaef4f2b8064882e7497695ba352c719b543dc8 Mon Sep 17 00:00:00 2001 From: William Deegan Date: Thu, 6 Jul 2017 11:54:40 -0400 Subject: python micro optimization in faster than find --- src/engine/SCons/PathList.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/engine/SCons/PathList.py b/src/engine/SCons/PathList.py index 77e30c4..76cbeab 100644 --- a/src/engine/SCons/PathList.py +++ b/src/engine/SCons/PathList.py @@ -104,11 +104,11 @@ class _PathList(object): pl = [] for p in pathlist: try: - index = p.find('$') + found = '$' in p except (AttributeError, TypeError): type = TYPE_OBJECT else: - if index == -1: + if not found: type = TYPE_STRING_NO_SUBST else: type = TYPE_STRING_SUBST -- cgit v0.12 From d2b59cc6d18e5d3139f623ab4285de34b3dd5596 Mon Sep 17 00:00:00 2001 From: William Deegan Date: Mon, 10 Jul 2017 15:01:04 -0400 Subject: py2/3 always convert stdin to bytes if py3. Previously was 3.5 only --- QMTest/TestCmd.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/QMTest/TestCmd.py b/QMTest/TestCmd.py index 00d61d3..0aab9a8 100644 --- a/QMTest/TestCmd.py +++ b/QMTest/TestCmd.py @@ -1516,8 +1516,8 @@ class TestCmd(object): if is_List(stdin): stdin = ''.join(stdin) - if stdin and IS_PY3 and sys.version_info[1] < 6: - stdin = bytearray(stdin,'utf-8') + if stdin and IS_PY3:# and sys.version_info[1] < 6: + stdin = to_bytes(stdin) # TODO(sgk): figure out how to re-use the logic in the .finish() # method above. Just calling it from here causes problems with -- cgit v0.12