summaryrefslogtreecommitdiffstats
path: root/bitbake/lib/bb/providers.py
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/lib/bb/providers.py
parent9d9b47bae4b880ec57eda0e647b1d24fbc3ba3cf (diff)
downloadpoky-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/lib/bb/providers.py')
-rw-r--r--bitbake/lib/bb/providers.py14
1 files changed, 5 insertions, 9 deletions
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):
50 if preference not in priorities[priority]: 50 if preference not in priorities[priority]:
51 priorities[priority][preference] = [] 51 priorities[priority][preference] = []
52 priorities[priority][preference].append(f) 52 priorities[priority][preference].append(f)
53 pri_list = priorities.keys()
54 pri_list.sort(lambda a, b: a - b)
55 tmp_pn = [] 53 tmp_pn = []
56 for pri in pri_list: 54 for pri in sorted(priorities, lambda a, b: a - b):
57 pref_list = priorities[pri].keys()
58 pref_list.sort(lambda a, b: b - a)
59 tmp_pref = [] 55 tmp_pref = []
60 for pref in pref_list: 56 for pref in sorted(priorities[pri], lambda a, b: b - a):
61 tmp_pref.extend(priorities[pri][pref]) 57 tmp_pref.extend(priorities[pri][pref])
62 tmp_pn = [tmp_pref] + tmp_pn 58 tmp_pn = [tmp_pref] + tmp_pn
63 59
@@ -193,17 +189,17 @@ def _filterProviders(providers, item, cfgData, dataCache):
193 pkg_pn[pn] = [] 189 pkg_pn[pn] = []
194 pkg_pn[pn].append(p) 190 pkg_pn[pn].append(p)
195 191
196 bb.msg.debug(1, bb.msg.domain.Provider, "providers for %s are: %s" % (item, pkg_pn.keys())) 192 bb.msg.debug(1, bb.msg.domain.Provider, "providers for %s are: %s" % (item, pkg_pn()))
197 193
198 # First add PREFERRED_VERSIONS 194 # First add PREFERRED_VERSIONS
199 for pn in pkg_pn.keys(): 195 for pn in pkg_pn():
200 sortpkg_pn[pn] = sortPriorities(pn, dataCache, pkg_pn) 196 sortpkg_pn[pn] = sortPriorities(pn, dataCache, pkg_pn)
201 preferred_versions[pn] = findPreferredProvider(pn, cfgData, dataCache, sortpkg_pn[pn], item) 197 preferred_versions[pn] = findPreferredProvider(pn, cfgData, dataCache, sortpkg_pn[pn], item)
202 if preferred_versions[pn][1]: 198 if preferred_versions[pn][1]:
203 eligible.append(preferred_versions[pn][1]) 199 eligible.append(preferred_versions[pn][1])
204 200
205 # Now add latest verisons 201 # Now add latest verisons
206 for pn in sortpkg_pn.keys(): 202 for pn in sortpkg_pn():
207 if pn in preferred_versions and preferred_versions[pn][1]: 203 if pn in preferred_versions and preferred_versions[pn][1]:
208 continue 204 continue
209 preferred_versions[pn] = findLatestProvider(pn, cfgData, dataCache, sortpkg_pn[pn][0]) 205 preferred_versions[pn] = findLatestProvider(pn, cfgData, dataCache, sortpkg_pn[pn][0])