Mercurial > hg4j
changeset 681:4f93bbc73b64
Do not instantiate thousands of small arrays(numerous readInt/readLong calls)
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Sun, 21 Jul 2013 17:48:05 +0200 |
parents | 58a6900f845d |
children | f568330dd9c0 |
files | src/org/tmatesoft/hg/internal/DataAccess.java |
diffstat | 1 files changed, 10 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- 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);