Rev 4451: Avoid inner function calls to .append() in http://bazaar.launchpad.net/~jameinel/bzr/1.17-annotate-bug387952
John Arbash Meinel
john at arbash-meinel.com
Tue Jun 16 22:20:50 BST 2009
At http://bazaar.launchpad.net/~jameinel/bzr/1.17-annotate-bug387952
------------------------------------------------------------
revno: 4451
revision-id: john at arbash-meinel.com-20090616212044-gdm6tfrrg230j72v
parent: john at arbash-meinel.com-20090616211728-3z22kmrhmw62bf8k
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: 1.17-annotate-bug387952
timestamp: Tue 2009-06-16 16:20:44 -0500
message:
Avoid inner function calls to .append()
instead, pre-allocate a buffer and then extend the output.
-------------- next part --------------
=== modified file 'bzrlib/annotate.py'
--- a/bzrlib/annotate.py 2009-06-16 21:17:28 +0000
+++ b/bzrlib/annotate.py 2009-06-16 21:20:44 +0000
@@ -407,35 +407,34 @@
# Shortcut the case when the two sides match exactly
output_lines.extend(annotated_match_subset)
return
- append = output_lines.append
assert len(annotated_match_subset) == len(right_parent_subset)
+ resolved = [None] * len(annotated_match_subset)
for idx in xrange(len(annotated_match_subset)):
new_line = annotated_match_subset[idx]
right_line = right_parent_subset[idx]
assert new_line[1] == right_line[1]
- if new_line[0] == right_line[0]:
- # These have identical annotations, just go with it
- append(new_line)
- elif new_line[0] == new_revision_id:
- # the new annotation claims 'this' modified it, but it just simply
- # comes from the right parent
- append(right_line)
+ if new_line[0] == right_line[0] or new_line[0] == new_revision_id:
+ # These have identical annotations, or the right parent supersedes
+ # the 'new' status
+ resolved[idx] = right_line
else:
# Both new and right parent lay claim to this line, resolve
if heads_provider is None:
- append((new_revision_id, right_line[1]))
+ resolved[idx] = (new_revision_id, right_line[1])
else:
heads = heads_provider.heads((new_line[0], right_line[0]))
if len(heads) == 1:
for head in heads:
break
- append((head, new_line[1]))
+ resolved[idx] = (head, right_line[1])
else:
# Both claim different origins, get a stable result.
# If the result is not stable, there is a risk a
# performance degradation as criss-cross merges will
# flip-flop the attribution.
- append(_break_annotation_tie([new_line, right_line]))
+ resolved[idx] = _break_annotation_tie(
+ [new_line, right_line])
+ output_lines.extend(resolved)
def _reannotate_annotated(right_parent_lines, new_lines, new_revision_id,
More information about the bazaar-commits
mailing list