From: Zac Medico Date: Sat, 12 Jul 2008 01:58:23 +0000 (-0000) Subject: * Add a digraph.get() method, analogous to dict.get(), used to simplify X-Git-Tag: v2.2_rc2~124 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=f9dc49ffd4486777e96b2e045c0b4523c479fef4;p=portage.git * Add a digraph.get() method, analogous to dict.get(), used to simplify Scheduler._pkg(). * Define digraph.__contains__ for containment tests via the "in" operator. svn path=/main/trunk/; revision=11021 --- diff --git a/pym/_emerge/__init__.py b/pym/_emerge/__init__.py index 5dbb44795..38f485aae 100644 --- a/pym/_emerge/__init__.py +++ b/pym/_emerge/__init__.py @@ -8732,12 +8732,9 @@ class Scheduler(PollLoop): settings.setcpv(pkg) pkg.metadata["USE"] = settings["PORTAGE_USE"] - if self._digraph and \ - self._digraph.contains(pkg): - for existing_instance in self._digraph.order: - if existing_instance == pkg: - pkg = existing_instance - break + if self._digraph is not None: + # Reuse existing instance when available. + pkg = self._digraph.get(pkg, pkg) return pkg diff --git a/pym/portage/__init__.py b/pym/portage/__init__.py index 453096f67..535ea9ed7 100644 --- a/pym/portage/__init__.py +++ b/pym/portage/__init__.py @@ -437,6 +437,9 @@ class digraph(object): """Checks if the digraph contains mynode""" return node in self.nodes + def get(self, key, default=None): + return self.nodes.get(key, default) + def all_nodes(self): """Return a list of all nodes in the graph""" return self.order[:] @@ -506,6 +509,7 @@ class digraph(object): allnodes = all_nodes allzeros = leaf_nodes hasnode = contains + __contains__ = contains empty = is_empty copy = clone