Remove lots of unnecessary list generation via dict.keys(). (trunk r6911)
authorZac Medico <zmedico@gentoo.org>
Fri, 22 Jun 2007 01:53:50 +0000 (01:53 -0000)
committerZac Medico <zmedico@gentoo.org>
Fri, 22 Jun 2007 01:53:50 +0000 (01:53 -0000)
svn path=/main/branches/2.1.2/; revision=6930

bin/emerge
bin/fix-db.py
bin/md5check.py
bin/repoman
pym/portage.py

index 4e3197bf0f334461d39e5740559ed6ece076e4f8..c2053c0a9e0ce0072251a61ed0522bcbb10c13a0 100755 (executable)
@@ -439,7 +439,7 @@ class search:
                                if self.searchre.search(full_desc):
                                        self.matches["desc"].append([full_package,masked])
                self.mlen=0
-               for mtype in self.matches.keys():
+               for mtype in self.matches:
                        self.matches[mtype].sort()
                        self.mlen += len(self.matches[mtype])
 
@@ -448,7 +448,7 @@ class search:
                print "\b\b  \n[ Results for search key : "+white(self.searchkey)+" ]"
                print "[ Applications found : "+white(str(self.mlen))+" ]"
                print " "
-               for mtype in self.matches.keys():
+               for mtype in self.matches:
                        for match,masked in self.matches[mtype]:
                                if mtype=="pkg":
                                        catpack=match
@@ -2182,7 +2182,7 @@ class depgraph:
                        mylist = getlist(self.settings, "system")
                        worlddict=genericdict(worldlist)
 
-                       for x in worlddict.keys():
+                       for x in worlddict:
                                if not portage.isvalidatom(x):
                                        world_problems = True
                                        continue
@@ -2665,7 +2665,7 @@ class depgraph:
                                                if myfilesdict is None:
                                                        myfilesdict="[empty/missing/bad digest]"
                                                else:
-                                                       for myfetchfile in myfilesdict.keys():
+                                                       for myfetchfile in myfilesdict:
                                                                if myfetchfile not in myfetchlist:
                                                                        mysize+=myfilesdict[myfetchfile]
                                                                        myfetchlist.append(myfetchfile)
