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 2010/12/19 01:15:28 UTC
svn commit: r1050737 -
/lucene/dev/trunk/lucene/src/java/org/apache/lucene/store/MMapDirectory.java
Author: rmuir
Date: Sun Dec 19 00:15:28 2010
New Revision: 1050737
URL: http://svn.apache.org/viewvc?rev=1050737&view=rev
Log:
LUCENE-2816: MMapDirectory speedups
Modified:
lucene/dev/trunk/lucene/src/java/org/apache/lucene/store/MMapDirectory.java
Modified: lucene/dev/trunk/lucene/src/java/org/apache/lucene/store/MMapDirectory.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/java/org/apache/lucene/store/MMapDirectory.java?rev=1050737&r1=1050736&r2=1050737&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/java/org/apache/lucene/store/MMapDirectory.java (original)
+++ lucene/dev/trunk/lucene/src/java/org/apache/lucene/store/MMapDirectory.java Sun Dec 19 00:15:28 2010
@@ -242,8 +242,35 @@ public class MMapDirectory extends FSDir
throw new IOException("read past EOF");
}
}
+
+ @Override
+ public short readShort() throws IOException {
+ try {
+ return buffer.getShort();
+ } catch (BufferUnderflowException e) {
+ throw new IOException("read past EOF");
+ }
+ }
@Override
+ public int readInt() throws IOException {
+ try {
+ return buffer.getInt();
+ } catch (BufferUnderflowException e) {
+ throw new IOException("read past EOF");
+ }
+ }
+
+ @Override
+ public long readLong() throws IOException {
+ try {
+ return buffer.getLong();
+ } catch (BufferUnderflowException e) {
+ throw new IOException("read past EOF");
+ }
+ }
+
+ @Override
public long getFilePointer() {
return buffer.position();
}
@@ -294,7 +321,6 @@ public class MMapDirectory extends FSDir
private final int maxBufSize;
private ByteBuffer curBuf; // redundant for speed: buffers[curBufIndex]
- private int curAvail; // redundant for speed: (bufSizes[curBufIndex] - curBuf.position())
private boolean isClone = false;
@@ -333,38 +359,67 @@ public class MMapDirectory extends FSDir
@Override
public byte readByte() throws IOException {
- // Performance might be improved by reading ahead into an array of
- // e.g. 128 bytes and readByte() from there.
- if (curAvail == 0) {
+ try {
+ return curBuf.get();
+ } catch (BufferUnderflowException e) {
curBufIndex++;
if (curBufIndex >= buffers.length)
throw new IOException("read past EOF");
curBuf = buffers[curBufIndex];
curBuf.position(0);
- curAvail = bufSizes[curBufIndex];
+ return curBuf.get();
}
- curAvail--;
- return curBuf.get();
}
@Override
public void readBytes(byte[] b, int offset, int len) throws IOException {
- while (len > curAvail) {
- curBuf.get(b, offset, curAvail);
- len -= curAvail;
- offset += curAvail;
- curBufIndex++;
- if (curBufIndex >= buffers.length)
- throw new IOException("read past EOF");
- curBuf = buffers[curBufIndex];
- curBuf.position(0);
- curAvail = bufSizes[curBufIndex];
+ try {
+ curBuf.get(b, offset, len);
+ } catch (BufferUnderflowException e) {
+ int curAvail = curBuf.remaining();
+ while (len > curAvail) {
+ curBuf.get(b, offset, curAvail);
+ len -= curAvail;
+ offset += curAvail;
+ curBufIndex++;
+ if (curBufIndex >= buffers.length)
+ throw new IOException("read past EOF");
+ curBuf = buffers[curBufIndex];
+ curBuf.position(0);
+ curAvail = curBuf.remaining();
+ }
+ curBuf.get(b, offset, len);
}
- curBuf.get(b, offset, len);
- curAvail -= len;
}
@Override
+ public short readShort() throws IOException {
+ try {
+ return curBuf.getShort();
+ } catch (BufferUnderflowException e) {
+ return super.readShort();
+ }
+ }
+
+ @Override
+ public int readInt() throws IOException {
+ try {
+ return curBuf.getInt();
+ } catch (BufferUnderflowException e) {
+ return super.readInt();
+ }
+ }
+
+ @Override
+ public long readLong() throws IOException {
+ try {
+ return curBuf.getLong();
+ } catch (BufferUnderflowException e) {
+ return super.readLong();
+ }
+ }
+
+ @Override
public long getFilePointer() {
return ((long) curBufIndex * maxBufSize) + curBuf.position();
}
@@ -375,7 +430,6 @@ public class MMapDirectory extends FSDir
curBuf = buffers[curBufIndex];
int bufOffset = (int) (pos - ((long) curBufIndex * maxBufSize));
curBuf.position(bufOffset);
- curAvail = bufSizes[curBufIndex] - bufOffset;
}
@Override