lucene-java-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mikemcc...@apache.org
Subject svn commit: r929738 - in /lucene/dev/trunk/lucene/src: java/org/apache/lucene/index/ByteBlockPool.java java/org/apache/lucene/index/DocumentsWriter.java test/org/apache/lucene/index/TestByteSlices.java
Date Wed, 31 Mar 2010 22:43:05 GMT
Author: mikemccand
Date: Wed Mar 31 22:43:04 2010
New Revision: 929738

URL: http://svn.apache.org/viewvc?rev=929738&view=rev
Log:
LUCENE-2360: don't use .toArray to recycle byte[] blocks used by doc stores

Modified:
    lucene/dev/trunk/lucene/src/java/org/apache/lucene/index/ByteBlockPool.java
    lucene/dev/trunk/lucene/src/java/org/apache/lucene/index/DocumentsWriter.java
    lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestByteSlices.java

Modified: lucene/dev/trunk/lucene/src/java/org/apache/lucene/index/ByteBlockPool.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/java/org/apache/lucene/index/ByteBlockPool.java?rev=929738&r1=929737&r2=929738&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/java/org/apache/lucene/index/ByteBlockPool.java (original)
+++ lucene/dev/trunk/lucene/src/java/org/apache/lucene/index/ByteBlockPool.java Wed Mar 31
22:43:04 2010
@@ -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);
   }
 

Modified: lucene/dev/trunk/lucene/src/java/org/apache/lucene/index/DocumentsWriter.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/java/org/apache/lucene/index/DocumentsWriter.java?rev=929738&r1=929737&r2=929738&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/java/org/apache/lucene/index/DocumentsWriter.java (original)
+++ lucene/dev/trunk/lucene/src/java/org/apache/lucene/index/DocumentsWriter.java Wed Mar
31 22:43:04 2010
@@ -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

Modified: lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestByteSlices.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestByteSlices.java?rev=929738&r1=929737&r2=929738&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestByteSlices.java (original)
+++ lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestByteSlices.java Wed Mar 31
22:43:04 2010
@@ -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 Luce
       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 {



Mime
View raw message