@@ -3554,7 +3554,7 @@ def unmerge(settings, myopts, vartree, unmerge_action, unmerge_files,
                                        if not slotmap.has_key(myslot):
                                                slotmap[myslot]={}
                                        slotmap[myslot][localtree.dbapi.cpv_counter(mypkg)]=mypkg
-                               for myslot in slotmap.keys():
+                               for myslot in slotmap:
                                        counterkeys=slotmap[myslot].keys()
                                        counterkeys.sort()
                                        if not counterkeys:
@@ -3581,7 +3581,7 @@ def unmerge(settings, myopts, vartree, unmerge_action, unmerge_files,
        finally:
                if vdb_lock:
                        portage_locks.unlockdir(vdb_lock)
-       for x in pkgmap.keys():
+       for x in pkgmap:
                for y in localtree.dep_match(x):
                        if y not in pkgmap[x]["omitted"] and \
                           y not in pkgmap[x]["selected"] and \
@@ -3637,7 +3637,7 @@ def unmerge(settings, myopts, vartree, unmerge_action, unmerge_files,
        if not autoclean:
                countdown(int(settings["CLEAN_DELAY"]), ">>> Unmerging")
 
-       for x in pkgmap.keys():
+       for x in pkgmap:
                for y in pkgmap[x]["selected"]:
                        print ">>> Unmerging "+y+"..."
                        emergelog(xterm_titles, "=== Unmerging... ("+y+")")
index 8292bc9608e2c28288378ee9ae43b100939ff794..301ec80025e564edbb8bb076440bc66f3a1d4618 100755 (executable)
@@ -136,7 +136,7 @@ for cat in os.listdir(vardbdir):
 
 actions = {}
 writemsg("\n\n")
-for catpkg in bad.keys():
+for catpkg in bad:
        bad[catpkg].sort()
 
        mystr = ""
@@ -155,7 +155,7 @@ for catpkg in bad.keys():
 
 if (len(sys.argv) > 1) and (sys.argv[1] == "--fix"):
        writemsg("These are only directions, at the moment.")
-       for catpkg in actions.keys():
+       for catpkg in actions:
                action = actions[catpkg]
                writemsg("We will now '%s' '%s'..." % (action, catpkg))
                #if action == 
index 8f1159e75f206a15a4ff768a2e3b873e8f59e441..5d960a4024150262f13e27676881285c4af3ada8 100755 (executable)
@@ -68,10 +68,10 @@ for mycpv in hugelist:
                else:
                        continue
                
-               if mybn not in md5sums.keys():
+               if mybn not in md5sums:
                        portage_util.writemsg("Missing md5sum: %s in %s\n" % (mybn, mycpv))
                else:
-                       if mybn in md5_list.keys():
+                       if mybn in md5_list:
                                if (md5_list[mybn]["MD5"]  != md5sums[mybn]["MD5"]) or \
                                   (md5_list[mybn]["size"] != md5sums[mybn]["size"]):
 
@@ -89,12 +89,12 @@ for mycpv in hugelist:
                        del md5sums[mybn]
                
        #portage.writemsg(str(bn_list)+"\n")
-       for x in md5sums.keys():
+       for x in md5sums:
                if x not in bn_list:
                        portage.writemsg("Extra md5sum: %s in %s\n" % (x, mycpv))
 
 
 print col_list
 print
-print str(len(md5_list.keys()))+" unique distfile md5s."
+print str(len(md5_list))+" unique distfile md5s."
 print str(len(bn_list))+" unique distfile names."
index f5ef34dca5cc39f6e905667a6e257c1af582ec81..a93965ff3ba3b55fa8bce3f272c318d11dc9682c 100755 (executable)
@@ -349,9 +349,9 @@ myoptions=[]
 if len(sys.argv)>1:
        x=1
        while x < len(sys.argv):
-               if sys.argv[x] in shortmodes.keys():
+               if sys.argv[x] in shortmodes:
                        sys.argv[x]=shortmodes[sys.argv[x]]
-               elif sys.argv[x] in repoman_shortoptions.keys():
+               elif sys.argv[x] in repoman_shortoptions:
                        sys.argv[x] = repoman_shortoptions[sys.argv[x]]
                if sys.argv[x] in modes:
                        if mymode is None:
@@ -1477,7 +1477,7 @@ def grouplist(mylist,seperator="/"):
                xs=x.split(seperator)
                if xs[0]==".":
                        xs=xs[1:]
-               if xs[0] not in mygroups.keys():
+               if xs[0] not in mygroups:
                        mygroups[xs[0]]=[seperator.join(xs[1:])]
                else:
                        mygroups[xs[0]]+=[seperator.join(xs[1:])]
index ff016c0213c2e4a0874175dd1dfcde35d6311534..1bd0330115161bf0cd5a0524c38dbec7fd557470 100644 (file)
@@ -1657,9 +1657,8 @@ class config:
 
        def load_infodir(self,infodir):
                self.modifying()
-               if self.configdict.has_key("pkg"):
-                       for x in self.configdict["pkg"].keys():
-                               del self.configdict["pkg"][x]
+               if "pkg" in self.configdict:
+                       self.configdict["pkg"].clear()
                else:
                        writemsg("No pkg setup for settings instance?\n",
                                noiselevel=-1)
@@ -2057,8 +2056,7 @@ class config:
                        return self.virts_p
                virts = self.getvirtuals(myroot)
                if virts:
-                       myvkeys = virts.keys()
-                       for x in myvkeys:
+                       for x in virts:
                                vkeysplit = x.split("/")
                                if not self.virts_p.has_key(vkeysplit[1]):
                                        self.virts_p[vkeysplit[1]] = virts[x]
@@ -2179,7 +2177,16 @@ class config:
                        return x
 
        def keys(self):
-               return unique_array(flatten([x.keys() for x in self.lookuplist]))
+               return list(self)
+
+       def __iter__(self):
+               keys = set()
+               for d in self.lookuplist:
+                       for k in d:
+                               if k in keys:
+                                       continue
+                               keys.add(k)
+                               yield k
 
        def __setitem__(self,mykey,myvalue):
                "set a value; will be thrown away at reset() time"
@@ -2192,7 +2199,7 @@ class config:
        def environ(self):
                "return our locally-maintained environment"
                mydict={}
-               for x in self.keys():
+               for x in self:
                        myvalue = self[x]
                        if not isinstance(myvalue, basestring):
                                writemsg("!!! Non-string value in config: %s=%s\n" % \
@@ -2529,7 +2536,7 @@ def fetch(myuris, mysettings, listonly=0, fetchonly=0, locks_in_subdir=".locks",
                                        noiselevel=-1)
                                return 0
                        del distlocks_subdir
-       for myfile in filedict.keys():
+       for myfile in filedict:
                """
                fetched  status
                0        nonexistent
@@ -2760,7 +2767,7 @@ def fetch(myuris, mysettings, listonly=0, fetchonly=0, locks_in_subdir=".locks",
                                                                else:
                                                                        eout = output.EOutput()
                                                                        eout.quiet = mysettings.get("PORTAGE_QUIET", None) == "1"
-                                                                       for x_key in mydigests[myfile].keys():
+                                                                       for x_key in mydigests[myfile]:
                                                                                eout.ebegin("%s %s ;-)" % (myfile, x_key))
                                                                                eout.eend(0)
                                                                        fetched=2
@@ -3016,7 +3023,7 @@ def digestcheck(myfiles, mysettings, strict=0, justmanifest=0):
 def spawnebuild(mydo,actionmap,mysettings,debug,alwaysdep=0,logfile=None):
        if alwaysdep or "noauto" not in mysettings.features:
                # process dependency first
-               if "dep" in actionmap[mydo].keys():
+               if "dep" in actionmap[mydo]:
                        retval=spawnebuild(actionmap[mydo]["dep"],actionmap,mysettings,debug,alwaysdep=alwaysdep,logfile=logfile)
                        if retval:
                                return retval
@@ -3822,11 +3829,11 @@ def doebuild(myebuild, mydo, myroot, mysettings, debug=0, listonly=0,
 
                # merge the deps in so we have again a 'full' actionmap
                # be glad when this can die.
-               for x in actionmap.keys():
+               for x in actionmap:
                        if len(actionmap_deps.get(x, [])):
                                actionmap[x]["dep"] = ' '.join(actionmap_deps[x])
 
-               if mydo in actionmap.keys():
+               if mydo in actionmap:
                        if mydo=="package":
                                portage_util.ensure_dirs(
                                        os.path.join(mysettings["PKGDIR"], mysettings["CATEGORY"]))
@@ -8064,9 +8071,11 @@ class FetchlistDict(UserDict.DictMixin):
                """Returns the complete fetch list for a given package."""
                return self.portdb.getfetchlist(pkg_key, mysettings=self.settings,
                        all=True, mytree=self.mytree)[1]
+       def __contains__(self):
+               return pkg_key in self.keys()
        def has_key(self, pkg_key):
                """Returns true if the given package exists within pkgdir."""
-               return pkg_key in self.keys()
+               return pkg_key in self
        def keys(self):
                """Returns keys for all packages within pkgdir"""
                return self.portdb.cp_list(self.cp, mytree=self.mytree)