Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/branchmap.py @ 20264:d9e1c167943b
branchmap: use set for update code
We are doing membership test and substraction. new code is marginally faster.
author | Pierre-Yves David <pierre-yves.david@ens-lyon.org> |
---|---|
date | Mon, 06 Jan 2014 15:19:31 -0800 |
parents | ea4996754d91 |
children | 05cfcecb3aef |
comparison
equal
deleted
inserted
replaced
20263:ea4996754d91 | 20264:d9e1c167943b |
---|---|
236 # if older branchheads are reachable from new ones, they aren't | 236 # if older branchheads are reachable from new ones, they aren't |
237 # really branchheads. Note checking parents is insufficient: | 237 # really branchheads. Note checking parents is insufficient: |
238 # 1 (branch a) -> 2 (branch b) -> 3 (branch a) | 238 # 1 (branch a) -> 2 (branch b) -> 3 (branch a) |
239 for branch, newheadrevs in newbranches.iteritems(): | 239 for branch, newheadrevs in newbranches.iteritems(): |
240 bheads = self.setdefault(branch, []) | 240 bheads = self.setdefault(branch, []) |
241 bheadrevs = [cl.rev(node) for node in bheads] | 241 bheadset = set(cl.rev(node) for node in bheads) |
242 | 242 |
243 # This have been tested True on all internal usage of this function. | 243 # This have been tested True on all internal usage of this function. |
244 # run it again in case of doubt | 244 # run it again in case of doubt |
245 # assert not (set(bheadrevs) & set(newheadrevs)) | 245 # assert not (set(bheadrevs) & set(newheadrevs)) |
246 newheadrevs.sort() | 246 newheadrevs.sort() |
247 bheadrevs.extend(newheadrevs) | 247 bheadset.update(newheadrevs) |
248 bheadrevs.sort() | |
249 | 248 |
250 # This loop prunes out two kinds of heads - heads that are | 249 # This loop prunes out two kinds of heads - heads that are |
251 # superseded by a head in newheadrevs, and newheadrevs that are not | 250 # superseded by a head in newheadrevs, and newheadrevs that are not |
252 # heads because an existing head is their descendant. | 251 # heads because an existing head is their descendant. |
253 while newheadrevs: | 252 while newheadrevs: |
254 latest = newheadrevs.pop() | 253 latest = newheadrevs.pop() |
255 if latest not in bheadrevs: | 254 if latest not in bheadset: |
256 continue | 255 continue |
257 ancestors = set(cl.ancestors([latest], bheadrevs[0])) | 256 ancestors = set(cl.ancestors([latest], min(bheadset))) |
258 if ancestors: | 257 bheadset -= ancestors |
259 bheadrevs = [b for b in bheadrevs if b not in ancestors] | 258 bheadrevs = sorted(bheadset) |
260 self[branch] = [cl.node(rev) for rev in bheadrevs] | 259 self[branch] = [cl.node(rev) for rev in bheadrevs] |
261 tiprev = bheadrevs[-1] | 260 tiprev = bheadrevs[-1] |
262 if tiprev > self.tiprev: | 261 if tiprev > self.tiprev: |
263 self.tipnode = cl.node(tiprev) | 262 self.tipnode = cl.node(tiprev) |
264 self.tiprev = tiprev | 263 self.tiprev = tiprev |