You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by rm...@apache.org on 2011/01/21 05:10:05 UTC
svn commit: r1061622 - in /lucene/dev/trunk/lucene: CHANGES.txt
src/java/org/apache/lucene/store/BufferedIndexInput.java
Author: rmuir
Date: Fri Jan 21 04:10:05 2011
New Revision: 1061622
URL: http://svn.apache.org/viewvc?rev=1061622&view=rev
Log:
LUCENE-2824: Optimize BufferedIndexInput to do less bounds checks
Modified:
lucene/dev/trunk/lucene/CHANGES.txt
lucene/dev/trunk/lucene/src/java/org/apache/lucene/store/BufferedIndexInput.java
Modified: lucene/dev/trunk/lucene/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/CHANGES.txt?rev=1061622&r1=1061621&r2=1061622&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/CHANGES.txt (original)
+++ lucene/dev/trunk/lucene/CHANGES.txt Fri Jan 21 04:10:05 2011
@@ -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
Modified: lucene/dev/trunk/lucene/src/java/org/apache/lucene/store/BufferedIndexInput.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/java/org/apache/lucene/store/BufferedIndexInput.java?rev=1061622&r1=1061621&r2=1061622&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/java/org/apache/lucene/store/BufferedIndexInput.java (original)
+++ lucene/dev/trunk/lucene/src/java/org/apache/lucene/store/BufferedIndexInput.java Fri Jan 21 04:10:05 2011
@@ -144,6 +144,68 @@ public abstract class BufferedIndexInput
}
}
+ @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;