# HG changeset patch # User Artem Tikhomirov # Date 1374421685 -7200 # Node ID 4f93bbc73b64b0a3a752dc60a302f62835060908 # Parent 58a6900f845d8e04dfe6564bba56adcedb56f29a Do not instantiate thousands of small arrays(numerous readInt/readLong calls) diff -r 58a6900f845d -r 4f93bbc73b64 src/org/tmatesoft/hg/internal/DataAccess.java --- a/src/org/tmatesoft/hg/internal/DataAccess.java Sun Jul 21 17:15:34 2013 +0200 +++ b/src/org/tmatesoft/hg/internal/DataAccess.java Sun Jul 21 17:48:05 2013 +0200 @@ -29,6 +29,8 @@ * @author TMate Software Ltd. */ public class DataAccess { + private byte[] longBuffer; + public boolean isEmpty() throws IOException { return true; } @@ -78,7 +80,10 @@ // no-op in this empty implementation } public int readInt() throws IOException { - byte[] b = new byte[4]; + if (longBuffer == null) { + longBuffer = new byte[8]; + } + byte[] b = longBuffer; readBytes(b, 0, 4); return b[0] << 24 | (b[1] & 0xFF) << 16 | (b[2] & 0xFF) << 8 | (b[3] & 0xFF); } @@ -87,7 +92,10 @@ * Read 8 bytes as long value, big-endian. */ public long readLong() throws IOException { - byte[] b = new byte[8]; + if (longBuffer == null) { + longBuffer = new byte[8]; + } + byte[] b = longBuffer; readBytes(b, 0, 8); int i1 = b[0] << 24 | (b[1] & 0xFF) << 16 | (b[2] & 0xFF) << 8 | (b[3] & 0xFF); int i2 = b[4] << 24 | (b[5] & 0xFF) << 16 | (b[6] & 0xFF) << 8 | (b[7] & 0xFF);