Mercurial > hg4j
diff src/com/tmate/hgkit/ll/Nodeid.java @ 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 | d4fdd1845b3f |
children | 346b66add79d |
line wrap: on
line diff
--- 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); } }