comparison src/org/tmatesoft/hg/internal/ByteArrayDataAccess.java @ 599:55b7987c1796

Do not instantiate intermediate arrays
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Fri, 03 May 2013 15:29:26 +0200
parents 6c22bdc0bdfd
children 46b56864b483
comparison
equal deleted inserted replaced
598:d29d9dc6c128 599:55b7987c1796
52 @Override 52 @Override
53 public void readBytes(byte[] buf, int off, int len) throws IOException { 53 public void readBytes(byte[] buf, int off, int len) throws IOException {
54 if (len > (this.length - pos)) { 54 if (len > (this.length - pos)) {
55 throw new IOException(); 55 throw new IOException();
56 } 56 }
57 System.arraycopy(data, pos, buf, off, len); 57 System.arraycopy(data, offset+pos, buf, off, len);
58 pos += len; 58 pos += len;
59 }
60 @Override
61 public int readInt() throws IOException {
62 // overridden not to create an intermediate array
63 if (length - pos < 4) {
64 throw new IOException();
65 }
66 int x = offset + pos;
67 int rv = data[x++] << 24 | (data[x++] & 0xFF) << 16 | (data[x++] & 0xFF) << 8 | (data[x] & 0xFF);
68 pos += 4;
69 return rv;
70 }
71 @Override
72 public long readLong() throws IOException {
73 // overridden not to create an intermediate array
74 if (length - pos < 8) {
75 throw new IOException();
76 }
77 int x = offset + pos;
78 int i1 = data[x++] << 24 | (data[x++] & 0xFF) << 16 | (data[x++] & 0xFF) << 8 | (data[x++] & 0xFF);
79 int i2 = data[x++] << 24 | (data[x++] & 0xFF) << 16 | (data[x++] & 0xFF) << 8 | (data[x] & 0xFF);
80 pos += 8;
81 return ((long) i1) << 32 | ((long) i2 & 0x0FFFFFFFFl);
59 } 82 }
60 83
61 @Override 84 @Override
62 public ByteArrayDataAccess reset() { 85 public ByteArrayDataAccess reset() {
63 pos = 0; 86 pos = 0;