Submitter | Pierre-Yves David |
---|---|
Date | Jan. 7, 2014, 1:38 a.m. |
Message ID | <a5e84385dfcb52aff31b.1389058707@marginatus.fb.com> |
Download | mbox | patch |
Permalink | /patch/3265/ |
State | Accepted |
Commit | 4fd3d79b0a68d1c4b1fa06a14b1e329ab0ff9456 |
Headers | show |
Comments
On Mon, Jan 06, 2014 at 05:38:27PM -0800, pierre-yves.david@ens-lyon.org wrote: > # HG changeset patch > # User Pierre-Yves David <pierre-yves.david@ens-lyon.org> > # Date 1389050371 28800 > # Mon Jan 06 15:19:31 2014 -0800 > # Node ID a5e84385dfcb52aff31b4b3739f02d270e16dc6f > # Parent 5edde891b488a474c9b677d0cd52569f79c44c7e > branchmap: use set for update code Looks like all simple straightforward cleanups, queueing. > > We are doing membership test and substraction. new code is marginally faster. > > diff --git a/mercurial/branchmap.py b/mercurial/branchmap.py > --- a/mercurial/branchmap.py > +++ b/mercurial/branchmap.py > @@ -231,29 +231,28 @@ class branchcache(dict): > # if older branchheads are reachable from new ones, they aren't > # really branchheads. Note checking parents is insufficient: > # 1 (branch a) -> 2 (branch b) -> 3 (branch a) > for branch, newheadrevs in newbranches.iteritems(): > bheads = self.setdefault(branch, []) > - bheadrevs = [cl.rev(node) for node in bheads] > + bheadset = set(cl.rev(node) for node in bheads) > > # This have been tested True on all internal usage of this function. > # run it again in case of doubt > # assert not (set(bheadrevs) & set(newheadrevs)) > newheadrevs.sort() > - bheadrevs.extend(newheadrevs) > - bheadrevs.sort() > + bheadset.update(newheadrevs) > > # This loop prunes out two kinds of heads - heads that are > # superseded by a head in newheadrevs, and newheadrevs that are not > # heads because an existing head is their descendant. > while newheadrevs: > latest = newheadrevs.pop() > - if latest not in bheadrevs: > + if latest not in bheadset: > continue > - ancestors = set(cl.ancestors([latest], bheadrevs[0])) > - if ancestors: > - bheadrevs = [b for b in bheadrevs if b not in ancestors] > + ancestors = set(cl.ancestors([latest], min(bheadset))) > + bheadset -= ancestors > + bheadrevs = sorted(bheadset) > self[branch] = [cl.node(rev) for rev in bheadrevs] > tiprev = bheadrevs[-1] > if tiprev > self.tiprev: > self.tipnode = cl.node(tiprev) > self.tiprev = tiprev > _______________________________________________ > Mercurial-devel mailing list > Mercurial-devel@selenic.com > http://selenic.com/mailman/listinfo/mercurial-devel
Patch
diff --git a/mercurial/branchmap.py b/mercurial/branchmap.py --- a/mercurial/branchmap.py +++ b/mercurial/branchmap.py @@ -231,29 +231,28 @@ class branchcache(dict): # if older branchheads are reachable from new ones, they aren't # really branchheads. Note checking parents is insufficient: # 1 (branch a) -> 2 (branch b) -> 3 (branch a) for branch, newheadrevs in newbranches.iteritems(): bheads = self.setdefault(branch, []) - bheadrevs = [cl.rev(node) for node in bheads] + bheadset = set(cl.rev(node) for node in bheads) # This have been tested True on all internal usage of this function. # run it again in case of doubt # assert not (set(bheadrevs) & set(newheadrevs)) newheadrevs.sort() - bheadrevs.extend(newheadrevs) - bheadrevs.sort() + bheadset.update(newheadrevs) # This loop prunes out two kinds of heads - heads that are # superseded by a head in newheadrevs, and newheadrevs that are not # heads because an existing head is their descendant. while newheadrevs: latest = newheadrevs.pop() - if latest not in bheadrevs: + if latest not in bheadset: continue - ancestors = set(cl.ancestors([latest], bheadrevs[0])) - if ancestors: - bheadrevs = [b for b in bheadrevs if b not in ancestors] + ancestors = set(cl.ancestors([latest], min(bheadset))) + bheadset -= ancestors + bheadrevs = sorted(bheadset) self[branch] = [cl.node(rev) for rev in bheadrevs] tiprev = bheadrevs[-1] if tiprev > self.tiprev: self.tipnode = cl.node(tiprev) self.tiprev = tiprev