From ada2a8494a88b59de25c0a44fce30190f560eff4 Mon Sep 17 00:00:00 2001 From: Chris Larson 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 Signed-off-by: Richard Purdie --- bitbake/lib/bb/shell.py | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) (limited to 'bitbake/lib/bb/shell.py') 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 = " " @@ -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 = "" @@ -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 == "": 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 == "": if cooker.status.pkg_fn is None: allmatches = [ "(No Matches Available. Parsed yet?)" ] else: allmatches = cooker.status.providers.iterkeys() -- cgit v1.2.3