mirror of https://github.com/apache/lucene.git
LUCENE-2824: Optimize BufferedIndexInput to do less bounds checks
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1061622 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
e2675f59f8
commit
81dba8b8e8
|
@ -880,6 +880,9 @@ Optimizations
|
|||
DirectoryReaders or other MultiReaders. This saves lots of memory
|
||||
during merge of norms. (Uwe Schindler, Mike McCandless)
|
||||
|
||||
* LUCENE-2824: Optimize BufferedIndexInput to do less bounds checks.
|
||||
(Robert Muir)
|
||||
|
||||
Build
|
||||
|
||||
* LUCENE-2124: Moved the JDK-based collation support from contrib/collation
|
||||
|
|
|
@ -144,6 +144,68 @@ public abstract class BufferedIndexInput extends IndexInput {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public short readShort() throws IOException {
|
||||
if (2 <= (bufferLength-bufferPosition)) {
|
||||
return (short) (((buffer[bufferPosition++] & 0xFF) << 8) | (buffer[bufferPosition++] & 0xFF));
|
||||
} else {
|
||||
return super.readShort();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int readInt() throws IOException {
|
||||
if (4 <= (bufferLength-bufferPosition)) {
|
||||
return ((buffer[bufferPosition++] & 0xFF) << 24) | ((buffer[bufferPosition++] & 0xFF) << 16)
|
||||
| ((buffer[bufferPosition++] & 0xFF) << 8) | (buffer[bufferPosition++] & 0xFF);
|
||||
} else {
|
||||
return super.readInt();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public long readLong() throws IOException {
|
||||
if (8 <= (bufferLength-bufferPosition)) {
|
||||
final int i1 = ((buffer[bufferPosition++] & 0xff) << 24) | ((buffer[bufferPosition++] & 0xff) << 16) |
|
||||
((buffer[bufferPosition++] & 0xff) << 8) | (buffer[bufferPosition++] & 0xff);
|
||||
final int i2 = ((buffer[bufferPosition++] & 0xff) << 24) | ((buffer[bufferPosition++] & 0xff) << 16) |
|
||||
((buffer[bufferPosition++] & 0xff) << 8) | (buffer[bufferPosition++] & 0xff);
|
||||
return (((long)i1) << 32) | (i2 & 0xFFFFFFFFL);
|
||||
} else {
|
||||
return super.readLong();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int readVInt() throws IOException {
|
||||
if (5 <= (bufferLength-bufferPosition)) {
|
||||
byte b = buffer[bufferPosition++];
|
||||
int i = b & 0x7F;
|
||||
for (int shift = 7; (b & 0x80) != 0; shift += 7) {
|
||||
b = buffer[bufferPosition++];
|
||||
i |= (b & 0x7F) << shift;
|
||||
}
|
||||
return i;
|
||||
} else {
|
||||
return super.readVInt();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public long readVLong() throws IOException {
|
||||
if (9 <= bufferLength-bufferPosition) {
|
||||
byte b = buffer[bufferPosition++];
|
||||
long i = b & 0x7F;
|
||||
for (int shift = 7; (b & 0x80) != 0; shift += 7) {
|
||||
b = buffer[bufferPosition++];
|
||||
i |= (b & 0x7FL) << shift;
|
||||
}
|
||||
return i;
|
||||
} else {
|
||||
return super.readVLong();
|
||||
}
|
||||
}
|
||||
|
||||
private void refill() throws IOException {
|
||||
long start = bufferStart + bufferPosition;
|
||||
long end = start + bufferSize;
|
||||
|
|
Loading…
Reference in New Issue