summaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit
diff options
context:
space:
mode:
authorShawn Pearce <sop@google.com>2013-04-11 01:11:11 -0700
committerShawn Pearce <sop@google.com>2013-04-11 01:17:35 -0700
commit0f32901ab7da9f0eaf1c716d66ce8d58bc70f101 (patch)
tree16683e084a2def2f816cf17cbaccea7325802cca /org.eclipse.jgit
parent1db50c9d91adaadc019938eaaa7e91e3963fb681 (diff)
downloadjgit-0f32901ab7da9f0eaf1c716d66ce8d58bc70f101.tar.gz
jgit-0f32901ab7da9f0eaf1c716d66ce8d58bc70f101.zip
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
Diffstat (limited to 'org.eclipse.jgit')
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/pack/DeltaEncoder.java37
1 files changed, 19 insertions, 18 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/pack/DeltaEncoder.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/pack/DeltaEncoder.java
index 8dfa62f0de..cccbc5903e 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/pack/DeltaEncoder.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/pack/DeltaEncoder.java
@@ -134,7 +134,7 @@ public class DeltaEncoder {
}
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 class DeltaEncoder {
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 class DeltaEncoder {
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 class DeltaEncoder {
}
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 class DeltaEncoder {
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;
}
}