changeset 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 73c20c648c1f
children 41218d84842a
files src/org/tmatesoft/hg/internal/Patch.java
diffstat 1 files changed, 10 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/src/org/tmatesoft/hg/internal/Patch.java	Fri Apr 26 18:38:41 2013 +0200
+++ b/src/org/tmatesoft/hg/internal/Patch.java	Fri Apr 26 20:04:17 2013 +0200
@@ -68,14 +68,18 @@
 	}
 	
 	public Patch() {
-		this(false);
+		this(16, false);
+	}
+	
+	public Patch(boolean normalizeOnChange) {
+		this(16, normalizeOnChange);
 	}
 
-	public Patch(boolean normalizeOnChange) {
+	public Patch(int sizeHint, boolean normalizeOnChange) {
 		shallNormalize = normalizeOnChange;
-		starts = new IntVector();
-		ends = new IntVector();
-		data = new ArrayList<byte[]>();
+		starts = new IntVector(sizeHint, -1);
+		ends = new IntVector(sizeHint, -1);
+		data = new ArrayList<byte[]>(sizeHint);
 	}
 	
 	public String toString() {
@@ -227,7 +231,7 @@
 	 * Modify this patch with subsequent patch 
 	 */
 	public /*SHALL BE PUBLIC ONCE TESTING ENDS*/ Patch apply(Patch another) {
-		Patch r = new Patch(shallNormalize);
+		Patch r = new Patch(count() + another.count() * 2, shallNormalize);
 		int p1TotalAppliedDelta = 0; // value to add to start and end indexes of the older patch to get their values as if
 		// in the patched text, iow, directly comparable with respective indexes from the newer patch.
 		int p1EntryStart = 0, p1EntryEnd = 0, p1EntryLen = 0;