From: Zac Medico Date: Fri, 26 Nov 2010 21:09:09 +0000 (-0800) Subject: portdbapi: eliminate redundant treemap lookups X-Git-Tag: v2.2.0_alpha6~10 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=07057dd0c4e0a7ed1f719ec267a64094a241f5e0;p=portage.git portdbapi: eliminate redundant treemap lookups --- diff --git a/pym/portage/dbapi/porttree.py b/pym/portage/dbapi/porttree.py index b3a219517..2f6b9dd16 100644 --- a/pym/portage/dbapi/porttree.py +++ b/pym/portage/dbapi/porttree.py @@ -248,9 +248,7 @@ class portdbapi(dbapi): it must return a path to the repository TreeMap = { id:path } """ - if repository_id in self.treemap: - return self.treemap[repository_id] - return None + return self.treemap.get(repository_id) def getRepositoryName(self, canonical_repo_path): """ @@ -300,12 +298,11 @@ class portdbapi(dbapi): if not mycpv: return (None, 0) - if myrepo: - if myrepo in self.treemap: - mytree = self.treemap[myrepo] - else: + if myrepo is not None: + mytree = self.treemap.get(myrepo) + if mytree is None: return (None, 0) - + mysplit = mycpv.split("/") psplit = pkgsplit(mysplit[1]) if psplit is None or len(mysplit) != 2: @@ -434,12 +431,11 @@ class portdbapi(dbapi): 'input: "sys-apps/foo-1.0",["SLOT","DEPEND","HOMEPAGE"]' 'return: ["0",">=sys-libs/bar-1.0","http://www.foo.com"] or raise KeyError if error' cache_me = False - if myrepo: - if myrepo in self.treemap: - mytree = self.treemap[myrepo] - else: + if myrepo is not None: + mytree = self.treemap.get(myrepo) + if mytree is None: raise KeyError(myrepo) - + if not mytree: cache_me = True if not mytree and not self._known_keys.intersection( @@ -626,10 +622,9 @@ class portdbapi(dbapi): elif useflags is None: if mysettings: useflags = mysettings["USE"].split() - if myrepo: - if myrepo in self.treemap: - mytree = self.treemap[myrepo] - else: + if myrepo is not None: + mytree = self.treemap.get(myrepo) + if mytree is None: return False else: mytree = None