dungba88 commented on code in PR #12778: URL: https://github.com/apache/lucene/pull/12778#discussion_r1384749437
########## lucene/core/src/java/org/apache/lucene/util/ByteBlockPool.java: ########## @@ -234,6 +234,44 @@ public void append(final BytesRef bytes) { append(bytes.bytes, bytes.offset, bytes.length); } + /** + * Append the bytes from a source {@link ByteBlockPool} at a given offset and length + * + * @param srcPool the source pool to copy from + * @param offset the source pool offset + * @param length the number of bytes to copy + */ + public void append(ByteBlockPool srcPool, long offset, int length) { + int bytesLeft = length; + while (bytesLeft > 0) { + int bufferLeft = BYTE_BLOCK_SIZE - byteUpto; + if (bytesLeft < bufferLeft) { // fits within current buffer + copyBytes(srcPool, offset, bytesLeft); + break; + } else { // fill up this buffer and move to next one + if (bufferLeft > 0) { + copyBytes(srcPool, offset, bufferLeft); + bytesLeft -= bufferLeft; + offset += bufferLeft; + } + nextBuffer(); + } + } + } + + // copy from source pool until no bytes left. length must be fit within the current head buffer + private void copyBytes(ByteBlockPool srcPool, long offset, int length) { + while (length > 0) { Review Comment: Thank you, I have incorporated the comment into the new rev -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org For additional commands, e-mail: issues-h...@lucene.apache.org