public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-commits] portage r12767 - main/trunk/pym/portage
@ 2009-03-06  4:29 Zac Medico (zmedico)
  0 siblings, 0 replies; only message in thread
From: Zac Medico (zmedico) @ 2009-03-06  4:29 UTC (permalink / raw
  To: gentoo-commits

Author: zmedico
Date: 2009-03-06 04:29:56 +0000 (Fri, 06 Mar 2009)
New Revision: 12767

Modified:
   main/trunk/pym/portage/__init__.py
Log:
Make digraph store a single priority list for each edge instead of two
identical lists.


Modified: main/trunk/pym/portage/__init__.py
===================================================================
--- main/trunk/pym/portage/__init__.py	2009-03-06 03:56:37 UTC (rev 12766)
+++ main/trunk/pym/portage/__init__.py	2009-03-06 04:29:56 UTC (rev 12767)
@@ -368,14 +368,14 @@
 			self.nodes[parent] = ({}, {}, parent)
 			self.order.append(parent)
 
-		priorities = self.nodes[node][1].setdefault(parent, [])
+		priorities = self.nodes[node][1].get(parent)
+		if priorities is None:
+			priorities = []
+			self.nodes[node][1][parent] = priorities
+			self.nodes[parent][0][node] = priorities
 		priorities.append(priority)
 		priorities.sort()
 
-		priorities = self.nodes[parent][0].setdefault(node, [])
-		priorities.append(priority)
-		priorities.sort()
-
 	def remove(self, node):
 		"""Removes the specified node from the digraph, also removing
 		and ties to other nodes in the digraph. Raises KeyError if the
@@ -560,13 +560,22 @@
 	def clone(self):
 		clone = digraph()
 		clone.nodes = {}
+		memo = {}
 		for children, parents, node in self.nodes.itervalues():
 			children_clone = {}
 			for child, priorities in children.iteritems():
-				children_clone[child] = priorities[:]
+				priorities_clone = memo.get(id(priorities))
+				if priorities_clone is None:
+					priorities_clone = priorities[:]
+					memo[id(priorities)] = priorities_clone
+				children_clone[child] = priorities_clone
 			parents_clone = {}
 			for parent, priorities in parents.iteritems():
-				parents_clone[parent] = priorities[:]
+				priorities_clone = memo.get(id(priorities))
+				if priorities_clone is None:
+					priorities_clone = priorities[:]
+					memo[id(priorities)] = priorities_clone
+				parents_clone[parent] = priorities_clone
 			clone.nodes[node] = (children_clone, parents_clone, node)
 		clone.order = self.order[:]
 		return clone




^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2009-03-06  4:30 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-03-06  4:29 [gentoo-commits] portage r12767 - main/trunk/pym/portage Zac Medico (zmedico)

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox