LUCENE-3738: Simplification of unrolled vint code

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1307910 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Uwe Schindler 2012-03-31 21:33:19 +00:00
parent 9ed6aaf3bf
commit 565c47e207
3 changed files with 39 additions and 39 deletions

View File

@ -199,17 +199,17 @@ public abstract class BufferedIndexInput extends IndexInput {
public final int readVInt() throws IOException { public final int readVInt() throws IOException {
if (5 <= (bufferLength-bufferPosition)) { if (5 <= (bufferLength-bufferPosition)) {
byte b = buffer[bufferPosition++]; byte b = buffer[bufferPosition++];
if (b >= 0) return b;
int i = b & 0x7F; int i = b & 0x7F;
if ((b & 0x80) == 0) return i;
b = buffer[bufferPosition++]; b = buffer[bufferPosition++];
i |= (b & 0x7F) << 7; i |= (b & 0x7F) << 7;
if ((b & 0x80) == 0) return i; if (b >= 0) return i;
b = buffer[bufferPosition++]; b = buffer[bufferPosition++];
i |= (b & 0x7F) << 14; i |= (b & 0x7F) << 14;
if ((b & 0x80) == 0) return i; if (b >= 0) return i;
b = buffer[bufferPosition++]; b = buffer[bufferPosition++];
i |= (b & 0x7F) << 21; i |= (b & 0x7F) << 21;
if ((b & 0x80) == 0) return i; if (b >= 0) return i;
b = buffer[bufferPosition++]; b = buffer[bufferPosition++];
// Warning: the next ands use 0x0F / 0xF0 - beware copy/paste errors: // Warning: the next ands use 0x0F / 0xF0 - beware copy/paste errors:
i |= (b & 0x0F) << 28; i |= (b & 0x0F) << 28;
@ -224,32 +224,32 @@ public abstract class BufferedIndexInput extends IndexInput {
public final long readVLong() throws IOException { public final long readVLong() throws IOException {
if (9 <= bufferLength-bufferPosition) { if (9 <= bufferLength-bufferPosition) {
byte b = buffer[bufferPosition++]; byte b = buffer[bufferPosition++];
if (b >= 0) return b;
long i = b & 0x7FL; long i = b & 0x7FL;
if ((b & 0x80) == 0) return i;
b = buffer[bufferPosition++]; b = buffer[bufferPosition++];
i |= (b & 0x7FL) << 7; i |= (b & 0x7FL) << 7;
if ((b & 0x80) == 0) return i; if (b >= 0) return i;
b = buffer[bufferPosition++]; b = buffer[bufferPosition++];
i |= (b & 0x7FL) << 14; i |= (b & 0x7FL) << 14;
if ((b & 0x80) == 0) return i; if (b >= 0) return i;
b = buffer[bufferPosition++]; b = buffer[bufferPosition++];
i |= (b & 0x7FL) << 21; i |= (b & 0x7FL) << 21;
if ((b & 0x80) == 0) return i; if (b >= 0) return i;
b = buffer[bufferPosition++]; b = buffer[bufferPosition++];
i |= (b & 0x7FL) << 28; i |= (b & 0x7FL) << 28;
if ((b & 0x80) == 0) return i; if (b >= 0) return i;
b = buffer[bufferPosition++]; b = buffer[bufferPosition++];
i |= (b & 0x7FL) << 35; i |= (b & 0x7FL) << 35;
if ((b & 0x80) == 0) return i; if (b >= 0) return i;
b = buffer[bufferPosition++]; b = buffer[bufferPosition++];
i |= (b & 0x7FL) << 42; i |= (b & 0x7FL) << 42;
if ((b & 0x80) == 0) return i; if (b >= 0) return i;
b = buffer[bufferPosition++]; b = buffer[bufferPosition++];
i |= (b & 0x7FL) << 49; i |= (b & 0x7FL) << 49;
if ((b & 0x80) == 0) return i; if (b >= 0) return i;
b = buffer[bufferPosition++]; b = buffer[bufferPosition++];
i |= (b & 0x7FL) << 56; i |= (b & 0x7FL) << 56;
if ((b & 0x80) == 0) return i; if (b >= 0) return i;
throw new IOException("Invalid vLong detected (negative values disallowed)"); throw new IOException("Invalid vLong detected (negative values disallowed)");
} else { } else {
return super.readVLong(); return super.readVLong();

View File

@ -102,17 +102,17 @@ public final class ByteArrayDataInput extends DataInput {
@Override @Override
public int readVInt() { public int readVInt() {
byte b = bytes[pos++]; byte b = bytes[pos++];
if (b >= 0) return b;
int i = b & 0x7F; int i = b & 0x7F;
if ((b & 0x80) == 0) return i;
b = bytes[pos++]; b = bytes[pos++];
i |= (b & 0x7F) << 7; i |= (b & 0x7F) << 7;
if ((b & 0x80) == 0) return i; if (b >= 0) return i;
b = bytes[pos++]; b = bytes[pos++];
i |= (b & 0x7F) << 14; i |= (b & 0x7F) << 14;
if ((b & 0x80) == 0) return i; if (b >= 0) return i;
b = bytes[pos++]; b = bytes[pos++];
i |= (b & 0x7F) << 21; i |= (b & 0x7F) << 21;
if ((b & 0x80) == 0) return i; if (b >= 0) return i;
b = bytes[pos++]; b = bytes[pos++];
// Warning: the next ands use 0x0F / 0xF0 - beware copy/paste errors: // Warning: the next ands use 0x0F / 0xF0 - beware copy/paste errors:
i |= (b & 0x0F) << 28; i |= (b & 0x0F) << 28;
@ -123,32 +123,32 @@ public final class ByteArrayDataInput extends DataInput {
@Override @Override
public long readVLong() { public long readVLong() {
byte b = bytes[pos++]; byte b = bytes[pos++];
if (b >= 0) return b;
long i = b & 0x7FL; long i = b & 0x7FL;
if ((b & 0x80) == 0) return i;
b = bytes[pos++]; b = bytes[pos++];
i |= (b & 0x7FL) << 7; i |= (b & 0x7FL) << 7;
if ((b & 0x80) == 0) return i; if (b >= 0) return i;
b = bytes[pos++]; b = bytes[pos++];
i |= (b & 0x7FL) << 14; i |= (b & 0x7FL) << 14;
if ((b & 0x80) == 0) return i; if (b >= 0) return i;
b = bytes[pos++]; b = bytes[pos++];
i |= (b & 0x7FL) << 21; i |= (b & 0x7FL) << 21;
if ((b & 0x80) == 0) return i; if (b >= 0) return i;
b = bytes[pos++]; b = bytes[pos++];
i |= (b & 0x7FL) << 28; i |= (b & 0x7FL) << 28;
if ((b & 0x80) == 0) return i; if (b >= 0) return i;
b = bytes[pos++]; b = bytes[pos++];
i |= (b & 0x7FL) << 35; i |= (b & 0x7FL) << 35;
if ((b & 0x80) == 0) return i; if (b >= 0) return i;
b = bytes[pos++]; b = bytes[pos++];
i |= (b & 0x7FL) << 42; i |= (b & 0x7FL) << 42;
if ((b & 0x80) == 0) return i; if (b >= 0) return i;
b = bytes[pos++]; b = bytes[pos++];
i |= (b & 0x7FL) << 49; i |= (b & 0x7FL) << 49;
if ((b & 0x80) == 0) return i; if (b >= 0) return i;
b = bytes[pos++]; b = bytes[pos++];
i |= (b & 0x7FL) << 56; i |= (b & 0x7FL) << 56;
if ((b & 0x80) == 0) return i; if (b >= 0) return i;
throw new RuntimeException("Invalid vLong detected (negative values disallowed)"); throw new RuntimeException("Invalid vLong detected (negative values disallowed)");
} }

View File

@ -94,17 +94,17 @@ public abstract class DataInput implements Cloneable {
return i; return i;
*/ */
byte b = readByte(); byte b = readByte();
if (b >= 0) return b;
int i = b & 0x7F; int i = b & 0x7F;
if ((b & 0x80) == 0) return i;
b = readByte(); b = readByte();
i |= (b & 0x7F) << 7; i |= (b & 0x7F) << 7;
if ((b & 0x80) == 0) return i; if (b >= 0) return i;
b = readByte(); b = readByte();
i |= (b & 0x7F) << 14; i |= (b & 0x7F) << 14;
if ((b & 0x80) == 0) return i; if (b >= 0) return i;
b = readByte(); b = readByte();
i |= (b & 0x7F) << 21; i |= (b & 0x7F) << 21;
if ((b & 0x80) == 0) return i; if (b >= 0) return i;
b = readByte(); b = readByte();
// Warning: the next ands use 0x0F / 0xF0 - beware copy/paste errors: // Warning: the next ands use 0x0F / 0xF0 - beware copy/paste errors:
i |= (b & 0x0F) << 28; i |= (b & 0x0F) << 28;
@ -135,32 +135,32 @@ public abstract class DataInput implements Cloneable {
return i; return i;
*/ */
byte b = readByte(); byte b = readByte();
if (b >= 0) return b;
long i = b & 0x7FL; long i = b & 0x7FL;
if ((b & 0x80) == 0) return i;
b = readByte(); b = readByte();
i |= (b & 0x7FL) << 7; i |= (b & 0x7FL) << 7;
if ((b & 0x80) == 0) return i; if (b >= 0) return i;
b = readByte(); b = readByte();
i |= (b & 0x7FL) << 14; i |= (b & 0x7FL) << 14;
if ((b & 0x80) == 0) return i; if (b >= 0) return i;
b = readByte(); b = readByte();
i |= (b & 0x7FL) << 21; i |= (b & 0x7FL) << 21;
if ((b & 0x80) == 0) return i; if (b >= 0) return i;
b = readByte(); b = readByte();
i |= (b & 0x7FL) << 28; i |= (b & 0x7FL) << 28;
if ((b & 0x80) == 0) return i; if (b >= 0) return i;
b = readByte(); b = readByte();
i |= (b & 0x7FL) << 35; i |= (b & 0x7FL) << 35;
if ((b & 0x80) == 0) return i; if (b >= 0) return i;
b = readByte(); b = readByte();
i |= (b & 0x7FL) << 42; i |= (b & 0x7FL) << 42;
if ((b & 0x80) == 0) return i; if (b >= 0) return i;
b = readByte(); b = readByte();
i |= (b & 0x7FL) << 49; i |= (b & 0x7FL) << 49;
if ((b & 0x80) == 0) return i; if (b >= 0) return i;
b = readByte(); b = readByte();
i |= (b & 0x7FL) << 56; i |= (b & 0x7FL) << 56;
if ((b & 0x80) == 0) return i; if (b >= 0) return i;
throw new IOException("Invalid vLong detected (negative values disallowed)"); throw new IOException("Invalid vLong detected (negative values disallowed)");
} }