comparison src/org/tmatesoft/hg/internal/Patch.java @ 587:a52f4cc56f9c

Minimize vectors re-allocating when merging patches
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Fri, 26 Apr 2013 20:04:17 +0200
parents ed243b668502
children 7c0d2ce340b8
comparison
equal deleted inserted replaced
586:73c20c648c1f 587:a52f4cc56f9c
66 Patch r = p1.apply(p2); 66 Patch r = p1.apply(p2);
67 System.out.println("r: " + r); 67 System.out.println("r: " + r);
68 } 68 }
69 69
70 public Patch() { 70 public Patch() {
71 this(false); 71 this(16, false);
72 } 72 }
73 73
74 public Patch(boolean normalizeOnChange) { 74 public Patch(boolean normalizeOnChange) {
75 this(16, normalizeOnChange);
76 }
77
78 public Patch(int sizeHint, boolean normalizeOnChange) {
75 shallNormalize = normalizeOnChange; 79 shallNormalize = normalizeOnChange;
76 starts = new IntVector(); 80 starts = new IntVector(sizeHint, -1);
77 ends = new IntVector(); 81 ends = new IntVector(sizeHint, -1);
78 data = new ArrayList<byte[]>(); 82 data = new ArrayList<byte[]>(sizeHint);
79 } 83 }
80 84
81 public String toString() { 85 public String toString() {
82 StringBuilder sb = new StringBuilder(); 86 StringBuilder sb = new StringBuilder();
83 Formatter f = new Formatter(sb); 87 Formatter f = new Formatter(sb);
225 229
226 /** 230 /**
227 * Modify this patch with subsequent patch 231 * Modify this patch with subsequent patch
228 */ 232 */
229 public /*SHALL BE PUBLIC ONCE TESTING ENDS*/ Patch apply(Patch another) { 233 public /*SHALL BE PUBLIC ONCE TESTING ENDS*/ Patch apply(Patch another) {
230 Patch r = new Patch(shallNormalize); 234 Patch r = new Patch(count() + another.count() * 2, shallNormalize);
231 int p1TotalAppliedDelta = 0; // value to add to start and end indexes of the older patch to get their values as if 235 int p1TotalAppliedDelta = 0; // value to add to start and end indexes of the older patch to get their values as if
232 // in the patched text, iow, directly comparable with respective indexes from the newer patch. 236 // in the patched text, iow, directly comparable with respective indexes from the newer patch.
233 int p1EntryStart = 0, p1EntryEnd = 0, p1EntryLen = 0; 237 int p1EntryStart = 0, p1EntryEnd = 0, p1EntryLen = 0;
234 byte[] p1Data = null; 238 byte[] p1Data = null;
235 boolean insideP1entry = false; 239 boolean insideP1entry = false;