Micro-optimize copy instructions in DeltaEncoder
The copy instruction formatter should not to compute the shifts and masks twice. Instead compute them once and assume there is a register available to store the temporary "b" for compare with 0. Change-Id: Ic7826f29dca67b16903d8f790bdf785eb478c10d
This commit is contained in:
parent
1db50c9d91
commit
0f32901ab7
|
@ -134,7 +134,7 @@ private void writeVarint(long sz) throws IOException {
|
|||
}
|
||||
buf[p++] = (byte) (((int) sz) & 0x7f);
|
||||
size += p;
|
||||
if (limit <= 0 || size < limit)
|
||||
if (limit == 0 || size < limit)
|
||||
out.write(buf, 0, p);
|
||||
}
|
||||
|
||||
|
@ -189,7 +189,7 @@ public boolean insert(byte[] text, int off, int cnt)
|
|||
throws IOException {
|
||||
if (cnt <= 0)
|
||||
return true;
|
||||
if (0 < limit) {
|
||||
if (limit != 0) {
|
||||
int hdrs = cnt / MAX_INSERT_DATA_SIZE;
|
||||
if (cnt % MAX_INSERT_DATA_SIZE != 0)
|
||||
hdrs++;
|
||||
|
@ -236,7 +236,7 @@ public boolean copy(long offset, int cnt) throws IOException {
|
|||
cnt -= MAX_V2_COPY;
|
||||
|
||||
if (buf.length < p + MAX_COPY_CMD_SIZE) {
|
||||
if (0 < limit && limit < size + p)
|
||||
if (limit != 0 && limit < size + p)
|
||||
return false;
|
||||
out.write(buf, 0, p);
|
||||
size += p;
|
||||
|
@ -245,7 +245,7 @@ public boolean copy(long offset, int cnt) throws IOException {
|
|||
}
|
||||
|
||||
p = encodeCopy(p, offset, cnt);
|
||||
if (0 < limit && limit < size + p)
|
||||
if (limit != 0 && limit < size + p)
|
||||
return false;
|
||||
out.write(buf, 0, p);
|
||||
size += p;
|
||||
|
@ -255,36 +255,37 @@ public boolean copy(long offset, int cnt) throws IOException {
|
|||
private int encodeCopy(int p, long offset, int cnt) {
|
||||
int cmd = 0x80;
|
||||
final int cmdPtr = p++; // save room for the command
|
||||
byte b;
|
||||
|
||||
if ((offset & 0xff) != 0) {
|
||||
if ((b = (byte) (offset & 0xff)) != 0) {
|
||||
cmd |= 0x01;
|
||||
buf[p++] = (byte) (offset & 0xff);
|
||||
buf[p++] = b;
|
||||
}
|
||||
if ((offset & (0xff << 8)) != 0) {
|
||||
if ((b = (byte) ((offset >>> 8) & 0xff)) != 0) {
|
||||
cmd |= 0x02;
|
||||
buf[p++] = (byte) ((offset >>> 8) & 0xff);
|
||||
buf[p++] = b;
|
||||
}
|
||||
if ((offset & (0xff << 16)) != 0) {
|
||||
if ((b = (byte) ((offset >>> 16) & 0xff)) != 0) {
|
||||
cmd |= 0x04;
|
||||
buf[p++] = (byte) ((offset >>> 16) & 0xff);
|
||||
buf[p++] = b;
|
||||
}
|
||||
if ((offset & (0xff << 24)) != 0) {
|
||||
if ((b = (byte) ((offset >>> 24) & 0xff)) != 0) {
|
||||
cmd |= 0x08;
|
||||
buf[p++] = (byte) ((offset >>> 24) & 0xff);
|
||||
buf[p++] = b;
|
||||
}
|
||||
|
||||
if (cnt != MAX_V2_COPY) {
|
||||
if ((cnt & 0xff) != 0) {
|
||||
if ((b = (byte) (cnt & 0xff)) != 0) {
|
||||
cmd |= 0x10;
|
||||
buf[p++] = (byte) (cnt & 0xff);
|
||||
buf[p++] = b;
|
||||
}
|
||||
if ((cnt & (0xff << 8)) != 0) {
|
||||
if ((b = (byte) ((cnt >>> 8) & 0xff)) != 0) {
|
||||
cmd |= 0x20;
|
||||
buf[p++] = (byte) ((cnt >>> 8) & 0xff);
|
||||
buf[p++] = b;
|
||||
}
|
||||
if ((cnt & (0xff << 16)) != 0) {
|
||||
if ((b = (byte) ((cnt >>> 16) & 0xff)) != 0) {
|
||||
cmd |= 0x40;
|
||||
buf[p++] = (byte) ((cnt >>> 16) & 0xff);
|
||||
buf[p++] = b;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue