summaryrefslogtreecommitdiffstats
path: root/bench
diff options
context:
space:
mode:
authorGreg Noel <GregNoel@tigris.org>2010-03-27 07:39:52 (GMT)
committerGreg Noel <GregNoel@tigris.org>2010-03-27 07:39:52 (GMT)
commit59ed0a109bf5add2efcef459080837b11066c6fb (patch)
treefff879b4f9676a72e16c0f7b4dd969f050038b4f /bench
parent00a3188193ba1feef927cf18e7f5fc20ad71b848 (diff)
downloadSCons-59ed0a109bf5add2efcef459080837b11066c6fb.zip
SCons-59ed0a109bf5add2efcef459080837b11066c6fb.tar.gz
SCons-59ed0a109bf5add2efcef459080837b11066c6fb.tar.bz2
http://scons.tigris.org/issues/show_bug.cgi?id=2329
Applied a number of idiomatic changes. Uses of the 'sort()' method were converted into calls of 'sorted()' when possible and the sorted() expression was inserted into a subsequent statement whenever that made sense. The statement 'while 1:' was changed to 'while True:'. Names from the 'types' module (e.g., 'types.FooType') were converted to the equivalent build-in type (e.g., 'foo'). Comparisons between types were changed to use 'isinstance()'.
Diffstat (limited to 'bench')
-rw-r--r--bench/bench.py5
-rw-r--r--bench/env.__setitem__.py8
-rw-r--r--bench/is_types.py79
3 files changed, 46 insertions, 46 deletions
diff --git a/bench/bench.py b/bench/bench.py
index e076e43..2acc29f 100644
--- a/bench/bench.py
+++ b/bench/bench.py
@@ -94,10 +94,9 @@ exec(open(args[0], 'rU').read())
try:
FunctionList
except NameError:
- function_names = [x for x in locals().keys() if x[:4] == FunctionPrefix]
- function_names.sort()
+ function_names = sorted([x for x in locals().keys() if x[:4] == FunctionPrefix])
l = [locals()[f] for f in function_names]
- FunctionList = [f for f in l if type(f) == types.FunctionType]
+ FunctionList = [f for f in l if isinstance(f, types.FunctionType)]
IterationList = [None] * Iterations
diff --git a/bench/env.__setitem__.py b/bench/env.__setitem__.py
index 61d8c1e..36a7672 100644
--- a/bench/env.__setitem__.py
+++ b/bench/env.__setitem__.py
@@ -37,13 +37,11 @@ def times(num=1000000, init='', title='Results:', **statements):
t = Timing(n, num, init, s)
t.timeit()
timings.append(t)
-
+
print
print title
- l = []
- for i in timings: l.append((i.getResult(),i.name))
- l.sort()
- for i in l: print " %9.3f s %s" % i
+ for i in sorted([(i.getResult(),i.name) for i in timings]):
+ print " %9.3f s %s" % i
# Import the necessary local SCons.* modules used by some of our
# alternative implementations below, first manipulating sys.path so
diff --git a/bench/is_types.py b/bench/is_types.py
index f9f7677..9cc397e 100644
--- a/bench/is_types.py
+++ b/bench/is_types.py
@@ -15,7 +15,7 @@ except ImportError:
# and modified slightly for use with SCons.
class UserString:
def __init__(self, seq):
- if type(seq) == type(''):
+ if isinstance(seq, str):
self.data = seq
elif isinstance(seq, UserString):
self.data = seq.data[:]
@@ -60,11 +60,14 @@ except ImportError:
__rmul__ = __mul__
InstanceType = types.InstanceType
-DictType = types.DictType
-ListType = types.ListType
-StringType = types.StringType
-if hasattr(types, 'UnicodeType'):
- UnicodeType = types.UnicodeType
+DictType = dict
+ListType = list
+StringType = str
+try: unicode
+except NameError:
+ UnicodeType = None
+else:
+ UnicodeType = unicode
# The original implementations, pretty straightforward checks for the
@@ -72,19 +75,19 @@ if hasattr(types, 'UnicodeType'):
# User* type.
def original_is_Dict(e):
- return type(e) is types.DictType or isinstance(e, UserDict)
+ return isinstance(e, dict) or isinstance(e, UserDict)
def original_is_List(e):
- return type(e) is types.ListType or isinstance(e, UserList)
+ return isinstance(e, list) or isinstance(e, UserList)
-if hasattr(types, 'UnicodeType'):
+if UnicodeType is not None:
def original_is_String(e):
- return type(e) is types.StringType \
- or type(e) is types.UnicodeType \
+ return isinstance(e, str) \
+ or isinstance(e, unicode) \
or isinstance(e, UserString)
else:
def original_is_String(e):
- return type(e) is types.StringType or isinstance(e, UserString)
+ return isinstance(e, str) or isinstance(e, UserString)
@@ -93,22 +96,22 @@ else:
# type.
def checkInstanceType_is_Dict(e):
- return type(e) is types.DictType or \
- (type(e) is types.InstanceType and isinstance(e, UserDict))
+ return isinstance(e, dict) or \
+ (isinstance(e, types.InstanceType) and isinstance(e, UserDict))
def checkInstanceType_is_List(e):
- return type(e) is types.ListType \
- or (type(e) is types.InstanceType and isinstance(e, UserList))
+ return isinstance(e, list) \
+ or (isinstance(e, types.InstanceType) and isinstance(e, UserList))
-if hasattr(types, 'UnicodeType'):
+if UnicodeType is not None:
def checkInstanceType_is_String(e):
- return type(e) is types.StringType \
- or type(e) is types.UnicodeType \
- or (type(e) is types.InstanceType and isinstance(e, UserString))
+ return isinstance(e, str) \
+ or isinstance(e, unicode) \
+ or (isinstance(e, types.InstanceType) and isinstance(e, UserString))
else:
def checkInstanceType_is_String(e):
- return type(e) is types.StringType \
- or (type(e) is types.InstanceType and isinstance(e, UserString))
+ return isinstance(e, str) \
+ or (isinstance(e, types.InstanceType) and isinstance(e, UserString))
@@ -117,24 +120,24 @@ else:
def cache_type_e_is_Dict(e):
t = type(e)
- return t is types.DictType or \
+ return t is dict or \
(t is types.InstanceType and isinstance(e, UserDict))
def cache_type_e_is_List(e):
t = type(e)
- return t is types.ListType \
+ return t is list \
or (t is types.InstanceType and isinstance(e, UserList))
-if hasattr(types, 'UnicodeType'):
+if UnicodeType is not None:
def cache_type_e_is_String(e):
t = type(e)
- return t is types.StringType \
- or t is types.UnicodeType \
+ return t is str \
+ or t is unicode \
or (t is types.InstanceType and isinstance(e, UserString))
else:
def cache_type_e_is_String(e):
t = type(e)
- return t is types.StringType \
+ return t is str \
or (t is types.InstanceType and isinstance(e, UserString))
@@ -153,7 +156,7 @@ def global_cache_type_e_is_List(e):
return t is ListType \
or (t is InstanceType and isinstance(e, UserList))
-if hasattr(types, 'UnicodeType'):
+if UnicodeType is not None:
def global_cache_type_e_is_String(e):
t = type(e)
return t is StringType \
@@ -171,18 +174,18 @@ else:
# to their corresponding underlying types.
instanceTypeMap = {
- UserDict : types.DictType,
- UserList : types.ListType,
- UserString : types.StringType,
+ UserDict : dict,
+ UserList : list,
+ UserString : str,
}
-if hasattr(types, 'UnicodeType'):
+if UnicodeType is not None:
def myType(obj):
t = type(obj)
if t is types.InstanceType:
t = instanceTypeMap.get(obj.__class__, t)
- elif t is types.UnicodeType:
- t = types.StringType
+ elif t is unicode:
+ t = str
return t
else:
def myType(obj):
@@ -192,13 +195,13 @@ else:
return t
def myType_is_Dict(e):
- return myType(e) is types.DictType
+ return myType(e) is dict
def myType_is_List(e):
- return myType(e) is types.ListType
+ return myType(e) is list
def myType_is_String(e):
- return myType(e) is types.StringType
+ return myType(e) is str