# HG changeset patch # User Artem Tikhomirov # Date 1367587766 -7200 # Node ID 55b7987c1796ec89dbd9aba1638275df4172a8a1 # Parent d29d9dc6c1282d9969754743354c66c523b2cd1d Do not instantiate intermediate arrays diff -r d29d9dc6c128 -r 55b7987c1796 src/org/tmatesoft/hg/internal/ByteArrayDataAccess.java --- a/src/org/tmatesoft/hg/internal/ByteArrayDataAccess.java Fri May 03 15:19:18 2013 +0200 +++ b/src/org/tmatesoft/hg/internal/ByteArrayDataAccess.java Fri May 03 15:29:26 2013 +0200 @@ -54,9 +54,32 @@ if (len > (this.length - pos)) { throw new IOException(); } - System.arraycopy(data, pos, buf, off, len); + System.arraycopy(data, offset+pos, buf, off, len); pos += len; } + @Override + public int readInt() throws IOException { + // overridden not to create an intermediate array + if (length - pos < 4) { + throw new IOException(); + } + int x = offset + pos; + int rv = data[x++] << 24 | (data[x++] & 0xFF) << 16 | (data[x++] & 0xFF) << 8 | (data[x] & 0xFF); + pos += 4; + return rv; + } + @Override + public long readLong() throws IOException { + // overridden not to create an intermediate array + if (length - pos < 8) { + throw new IOException(); + } + int x = offset + pos; + int i1 = data[x++] << 24 | (data[x++] & 0xFF) << 16 | (data[x++] & 0xFF) << 8 | (data[x++] & 0xFF); + int i2 = data[x++] << 24 | (data[x++] & 0xFF) << 16 | (data[x++] & 0xFF) << 8 | (data[x] & 0xFF); + pos += 8; + return ((long) i1) << 32 | ((long) i2 & 0x0FFFFFFFFl); + } @Override public ByteArrayDataAccess reset() {