Make digraph store a single priority list for each edge instead of two
authorZac Medico <zmedico@gentoo.org>
Wed, 11 Mar 2009 06:44:38 +0000 (06:44 -0000)
committerZac Medico <zmedico@gentoo.org>
Wed, 11 Mar 2009 06:44:38 +0000 (06:44 -0000)
identical lists. (trunk r12767)

svn path=/main/branches/2.1.6/; revision=13011

pym/portage/__init__.py

index dbc19f8edab94fe9a42e8ff24243c60db793aa20..82fc57431df581c32ca00a20467860b90d4a9162 100644 (file)
@@ -368,11 +368,11 @@ class digraph(object):
                        self.nodes[parent] = ({}, {}, parent)
                        self.order.append(parent)
 
-               priorities = self.nodes[node][1].setdefault(parent, [])
-               priorities.append(priority)
-               priorities.sort()
-
-               priorities = self.nodes[parent][0].setdefault(node, [])
+               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()
 
@@ -560,13 +560,22 @@ class digraph(object):
        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