comparison src/org/tmatesoft/hg/internal/FileAnnotation.java @ 674:cce0387c6041

Introduced dedicated IntSliceSeq/IntTuple in place of IntArray with subsequences
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Wed, 17 Jul 2013 15:40:51 +0200
parents 72c979555cb8
children
comparison
equal deleted inserted replaced
673:545b1d4cc11d 674:cce0387c6041
41 public interface LineDescriptor { 41 public interface LineDescriptor {
42 int totalLines(); 42 int totalLines();
43 } 43 }
44 44
45 // keeps <startSeq1, startSeq2, len> of equal blocks, origin to target, from some previous step 45 // keeps <startSeq1, startSeq2, len> of equal blocks, origin to target, from some previous step
46 private RangeSeq activeEquals; 46 private RangePairSeq activeEquals;
47 // equal blocks of the current iteration, to be recalculated before next step 47 // equal blocks of the current iteration, to be recalculated before next step
48 // to track line number (current target to ultimate target) mapping 48 // to track line number (current target to ultimate target) mapping
49 private RangeSeq intermediateEquals = new RangeSeq(); 49 private RangePairSeq intermediateEquals = new RangePairSeq();
50 50
51 private boolean[] knownLines; 51 private boolean[] knownLines;
52 private final LineInspector delegate; 52 private final LineInspector delegate;
53 private RevisionDescriptor revisionDescriptor; 53 private RevisionDescriptor revisionDescriptor;
54 private BlockData lineContent; 54 private BlockData lineContent;
55 55
56 private IntMap<RangeSeq> mergedRanges = new IntMap<RangeSeq>(10); 56 private IntMap<RangePairSeq> mergedRanges = new IntMap<RangePairSeq>(10);
57 private IntMap<RangeSeq> equalRanges = new IntMap<RangeSeq>(10); 57 private IntMap<RangePairSeq> equalRanges = new IntMap<RangePairSeq>(10);
58 private boolean activeEqualsComesFromMerge = false; 58 private boolean activeEqualsComesFromMerge = false;
59 59
60 public FileAnnotation(LineInspector lineInspector) { 60 public FileAnnotation(LineInspector lineInspector) {
61 delegate = lineInspector; 61 delegate = lineInspector;
62 } 62 }
64 public void start(RevisionDescriptor rd) { 64 public void start(RevisionDescriptor rd) {
65 revisionDescriptor = rd; 65 revisionDescriptor = rd;
66 if (knownLines == null) { 66 if (knownLines == null) {
67 lineContent = rd.target(); 67 lineContent = rd.target();
68 knownLines = new boolean[lineContent.elementCount()]; 68 knownLines = new boolean[lineContent.elementCount()];
69 activeEquals = new RangeSeq(); 69 activeEquals = new RangePairSeq();
70 activeEquals.add(0, 0, knownLines.length); 70 activeEquals.add(0, 0, knownLines.length);
71 equalRanges.put(rd.targetChangesetIndex(), activeEquals); 71 equalRanges.put(rd.targetChangesetIndex(), activeEquals);
72 } else { 72 } else {
73 activeEquals = equalRanges.get(rd.targetChangesetIndex()); 73 activeEquals = equalRanges.get(rd.targetChangesetIndex());
74 if (activeEquals == null) { 74 if (activeEquals == null) {
83 } 83 }
84 } 84 }
85 85
86 public void done(RevisionDescriptor rd) { 86 public void done(RevisionDescriptor rd) {
87 // update line numbers of the intermediate target to point to ultimate target's line numbers 87 // update line numbers of the intermediate target to point to ultimate target's line numbers
88 RangeSeq v = intermediateEquals.intersect(activeEquals); 88 RangePairSeq v = intermediateEquals.intersect(activeEquals);
89 if (activeEqualsComesFromMerge) { 89 if (activeEqualsComesFromMerge) {
90 mergedRanges.put(rd.originChangesetIndex(), v); 90 mergedRanges.put(rd.originChangesetIndex(), v);
91 } else { 91 } else {
92 equalRanges.put(rd.originChangesetIndex(), v); 92 equalRanges.put(rd.originChangesetIndex(), v);
93 } 93 }
94 if (rd.isMerge() && !mergedRanges.containsKey(rd.mergeChangesetIndex())) { 94 if (rd.isMerge() && !mergedRanges.containsKey(rd.mergeChangesetIndex())) {
95 // seen merge, but no lines were merged from p2. 95 // seen merge, but no lines were merged from p2.
96 // Add empty range to avoid uncertainty when a parent of p2 pops in 96 // Add empty range to avoid uncertainty when a parent of p2 pops in
97 mergedRanges.put(rd.mergeChangesetIndex(), new RangeSeq()); 97 mergedRanges.put(rd.mergeChangesetIndex(), new RangePairSeq());
98 } 98 }
99 intermediateEquals.clear(); 99 intermediateEquals.clear();
100 activeEquals = null; 100 activeEquals = null;
101 activeEqualsComesFromMerge = false; 101 activeEqualsComesFromMerge = false;
102 revisionDescriptor = null; 102 revisionDescriptor = null;
105 public void same(EqualBlock block) { 105 public void same(EqualBlock block) {
106 intermediateEquals.add(block.originStart(), block.targetStart(), block.length()); 106 intermediateEquals.add(block.originStart(), block.targetStart(), block.length());
107 } 107 }
108 108
109 public void added(AddBlock block) { 109 public void added(AddBlock block) {
110 RangeSeq rs = null; 110 RangePairSeq rs = null;
111 if (revisionDescriptor.isMerge() && block.originChangesetIndex() == revisionDescriptor.mergeChangesetIndex()) { 111 if (revisionDescriptor.isMerge() && block.originChangesetIndex() == revisionDescriptor.mergeChangesetIndex()) {
112 rs = mergedRanges.get(revisionDescriptor.mergeChangesetIndex()); 112 rs = mergedRanges.get(revisionDescriptor.mergeChangesetIndex());
113 if (rs == null) { 113 if (rs == null) {
114 mergedRanges.put(revisionDescriptor.mergeChangesetIndex(), rs = new RangeSeq()); 114 mergedRanges.put(revisionDescriptor.mergeChangesetIndex(), rs = new RangePairSeq());
115 } 115 }
116 } 116 }
117 if (activeEquals.size() == 0) { 117 if (activeEquals.size() == 0) {
118 return; 118 return;
119 } 119 }