LUCENE-430: Delay allocation of the buffer after a clone of BufferedIndexInput.

git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@541402 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Michael Busch 2007-05-24 19:42:47 +00:00
parent 45f760ea24
commit 393b4525db
2 changed files with 11 additions and 5 deletions

View File

@ -181,6 +181,10 @@ Optimizations
4. LUCENE-882: Spellchecker doesn't store the ngrams anymore but only indexes 4. LUCENE-882: Spellchecker doesn't store the ngrams anymore but only indexes
them to keep the spell index small. (Daniel Naber) them to keep the spell index small. (Daniel Naber)
5. LUCENE-430: Delay allocation of the buffer after a clone of BufferedIndexInput.
Together with LUCENE-888 this will allow to adjust the buffer size
dynamically. (Paul Elschot, Michael Busch)
Documentation Documentation
1. LUCENE 791 && INFRA-1173: Infrastructure moved the Wiki to 1. LUCENE 791 && INFRA-1173: Infrastructure moved the Wiki to

View File

@ -88,8 +88,10 @@ public abstract class BufferedIndexInput extends IndexInput {
if (bufferLength <= 0) if (bufferLength <= 0)
throw new IOException("read past EOF"); throw new IOException("read past EOF");
if (buffer == null) if (buffer == null) {
buffer = new byte[BUFFER_SIZE]; // allocate buffer lazily buffer = new byte[BUFFER_SIZE]; // allocate buffer lazily
seekInternal(bufferStart);
}
readInternal(buffer, 0, bufferLength); readInternal(buffer, 0, bufferLength);
bufferStart = start; bufferStart = start;
@ -127,10 +129,10 @@ public abstract class BufferedIndexInput extends IndexInput {
public Object clone() { public Object clone() {
BufferedIndexInput clone = (BufferedIndexInput)super.clone(); BufferedIndexInput clone = (BufferedIndexInput)super.clone();
if (buffer != null) { clone.buffer = null;
clone.buffer = new byte[BUFFER_SIZE]; clone.bufferLength = 0;
System.arraycopy(buffer, 0, clone.buffer, 0, bufferLength); clone.bufferPosition = 0;
} clone.bufferStart = getFilePointer();
return clone; return clone;
} }