aboutsummaryrefslogtreecommitdiffstats
path: root/bitbake
diff options
context:
space:
mode:
authorChris Larson <clarson@mvista.com>2009-06-11 13:10:04 -0700
committerRichard Purdie <rpurdie@linux.intel.com>2010-03-22 15:01:59 +0000
commitada2a8494a88b59de25c0a44fce30190f560eff4 (patch)
tree67f60f7ae769b74815757e45c12e4d694270a802 /bitbake
parent9d9b47bae4b880ec57eda0e647b1d24fbc3ba3cf (diff)
downloadopenembedded-core-contrib-ada2a8494a88b59de25c0a44fce30190f560eff4.tar.gz
Avoid unnecessary calls to keys() when iterating over dictionaries.
dict objects provide an __iter__ method for the iteration which gives you the keys, so calling keys directly is unnecessary, and isn't really a best practice. The only time you really need to call the keys is if there's a danger of the dict changing out from underneith you, either due to external forces or due to modification of the iterable in the loop. Iterations over os.environ are apparently subject to such changes, so they must continue to use keys(). As an aside, also switches a couple spots to using sorted() rather than creating a temporary list with keys() and sorting that. (Bitbake rev: 5b6ccb16c6e71e23dac6920cd2df994d67c2587b) Signed-off-by: Chris Larson <clarson@mvista.com> Signed-off-by: Richard Purdie <rpurdie@linux.intel.com>
Diffstat (limited to 'bitbake')
-rw-r--r--bitbake/lib/bb/cooker.py9
-rw-r--r--bitbake/lib/bb/data_smart.py4
-rw-r--r--bitbake/lib/bb/fetch/__init__.py4
-rw-r--r--bitbake/lib/bb/manifest.py2
-rw-r--r--bitbake/lib/bb/providers.py14
-rw-r--r--bitbake/lib/bb/shell.py18
6 files changed, 21 insertions, 30 deletions
diff --git a/bitbake/lib/bb/cooker.py b/bitbake/lib/bb/cooker.py
index 5f9becccac..938bdeaaea 100644
--- a/bitbake/lib/bb/cooker.py
+++ b/bitbake/lib/bb/cooker.py
@@ -219,18 +219,15 @@ class BBCooker:
latest_versions = {}
# Sort by priority
- for pn in pkg_pn.keys():
+ for pn in pkg_pn:
(last_ver,last_file,pref_ver,pref_file) = bb.providers.findBestProvider(pn, self.configuration.data, self.status)
preferred_versions[pn] = (pref_ver, pref_file)
latest_versions[pn] = (last_ver, last_file)
- pkg_list = pkg_pn.keys()
- pkg_list.sort()
-
bb.msg.plain("%-35s %25s %25s" % ("Package Name", "Latest Version", "Preferred Version"))
bb.msg.plain("%-35s %25s %25s\n" % ("============", "==============", "================="))
- for p in pkg_list:
+ for p in sorted(pkg_pn):
pref = preferred_versions[p]
latest = latest_versions[p]
@@ -487,7 +484,7 @@ class BBCooker:
self.status.preferred[providee] = provider
# Calculate priorities for each file
- for p in self.status.pkg_fn.keys():
+ for p in self.status.pkg_fn:
self.status.bbfile_priority[p] = calc_bbfile_priority(p)
def buildWorldTargetList(self):
diff --git a/bitbake/lib/bb/data_smart.py b/bitbake/lib/bb/data_smart.py
index 988d5c3578..dac7fb705e 100644
--- a/bitbake/lib/bb/data_smart.py
+++ b/bitbake/lib/bb/data_smart.py
@@ -219,7 +219,7 @@ class DataSmart:
if not var in self.dict:
self._makeShadowCopy(var)
- for i in flags.keys():
+ for i in flags:
if i == "content":
continue
self.dict[var][i] = flags[i]
@@ -229,7 +229,7 @@ class DataSmart:
flags = {}
if local_var:
- for i in local_var.keys():
+ for i in local_var:
if i == "content":
continue
flags[i] = local_var[i]
diff --git a/bitbake/lib/bb/fetch/__init__.py b/bitbake/lib/bb/fetch/__init__.py
index 435c02683c..d181eea71b 100644
--- a/bitbake/lib/bb/fetch/__init__.py
+++ b/bitbake/lib/bb/fetch/__init__.py
@@ -139,7 +139,7 @@ def encodeurl(decoded):
url += "%s" % host
url += "%s" % path
if p:
- for parm in p.keys():
+ for parm in p:
url += ";%s=%s" % (parm, p[parm])
return url
@@ -169,7 +169,7 @@ def uri_replace(uri, uri_find, uri_replace, d):
# bb.msg.note(1, bb.msg.domain.Fetcher, "uri_replace: no match")
return uri
# else:
-# for j in i.keys():
+# for j in i:
# FIXME: apply replacements against options
return bb.encodeurl(result_decoded)
diff --git a/bitbake/lib/bb/manifest.py b/bitbake/lib/bb/manifest.py
index 4e4b7d98ec..418367759f 100644
--- a/bitbake/lib/bb/manifest.py
+++ b/bitbake/lib/bb/manifest.py
@@ -96,7 +96,7 @@ def mangle (func, line, d):
varmap["${datadir}"] = "${STAGING_DATADIR}"
matched = 0
- for key in varmap.keys():
+ for key in varmap:
if dest.startswith(key):
dest = varmap[key] + "/" + dest[len(key):]
matched = 1
diff --git a/bitbake/lib/bb/providers.py b/bitbake/lib/bb/providers.py
index 8617251ca3..c9fe7c7d7f 100644
--- a/bitbake/lib/bb/providers.py
+++ b/bitbake/lib/bb/providers.py
@@ -50,14 +50,10 @@ def sortPriorities(pn, dataCache, pkg_pn = None):
if preference not in priorities[priority]:
priorities[priority][preference] = []
priorities[priority][preference].append(f)
- pri_list = priorities.keys()
- pri_list.sort(lambda a, b: a - b)
tmp_pn = []
- for pri in pri_list:
- pref_list = priorities[pri].keys()
- pref_list.sort(lambda a, b: b - a)
+ for pri in sorted(priorities, lambda a, b: a - b):
tmp_pref = []
- for pref in pref_list:
+ for pref in sorted(priorities[pri], lambda a, b: b - a):
tmp_pref.extend(priorities[pri][pref])
tmp_pn = [tmp_pref] + tmp_pn
@@ -193,17 +189,17 @@ def _filterProviders(providers, item, cfgData, dataCache):
pkg_pn[pn] = []
pkg_pn[pn].append(p)
- bb.msg.debug(1, bb.msg.domain.Provider, "providers for %s are: %s" % (item, pkg_pn.keys()))
+ bb.msg.debug(1, bb.msg.domain.Provider, "providers for %s are: %s" % (item, pkg_pn()))
# First add PREFERRED_VERSIONS
- for pn in pkg_pn.keys():
+ for pn in pkg_pn():
sortpkg_pn[pn] = sortPriorities(pn, dataCache, pkg_pn)
preferred_versions[pn] = findPreferredProvider(pn, cfgData, dataCache, sortpkg_pn[pn], item)
if preferred_versions[pn][1]:
eligible.append(preferred_versions[pn][1])
# Now add latest verisons
- for pn in sortpkg_pn.keys():
+ for pn in sortpkg_pn():
if pn in preferred_versions and preferred_versions[pn][1]:
continue
preferred_versions[pn] = findLatestProvider(pn, cfgData, dataCache, sortpkg_pn[pn][0])
diff --git a/bitbake/lib/bb/shell.py b/bitbake/lib/bb/shell.py
index 66e51719a4..7abea0f126 100644
--- a/bitbake/lib/bb/shell.py
+++ b/bitbake/lib/bb/shell.py
@@ -147,7 +147,7 @@ class BitBakeShellCommands:
global last_exception
globexpr = params[0]
self._checkParsed()
- names = globfilter( cooker.status.pkg_pn.keys(), globexpr )
+ names = globfilter( cooker.status.pkg_pn, globexpr )
if len( names ) == 0: names = [ globexpr ]
print "SHELL: Building %s" % ' '.join( names )
@@ -294,9 +294,7 @@ class BitBakeShellCommands:
def help( self, params ):
"""Show a comprehensive list of commands and their purpose"""
print "="*30, "Available Commands", "="*30
- allcmds = cmds.keys()
- allcmds.sort()
- for cmd in allcmds:
+ for cmd in sorted(cmds):
function,numparams,usage,helptext = cmds[cmd]
print "| %s | %s" % (usage.ljust(30), helptext)
print "="*78
@@ -322,10 +320,10 @@ class BitBakeShellCommands:
what, globexpr = params
if what == "files":
self._checkParsed()
- for key in globfilter( cooker.status.pkg_fn.keys(), globexpr ): print key
+ for key in globfilter( cooker.status.pkg_fn, globexpr ): print key
elif what == "providers":
self._checkParsed()
- for key in globfilter( cooker.status.pkg_pn.keys(), globexpr ): print key
+ for key in globfilter( cooker.status.pkg_pn, globexpr ): print key
else:
print "Usage: match %s" % self.print_.usage
match.usage = "<files|providers> <glob>"
@@ -473,10 +471,10 @@ SRC_URI = ""
what = params[0]
if what == "files":
self._checkParsed()
- for key in cooker.status.pkg_fn.keys(): print key
+ for key in cooker.status.pkg_fn: print key
elif what == "providers":
self._checkParsed()
- for key in cooker.status.providers.keys(): print key
+ for key in cooker.status.providers: print key
else:
print "Usage: print %s" % self.print_.usage
print_.usage = "<files|providers>"
@@ -571,7 +569,7 @@ def completeFilePath( bbfile ):
"""Get the complete bbfile path"""
if not cooker.status: return bbfile
if not cooker.status.pkg_fn: return bbfile
- for key in cooker.status.pkg_fn.keys():
+ for key in cooker.status.pkg_fn:
if key.endswith( bbfile ):
return key
return bbfile
@@ -615,7 +613,7 @@ def completer( text, state ):
allmatches = cooker.configuration.data.keys()
elif u == "<bbfile>":
if cooker.status.pkg_fn is None: allmatches = [ "(No Matches Available. Parsed yet?)" ]
- else: allmatches = [ x.split("/")[-1] for x in cooker.status.pkg_fn.keys() ]
+ else: allmatches = [ x.split("/")[-1] for x in cooker.status.pkg_fn ]
elif u == "<providee>":
if cooker.status.pkg_fn is None: allmatches = [ "(No Matches Available. Parsed yet?)" ]
else: allmatches = cooker.status.providers.iterkeys()