1
0
mirror of https://git.yoctoproject.org/poky synced 2026-06-03 01:40:07 +00:00

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 <robert@erafx.com>
Signed-off-by: Richard Purdie <rpurdie@linux.intel.com>
This commit is contained in:
Bob Foerster
2010-11-20 04:39:22 +08:00
committed by Richard Purdie
parent e81fc749f3
commit c6328564de
4 changed files with 37 additions and 37 deletions
+5 -5
View File
@@ -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: