From ada2a8494a88b59de25c0a44fce30190f560eff4 Mon Sep 17 00:00:00 2001
From: Chris Larson <clarson@mvista.com>
Date: Thu, 11 Jun 2009 13:10:04 -0700
Subject: 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>
---
 bitbake/lib/bb/providers.py | 14 +++++---------
 1 file changed, 5 insertions(+), 9 deletions(-)

(limited to 'bitbake/lib/bb/providers.py')

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])
-- 
cgit v1.2.3