aboutsummaryrefslogtreecommitdiffstats
path: root/lib/bb/providers.py
diff options
context:
space:
mode:
authorChris Larson <clarson@mvista.com>2009-06-11 13:10:04 -0700
committerChris Larson <chris_larson@mentor.com>2010-02-25 11:16:15 -0700
commit5b6ccb16c6e71e23dac6920cd2df994d67c2587b (patch)
tree6b938155a18ca31a46860b659dd374cffa38199b /lib/bb/providers.py
parent446cc0cebd4daff7f849717f4cb89ac1b4c6b755 (diff)
downloadbitbake-5b6ccb16c6e71e23dac6920cd2df994d67c2587b.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. Signed-off-by: Chris Larson <clarson@mvista.com>
Diffstat (limited to 'lib/bb/providers.py')
-rw-r--r--lib/bb/providers.py12
1 files changed, 4 insertions, 8 deletions
diff --git a/lib/bb/providers.py b/lib/bb/providers.py
index f85fa6f2c..058996ba5 100644
--- a/lib/bb/providers.py
+++ b/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
@@ -196,14 +192,14 @@ def _filterProviders(providers, item, cfgData, dataCache):
bb.msg.debug(1, bb.msg.domain.Provider, "providers for %s are: %s" % (item, pkg_pn.keys()))
# 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 versions
- 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])