From c6328564de8e8cae113ee559d769105f9f4b6003 Mon Sep 17 00:00:00 2001 From: Bob Foerster Date: Sat, 20 Nov 2010 04:39:22 +0800 Subject: Prefer xrange over range for small performance gain. range() allocates an actual list when called. xrange() is just an iterator and creates the next range item on demand. This provides a slight performance increase. In python 3, range will do what xrange does currently, but the upgrade will be handled by the 2to3 tool. (Bitbake rev: 73b40f06444cb877a5960b2aa66abf7dacbd88f0) Signed-off-by: Bob Foerster Signed-off-by: Richard Purdie --- bitbake/lib/bb/utils.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'bitbake/lib/bb/utils.py') diff --git a/bitbake/lib/bb/utils.py b/bitbake/lib/bb/utils.py index f5336dda6..4208c7934 100644 --- a/bitbake/lib/bb/utils.py +++ b/bitbake/lib/bb/utils.py @@ -194,10 +194,10 @@ def vercmp_string(val1, val2): val2 = val2[0].split('.') # add back decimal point so that .03 does not become "3" ! - for x in range(1, len(val1)): + for x in xrange(1, len(val1)): if val1[x][0] == '0' : val1[x] = '.' + val1[x] - for x in range(1, len(val2)): + for x in xrange(1, len(val2)): if val2[x][0] == '0' : val2[x] = '.' + val2[x] @@ -214,10 +214,10 @@ def vercmp_string(val1, val2): val2[-1] += '_' + val2_prepart # The above code will extend version numbers out so they # have the same number of digits. - for x in range(0, len(val1)): + for x in xrange(0, len(val1)): cmp1 = relparse(val1[x]) cmp2 = relparse(val2[x]) - for y in range(0, 3): + for y in xrange(0, 3): myret = cmp1[y] - cmp2[y] if myret != 0: __vercmp_cache__[valkey] = myret @@ -308,7 +308,7 @@ def _print_trace(body, line): # print the environment of the method min_line = max(1, line-4) max_line = min(line + 4, len(body)) - for i in range(min_line, max_line + 1): + for i in xrange(min_line, max_line + 1): if line == i: logger.error(" *** %.4d:%s" % (i, body[i-1]) ) else: -- cgit v1.2.3