diff options
author | Chris Larson <clarson@mvista.com> | 2009-06-11 13:10:04 -0700 |
---|---|---|
committer | Richard Purdie <rpurdie@linux.intel.com> | 2010-03-22 15:01:59 +0000 |
commit | ada2a8494a88b59de25c0a44fce30190f560eff4 (patch) | |
tree | 67f60f7ae769b74815757e45c12e4d694270a802 /bitbake/lib/bb/shell.py | |
parent | 9d9b47bae4b880ec57eda0e647b1d24fbc3ba3cf (diff) | |
download | openembedded-core-ada2a8494a88b59de25c0a44fce30190f560eff4.tar.gz openembedded-core-ada2a8494a88b59de25c0a44fce30190f560eff4.tar.bz2 openembedded-core-ada2a8494a88b59de25c0a44fce30190f560eff4.zip |
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/shell.py')
-rw-r--r-- | bitbake/lib/bb/shell.py | 18 |
1 files changed, 8 insertions, 10 deletions
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() |