You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by mi...@apache.org on 2012/03/14 22:50:35 UTC

svn commit: r1300744 - /lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/util/PagedBytes.java

Author: mikemccand
Date: Wed Mar 14 21:50:35 2012
New Revision: 1300744

URL: http://svn.apache.org/viewvc?rev=1300744&view=rev
Log:
LUCENE-3841: restore fillSliceWithPrefix's ability to span 2 blocks

Modified:
    lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/util/PagedBytes.java

Modified: lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/util/PagedBytes.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/util/PagedBytes.java?rev=1300744&r1=1300743&r2=1300744&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/util/PagedBytes.java (original)
+++ lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/util/PagedBytes.java Wed Mar 14 21:50:35 2012
@@ -207,12 +207,26 @@ public final class PagedBytes {
       }
       assert length >= 0: "length=" + length;
       b.length = length;
-      // We always alloc a new block when writing w/ prefix;
+
+      // NOTE: even though copyUsingLengthPrefix always
+      // allocs a new block if the byte[] to be added won't
+      // fit in current block,
+      // VarDerefBytesImpl.finishInternal does its own
+      // prefix + byte[] writing which can span two blocks,
+      // so we support that here on decode:
       // we could some day relax that and span two blocks:
-      assert blockSize - offset >= length;
-      // Within block
-      b.offset = offset;
-      b.bytes = blocks[index];
+      
+      if (blockSize - offset >= length) {
+        // Within block
+        b.offset = offset;
+        b.bytes = blocks[index];
+      } else {
+        // Split
+        b.bytes = new byte[length];
+        b.offset = 0;
+        System.arraycopy(blocks[index], offset, b.bytes, 0, blockSize-offset);
+        System.arraycopy(blocks[1+index], 0, b.bytes, blockSize-offset, length-(blockSize-offset));
+      }
       return b;
     }