This commit is contained in:
redkale
2024-10-04 20:22:44 +08:00
parent 69fa2c9156
commit 198a3575f8

View File

@@ -470,94 +470,58 @@ public class ProtobufReader extends Reader {
protected int readRawVarint32() { // readUInt32 protected int readRawVarint32() { // readUInt32
byte[] data = content; byte[] data = content;
fastpath:
{
int curr = this.position; int curr = this.position;
if ((curr + 1) == limit) { byte b = data[++curr];
break fastpath; if (b >= 0) {
}
int x;
if ((x = data[++curr]) >= 0) {
this.position = curr; this.position = curr;
return x; return b;
} else if (limit - (curr + 1) < 9) { }
break fastpath; int result = b & 0x7f;
} else if ((x ^= (data[++curr] << 7)) < 0) { if ((b = data[++curr]) >= 0) {
x ^= (~0 << 7); result |= b << 7;
} else if ((x ^= (data[++curr] << 14)) >= 0) {
x ^= (~0 << 7) ^ (~0 << 14);
} else if ((x ^= (data[++curr] << 21)) < 0) {
x ^= (~0 << 7) ^ (~0 << 14) ^ (~0 << 21);
} else { } else {
int y = data[++curr]; result |= (b & 0x7f) << 7;
x ^= y << 28; if ((b = data[++curr]) >= 0) {
x ^= (~0 << 7) ^ (~0 << 14) ^ (~0 << 21) ^ (~0 << 28); result |= b << 14;
if (y < 0 } else {
&& data[++curr] < 0 result |= (b & 0x7f) << 14;
&& data[++curr] < 0 if ((b = data[++curr]) >= 0) {
&& data[++curr] < 0 result |= b << 21;
&& data[++curr] < 0 } else {
&& data[++curr] < 0) { result |= (b & 0x7f) << 21;
break fastpath; // Will throw malformedVarint() result |= (b = data[++curr]) << 28;
if (b < 0) {
// Discard upper 32 bits.
for (int i = 0; i < 5; i++) {
if (data[++curr] >= 0) {
this.position = curr;
return result;
}
}
throw new ConvertException("readRawVarint32 error");
}
}
} }
} }
this.position = curr; this.position = curr;
return x; return result;
}
return (int) readRawVarint64SlowPath();
} }
protected long readRawVarint64() { protected long readRawVarint64() {
byte[] data = content; byte[] data = content;
fastpath:
{
int curr = this.position; int curr = this.position;
if ((curr + 1) == this.limit) { int shift = 0;
break fastpath; long result = 0;
} while (shift < 64) {
final byte b = data[++curr];
long x; result |= (long) (b & 0x7F) << shift;
int y; if ((b & 0x80) == 0) {
if ((y = data[++curr]) >= 0) {
this.position = curr; this.position = curr;
return y; return result;
} else if (this.limit - (curr + 1) < 9) {
break fastpath;
} else if ((y ^= (data[++curr] << 7)) < 0) {
x = y ^ (~0 << 7);
} else if ((y ^= (data[++curr] << 14)) >= 0) {
x = y ^ ((~0 << 7) ^ (~0 << 14));
} else if ((y ^= (data[++curr] << 21)) < 0) {
x = y ^ ((~0 << 7) ^ (~0 << 14) ^ (~0 << 21));
} else if ((x = y ^ ((long) data[++curr] << 28)) >= 0L) {
x ^= (~0L << 7) ^ (~0L << 14) ^ (~0L << 21) ^ (~0L << 28);
} else if ((x ^= ((long) data[++curr] << 35)) < 0L) {
x ^= (~0L << 7) ^ (~0L << 14) ^ (~0L << 21) ^ (~0L << 28) ^ (~0L << 35);
} else if ((x ^= ((long) data[++curr] << 42)) >= 0L) {
x ^= (~0L << 7) ^ (~0L << 14) ^ (~0L << 21) ^ (~0L << 28) ^ (~0L << 35) ^ (~0L << 42);
} else if ((x ^= ((long) data[++curr] << 49)) < 0L) {
x ^= (~0L << 7) ^ (~0L << 14) ^ (~0L << 21) ^ (~0L << 28) ^ (~0L << 35) ^ (~0L << 42) ^ (~0L << 49);
} else {
x ^= ((long) data[++curr] << 56);
x ^= (~0L << 7)
^ (~0L << 14)
^ (~0L << 21)
^ (~0L << 28)
^ (~0L << 35)
^ (~0L << 42)
^ (~0L << 49)
^ (~0L << 56);
if (x < 0L) {
if (data[++curr] < 0L) {
break fastpath; // Will throw malformedVarint()
} }
shift += 7;
} }
} throw new ConvertException("readRawVarint64 error");
this.position = curr;
return x;
}
return readRawVarint64SlowPath();
} }
protected long readRawVarint64SlowPath() { protected long readRawVarint64SlowPath() {