mirror of https://github.com/apache/lucene.git
LUCENE-2360: don't use .toArray to recycle byte[] blocks used by doc stores
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@929738 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
f3ba962a5e
commit
a528a707c1
|
@ -34,6 +34,7 @@ package org.apache.lucene.index;
|
|||
* hit a non-zero byte. */
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import static org.apache.lucene.util.RamUsageEstimator.NUM_BYTES_OBJECT_REF;
|
||||
import org.apache.lucene.util.ArrayUtil;
|
||||
|
||||
|
@ -42,6 +43,7 @@ final class ByteBlockPool {
|
|||
|
||||
abstract static class Allocator {
|
||||
abstract void recycleByteBlocks(byte[][] blocks, int start, int end);
|
||||
abstract void recycleByteBlocks(List<byte[]> blocks);
|
||||
abstract byte[] getByteBlock(boolean trackAllocations);
|
||||
}
|
||||
|
||||
|
|
|
@ -207,8 +207,7 @@ final class DocumentsWriter {
|
|||
// Recycle the blocks
|
||||
final int blockCount = buffers.size();
|
||||
|
||||
final byte[][] blocks = buffers.toArray( new byte[blockCount][] );
|
||||
perDocAllocator.recycleByteBlocks(blocks, 0, blockCount);
|
||||
perDocAllocator.recycleByteBlocks(buffers);
|
||||
buffers.clear();
|
||||
sizeInBytes = 0;
|
||||
|
||||
|
@ -1285,6 +1284,15 @@ final class DocumentsWriter {
|
|||
freeByteBlocks.add(blocks[i]);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
void recycleByteBlocks(List<byte[]> blocks) {
|
||||
synchronized(DocumentsWriter.this) {
|
||||
final int size = blocks.size();
|
||||
for(int i=0;i<size;i++)
|
||||
freeByteBlocks.add(blocks.get(i));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Initial chunks size of the shared int[] blocks used to
|
||||
|
|
|
@ -16,6 +16,7 @@ package org.apache.lucene.index;
|
|||
|
||||
import java.util.Random;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import org.apache.lucene.util.LuceneTestCase;
|
||||
|
||||
public class TestByteSlices extends LuceneTestCase {
|
||||
|
@ -41,6 +42,13 @@ public class TestByteSlices extends LuceneTestCase {
|
|||
for(int i=start;i<end;i++)
|
||||
freeByteBlocks.add(blocks[i]);
|
||||
}
|
||||
|
||||
@Override
|
||||
synchronized void recycleByteBlocks(List<byte[]> blocks) {
|
||||
final int size = blocks.size();
|
||||
for(int i=0;i<size;i++)
|
||||
freeByteBlocks.add(blocks.get(i));
|
||||
}
|
||||
}
|
||||
|
||||
public void testBasic() throws Throwable {
|
||||
|
|
Loading…
Reference in New Issue