changeset 28:b2251b7a9823

Explicit cons arg for clone is more error-prone
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Tue, 11 Jan 2011 04:34:34 +0100
parents b0a15cefdfd6
children 6cce719bbb62
files src/com/tmate/hgkit/ll/HgManifest.java src/com/tmate/hgkit/ll/Nodeid.java
diffstat 2 files changed, 6 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/src/com/tmate/hgkit/ll/HgManifest.java	Sun Jan 09 16:02:26 2011 +0100
+++ b/src/com/tmate/hgkit/ll/HgManifest.java	Tue Jan 11 04:34:34 2011 +0100
@@ -22,7 +22,7 @@
 				if (!gtg) {
 					return;
 				}
-				gtg = gtg && inspector.begin(revisionNumber, new Nodeid(nodeid.clone()));
+				gtg = gtg && inspector.begin(revisionNumber, new Nodeid(nodeid, true));
 				int i;
 				String fname = null;
 				String flags = null;
--- a/src/com/tmate/hgkit/ll/Nodeid.java	Sun Jan 09 16:02:26 2011 +0100
+++ b/src/com/tmate/hgkit/ll/Nodeid.java	Tue Jan 11 04:34:34 2011 +0100
@@ -21,15 +21,16 @@
 	private final byte[] binaryData; 
 
 	/**
-	 * @param binaryRepresentation - byte[20], kept by reference. Use {@link #clone()} if original array may get changed. 
+	 * @param binaryRepresentation - byte[20], kept by reference
+	 * @param shallClone - true if array is subject to future modification and shall be copied, not referenced 
 	 */
-	public Nodeid(byte[] binaryRepresentation) {
+	public Nodeid(byte[] binaryRepresentation, boolean shallClone) {
 		// 5 int fields => 32 bytes
 		// byte[20] => 48 bytes
 		if (binaryRepresentation == null || binaryRepresentation.length != 20) {
 			throw new IllegalArgumentException();
 		}
-		this.binaryData = binaryRepresentation;
+		this.binaryData = shallClone ? binaryRepresentation.clone() : binaryRepresentation;
 	}
 
 	@Override
@@ -66,6 +67,6 @@
 			int lowNibble = Character.digit(asciiRepresentation[j++], 16);
 			data[i] = (byte) (((hiNibble << 4) | lowNibble) & 0xFF);
 		}
-		return new Nodeid(data);
+		return new Nodeid(data, false);
 	}
 }