You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-commits@lucene.apache.org by mi...@apache.org on 2008/01/10 19:22:42 UTC
svn commit: r610861 -
/lucene/java/branches/lucene_2_3/src/java/org/apache/lucene/index/DocumentsWriter.java
Author: mikemccand
Date: Thu Jan 10 10:22:41 2008
New Revision: 610861
URL: http://svn.apache.org/viewvc?rev=610861&view=rev
Log:
LUCENE-1125 on 2.3 branch: fix over-zero-filling that was drastically slowing down small docs w/ term vectors
Modified:
lucene/java/branches/lucene_2_3/src/java/org/apache/lucene/index/DocumentsWriter.java
Modified: lucene/java/branches/lucene_2_3/src/java/org/apache/lucene/index/DocumentsWriter.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/lucene_2_3/src/java/org/apache/lucene/index/DocumentsWriter.java?rev=610861&r1=610860&r2=610861&view=diff
==============================================================================
--- lucene/java/branches/lucene_2_3/src/java/org/apache/lucene/index/DocumentsWriter.java (original)
+++ lucene/java/branches/lucene_2_3/src/java/org/apache/lucene/index/DocumentsWriter.java Thu Jan 10 10:22:41 2008
@@ -2768,10 +2768,26 @@
public int byteOffset = -BYTE_BLOCK_SIZE; // Current head offset
public void reset() {
- recycleByteBlocks(buffers, 1+bufferUpto);
- bufferUpto = -1;
- byteUpto = BYTE_BLOCK_SIZE;
- byteOffset = -BYTE_BLOCK_SIZE;
+ if (bufferUpto != -1) {
+ // We allocated at least one buffer
+
+ for(int i=0;i<bufferUpto;i++)
+ // Fully zero fill buffers that we fully used
+ Arrays.fill(buffers[i], (byte) 0);
+
+ // Partial zero fill the final buffer
+ Arrays.fill(buffers[bufferUpto], 0, byteUpto, (byte) 0);
+
+ if (bufferUpto > 0)
+ // Recycle all but the first buffer
+ recycleByteBlocks(buffers, 1, 1+bufferUpto);
+
+ // Re-use the first buffer
+ bufferUpto = 0;
+ byteUpto = 0;
+ byteOffset = 0;
+ buffer = buffers[0];
+ }
}
public void nextBuffer() {
@@ -2782,7 +2798,6 @@
buffers = newBuffers;
}
buffer = buffers[bufferUpto] = getByteBlock();
- Arrays.fill(buffer, (byte) 0);
byteUpto = 0;
byteOffset += BYTE_BLOCK_SIZE;
@@ -2954,10 +2969,10 @@
}
/* Return a byte[] to the pool */
- synchronized void recycleByteBlocks(byte[][] blocks, int numBlocks) {
- for(int i=0;i<numBlocks;i++)
+ synchronized void recycleByteBlocks(byte[][] blocks, int start, int end) {
+ for(int i=start;i<end;i++)
freeByteBlocks.add(blocks[i]);
- numBytesUsed -= numBlocks * BYTE_BLOCK_SIZE;
+ numBytesUsed -= (end-start) * BYTE_BLOCK_SIZE;
}
/* Initial chunk size of the shared char[] blocks used to