mirror of https://github.com/apache/lucene.git
fix bytesref problems in readBytes, just take byte[],int,int
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/branches/lucene4547@1441543 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
040ca47778
commit
00f66bf975
|
@ -112,7 +112,9 @@ class BinaryDocValuesWriter extends DocValuesWriter {
|
|||
}
|
||||
if (upto < size) {
|
||||
int length = (int) lengthsIterator.next();
|
||||
pool.readBytes(value, byteOffset, length);
|
||||
value.grow(length);
|
||||
value.length = length;
|
||||
pool.readBytes(byteOffset, value.bytes, value.offset, value.length);
|
||||
byteOffset += length;
|
||||
} else {
|
||||
// This is to handle last N documents not having
|
||||
|
|
|
@ -327,32 +327,29 @@ public final class ByteBlockPool {
|
|||
|
||||
/**
|
||||
* Reads bytes bytes out of the pool starting at the given offset with the given
|
||||
* length into the given {@link BytesRef} at offset <tt>0</tt>.
|
||||
* length into the given byte array at offset <tt>off</tt>.
|
||||
* <p>Note: this method allows to copy across block boundaries.</p>
|
||||
*/
|
||||
public void readBytes(final BytesRef bytes, final long offset, final int length) {
|
||||
bytes.offset = 0;
|
||||
bytes.grow(length);
|
||||
bytes.length = length;
|
||||
public void readBytes(final long offset, final byte bytes[], final int off, final int length) {
|
||||
if (length == 0) {
|
||||
return;
|
||||
}
|
||||
int bytesOffset = off;
|
||||
int bytesLength = length;
|
||||
int bufferIndex = (int) (offset >> BYTE_BLOCK_SHIFT);
|
||||
byte[] buffer = buffers[bufferIndex];
|
||||
int pos = (int) (offset & BYTE_BLOCK_MASK);
|
||||
int overflow = (pos + length) - BYTE_BLOCK_SIZE;
|
||||
do {
|
||||
if (overflow <= 0) {
|
||||
System.arraycopy(buffer, pos, bytes.bytes, bytes.offset, bytes.length);
|
||||
bytes.length = length;
|
||||
bytes.offset = 0;
|
||||
System.arraycopy(buffer, pos, bytes, bytesOffset, bytesLength);
|
||||
break;
|
||||
} else {
|
||||
final int bytesToCopy = length - overflow;
|
||||
System.arraycopy(buffer, pos, bytes.bytes, bytes.offset, bytesToCopy);
|
||||
System.arraycopy(buffer, pos, bytes, bytesOffset, bytesToCopy);
|
||||
pos = 0;
|
||||
bytes.length -= bytesToCopy;
|
||||
bytes.offset += bytesToCopy;
|
||||
bytesLength -= bytesToCopy;
|
||||
bytesOffset += bytesToCopy;
|
||||
buffer = buffers[++bufferIndex];
|
||||
overflow = overflow - BYTE_BLOCK_SIZE;
|
||||
}
|
||||
|
|
|
@ -43,7 +43,9 @@ public class TestByteBlockPool extends LuceneTestCase {
|
|||
// verify
|
||||
long position = 0;
|
||||
for (BytesRef expected : list) {
|
||||
pool.readBytes(ref, position, expected.length);
|
||||
ref.grow(expected.length);
|
||||
ref.length = expected.length;
|
||||
pool.readBytes(position, ref.bytes, ref.offset, ref.length);
|
||||
assertEquals(expected, ref);
|
||||
position += ref.length;
|
||||
}
|
||||
|
|
|
@ -104,7 +104,10 @@ public final class BytesRefArray {
|
|||
int offset = offsets[ord];
|
||||
int length = ord == lastElement - 1 ? currentOffset - offset
|
||||
: offsets[ord + 1] - offset;
|
||||
pool.readBytes(spare, offset, length);
|
||||
assert spare.offset == 0;
|
||||
spare.grow(length);
|
||||
spare.length = length;
|
||||
pool.readBytes(offset, spare.bytes, spare.offset, spare.length);
|
||||
return spare;
|
||||
}
|
||||
throw new IndexOutOfBoundsException("index " + ord
|
||||
|
|
Loading…
Reference in New Issue