LUCENE-3841: restore fillSliceWithPrefix's ability to span 2 blocks

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1300744 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Michael McCandless 2012-03-14 21:50:35 +00:00
parent 8bcbd04454
commit 24bce3e8b7
1 changed files with 19 additions and 5 deletions

View File

@ -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;
}