From 9568c3258f7349ec24a76d015d82c762ac7fb2d7 Mon Sep 17 00:00:00 2001 From: Zac Medico Date: Fri, 22 Jun 2007 02:09:41 +0000 Subject: [PATCH] Remove more unnecessary list generation. (trunk r6912) svn path=/main/branches/2.1.2/; revision=6931 --- pym/cache/template.py | 2 +- pym/cache/util.py | 7 ++----- pym/cvstree.py | 20 ++++++++++---------- pym/portage.py | 6 +++--- pym/portage_checksum.py | 6 +++--- pym/portage_util.py | 6 +++--- 6 files changed, 22 insertions(+), 25 deletions(-) diff --git a/pym/cache/template.py b/pym/cache/template.py index 4ffd9b9ef..d19bb8892 100644 --- a/pym/cache/template.py +++ b/pym/cache/template.py @@ -151,7 +151,7 @@ class database(object): if key not in self.__known_keys: raise InvalidRestriction(key, match, "Key isn't valid") - for cpv in self.keys(): + for cpv in self.iterkeys(): cont = True vals = self[cpv] for key, match in restricts.iteritems(): diff --git a/pym/cache/util.py b/pym/cache/util.py index ac09c132c..0e81a399f 100644 --- a/pym/cache/util.py +++ b/pym/cache/util.py @@ -18,8 +18,7 @@ def mirror_cache(valid_nodes_iterable, src_cache, trg_cache, eclass_cache=None, else: noise=verbose_instance - dead_nodes = {} - dead_nodes = dict.fromkeys(trg_cache.keys()) + dead_nodes = set(trg_cache.iterkeys()) count=0 if not trg_cache.autocommits: @@ -28,8 +27,7 @@ def mirror_cache(valid_nodes_iterable, src_cache, trg_cache, eclass_cache=None, for x in valid_nodes_iterable: # print "processing x=",x count+=1 - if dead_nodes.has_key(x): - del dead_nodes[x] + dead_nodes.discard(x) try: entry = src_cache[x] except KeyError, e: noise.missing_entry(x) @@ -105,7 +103,6 @@ def mirror_cache(valid_nodes_iterable, src_cache, trg_cache, eclass_cache=None, except cache_errors.CacheError, ce: noise.exception(ce) del ce - dead_nodes.clear() noise.finish() diff --git a/pym/cvstree.py b/pym/cvstree.py index 30f143cd8..ca94d3512 100644 --- a/pym/cvstree.py +++ b/pym/cvstree.py @@ -64,12 +64,12 @@ def findnew(entries,recursive=0,basedir=""): if basedir and basedir[-1]!="/": basedir=basedir+"/" mylist=[] - for myfile in entries["files"].keys(): + for myfile in entries["files"]: if "cvs" in entries["files"][myfile]["status"]: if "0" == entries["files"][myfile]["revision"]: mylist.append(basedir+myfile) if recursive: - for mydir in entries["dirs"].keys(): + for mydir in entries["dirs"]: mylist+=findnew(entries["dirs"][mydir],recursive,basedir+mydir) return mylist @@ -81,14 +81,14 @@ def findchanged(entries,recursive=0,basedir=""): if basedir and basedir[-1]!="/": basedir=basedir+"/" mylist=[] - for myfile in entries["files"].keys(): + for myfile in entries["files"]: if "cvs" in entries["files"][myfile]["status"]: if "current" not in entries["files"][myfile]["status"]: if "exists" in entries["files"][myfile]["status"]: if entries["files"][myfile]["revision"]!="0": mylist.append(basedir+myfile) if recursive: - for mydir in entries["dirs"].keys(): + for mydir in entries["dirs"]: mylist+=findchanged(entries["dirs"][mydir],recursive,basedir+mydir) return mylist @@ -100,13 +100,13 @@ def findmissing(entries,recursive=0,basedir=""): if basedir and basedir[-1]!="/": basedir=basedir+"/" mylist=[] - for myfile in entries["files"].keys(): + for myfile in entries["files"]: if "cvs" in entries["files"][myfile]["status"]: if "exists" not in entries["files"][myfile]["status"]: if "removed" not in entries["files"][myfile]["status"]: mylist.append(basedir+myfile) if recursive: - for mydir in entries["dirs"].keys(): + for mydir in entries["dirs"]: mylist+=findmissing(entries["dirs"][mydir],recursive,basedir+mydir) return mylist @@ -120,11 +120,11 @@ def findunadded(entries,recursive=0,basedir=""): mylist=[] #ignore what cvs ignores. - for myfile in entries["files"].keys(): + for myfile in entries["files"]: if "cvs" not in entries["files"][myfile]["status"]: mylist.append(basedir+myfile) if recursive: - for mydir in entries["dirs"].keys(): + for mydir in entries["dirs"]: mylist+=findunadded(entries["dirs"][mydir],recursive,basedir+mydir) return mylist @@ -135,11 +135,11 @@ def findremoved(entries,recursive=0,basedir=""): if basedir and basedir[-1]!="/": basedir=basedir+"/" mylist=[] - for myfile in entries["files"].keys(): + for myfile in entries["files"]: if "removed" in entries["files"][myfile]["status"]: mylist.append(basedir+myfile) if recursive: - for mydir in entries["dirs"].keys(): + for mydir in entries["dirs"]: mylist+=findremoved(entries["dirs"][mydir],recursive,basedir+mydir) return mylist diff --git a/pym/portage.py b/pym/portage.py index 1bd033011..44451269d 100644 --- a/pym/portage.py +++ b/pym/portage.py @@ -4999,7 +4999,7 @@ class fakedbapi(dbapi): def cp_all(self): returnme=[] - for x in self.cpdict.keys(): + for x in self.cpdict: returnme.extend(self.cpdict[x]) return returnme @@ -5878,7 +5878,7 @@ class portdbapi(dbapi): pass def close_caches(self): - for x in self.auxdb.keys(): + for x in self.auxdb: self.auxdb[x].sync() self.auxdb.clear() @@ -6053,7 +6053,7 @@ class portdbapi(dbapi): returnme = [] for x in mylist: if x == "INHERITED": - returnme.append(' '.join(mydata.get("_eclasses_", {}).keys())) + returnme.append(' '.join(mydata.get("_eclasses_", []))) else: returnme.append(mydata.get(x,"")) diff --git a/pym/portage_checksum.py b/pym/portage_checksum.py index 885535ee0..72290e350 100644 --- a/pym/portage_checksum.py +++ b/pym/portage_checksum.py @@ -79,7 +79,7 @@ def perform_md5(x, calc_prelink=0): def perform_all(x, calc_prelink=0): mydict = {} - for k in hashfunc_map.keys(): + for k in hashfunc_map: mydict[k] = perform_checksum(x, hashfunc_map[k], calc_prelink)[0] return mydict @@ -131,10 +131,10 @@ def verify_all(filename, mydict, calc_prelink=0, strict=0): got = " ".join(got) return False, ("Insufficient data for checksum verification", got, expected) - for x in mydict.keys(): + for x in mydict: if x == "size": continue - elif x in hashfunc_map.keys(): + elif x in hashfunc_map: myhash = perform_checksum(filename, x, calc_prelink=calc_prelink)[0] if mydict[x] != myhash: if strict: diff --git a/pym/portage_util.py b/pym/portage_util.py index ec359e206..d71add57e 100644 --- a/pym/portage_util.py +++ b/pym/portage_util.py @@ -76,7 +76,7 @@ def map_dictlist_vals(func,myDict): """Performs a function on each value of each key in a dictlist. Returns a new dictlist.""" new_dl = {} - for key in myDict.keys(): + for key in myDict: new_dl[key] = [] new_dl[key] = map(func,myDict[key]) return new_dl @@ -118,7 +118,7 @@ def stack_dictlist(original_dicts, incremental=0, incrementals=[], ignore_none=0 for mydict in original_dicts: if mydict is None: continue - for y in mydict.keys(): + for y in mydict: if not y in final_dict: final_dict[y] = [] @@ -280,7 +280,7 @@ def writedict(mydict,myfilename,writekey=True): for x in mydict.values(): myfile.write(x+"\n") else: - for x in mydict.keys(): + for x in mydict: myfile.write("%s %s\n" % (x, " ".join(mydict[x]))) myfile.close() except IOError: -- 2.26.2