mirror of
				https://git.launchpad.net/~ubuntu-release/britney/+git/britney2-ubuntu
				synced 2025-11-04 10:34:05 +00:00 
			
		
		
		
	britney.py: Minor optimisation to sort_actions
Avoid some cases of O(n^2) behaviour in sort_actions and reduce the size of n for the remaining O(n^2)-ish behaviour by filtering out removals early on. Signed-off-by: Niels Thykier <niels@thykier.net>
This commit is contained in:
		
							parent
							
								
									d5cfd5aebd
								
							
						
					
					
						commit
						bf3aa08023
					
				
							
								
								
									
										48
									
								
								britney.py
									
									
									
									
									
								
							
							
						
						
									
										48
									
								
								britney.py
									
									
									
									
									
								
							@ -2745,29 +2745,39 @@ class Britney(object):
 | 
				
			|||||||
        so the ones with most reverse dependencies are at the end of the loop.
 | 
					        so the ones with most reverse dependencies are at the end of the loop.
 | 
				
			||||||
        If an action depends on another one, it is put after it.
 | 
					        If an action depends on another one, it is put after it.
 | 
				
			||||||
        """
 | 
					        """
 | 
				
			||||||
        upgrade_me = [x.name for x in self.excuses if x.name in [y.uvname for y in self.upgrade_me]]
 | 
					        uvnames = frozenset(y.uvname for y in self.upgrade_me)
 | 
				
			||||||
        for e in self.excuses:
 | 
					        excuses = [e for e in self.excuses if e.name in uvnames]
 | 
				
			||||||
            if e.name not in upgrade_me: continue
 | 
					        removals = []
 | 
				
			||||||
            # try removes at the end of the loop
 | 
					        upgrade_me = []
 | 
				
			||||||
            elif e.name[0] == '-':
 | 
					
 | 
				
			||||||
                upgrade_me.remove(e.name)
 | 
					        for e in excuses:
 | 
				
			||||||
                upgrade_me.append(e.name)
 | 
					            # We order removals and regular migrations differently, so
 | 
				
			||||||
            # otherwise, put it in a good position checking its dependencies
 | 
					            # split them out early.
 | 
				
			||||||
 | 
					            if e.name[0] == '-':
 | 
				
			||||||
 | 
					                removals.append(e.name)
 | 
				
			||||||
            else:
 | 
					            else:
 | 
				
			||||||
                pos = []
 | 
					                upgrade_me.append(e.name)
 | 
				
			||||||
                udeps = [upgrade_me.index(x) for x in e.deps if x in upgrade_me and x != e.name]
 | 
					
 | 
				
			||||||
                if len(udeps) > 0:
 | 
					        for e in excuses:
 | 
				
			||||||
                    pos.append(max(udeps))
 | 
					            # put the item (regular migration) in a good position
 | 
				
			||||||
                sdeps = [upgrade_me.index(x) for x in e.sane_deps if x in upgrade_me and x != e.name]
 | 
					            # checking its dependencies
 | 
				
			||||||
                if len(sdeps) > 0:
 | 
					            pos = []
 | 
				
			||||||
                    pos.append(min(sdeps))
 | 
					            udeps = [upgrade_me.index(x) for x in e.deps if x in upgrade_me and x != e.name]
 | 
				
			||||||
                if len(pos) == 0: continue
 | 
					            if udeps:
 | 
				
			||||||
                upgrade_me.remove(e.name)
 | 
					                pos.append(max(udeps))
 | 
				
			||||||
                upgrade_me.insert(max(pos)+1, e.name)
 | 
					            sdeps = [upgrade_me.index(x) for x in e.sane_deps if x in upgrade_me and x != e.name]
 | 
				
			||||||
                self.dependencies[e.name] = e.deps
 | 
					            if sdeps:
 | 
				
			||||||
 | 
					                pos.append(min(sdeps))
 | 
				
			||||||
 | 
					            if not pos:
 | 
				
			||||||
 | 
					                continue
 | 
				
			||||||
 | 
					            upgrade_me.remove(e.name)
 | 
				
			||||||
 | 
					            upgrade_me.insert(max(pos)+1, e.name)
 | 
				
			||||||
 | 
					            self.dependencies[e.name] = e.deps
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        # replace the list of actions with the new one
 | 
					        # replace the list of actions with the new one
 | 
				
			||||||
        self.upgrade_me = [ make_migrationitem(x, self.sources) for x in upgrade_me ]
 | 
					        self.upgrade_me = [ make_migrationitem(x, self.sources) for x in upgrade_me ]
 | 
				
			||||||
 | 
					        self.upgrade_me.extend(make_migrationitem(x, self.sources) for x in removals)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def auto_hinter(self):
 | 
					    def auto_hinter(self):
 | 
				
			||||||
        """Auto-generate "easy" hints.
 | 
					        """Auto-generate "easy" hints.
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user