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

@ -180,6 +180,10 @@ Optimizations
4. LUCENE-882: Spellchecker doesn't store the ngrams anymore but only indexes
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

View File

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