Skip to content

Commit

Permalink
doh! friday afternoon
Browse files Browse the repository at this point in the history
  • Loading branch information
iverase committed Oct 13, 2023
1 parent 0ac0028 commit 074ccad
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -185,9 +185,7 @@ static BytesReference fromByteArray(ByteArray byteArray, int length) {
/**
* Returns a BytesRefIterator for this BytesReference. This method allows
* access to the internal pages of this reference without copying them.
* It must return direct references to the pages, not copies. If the object
* does not hold internal pages, then it mush return Use with care!
*
* It must return direct references to the pages, not copies. Use with care!
*
* @see BytesRefIterator
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,20 +61,16 @@ public BytesRefIterator iterator() {
final byte[] buffer = new byte[Math.min(length, PageCacheRecycler.BYTE_PAGE_SIZE)];
return new BytesRefIterator() {
int remaining = length;
BytesRef current;

@Override
public BytesRef next() {
if (current != null) {
if (IntStream.range(0, current.bytes.length).map(i -> current.bytes[i]).anyMatch(b -> b != 0)) {
throw new AssertionError("Internal pages from ZeroBytesReference must be zero");
}
if (IntStream.range(0, buffer.length).map(i -> buffer[i]).anyMatch(b -> b != 0)) {
throw new AssertionError("Internal pages from ZeroBytesReference must be zero");
}
if (remaining > 0) {
final int nextLength = Math.min(remaining, buffer.length);
remaining -= nextLength;
current = new BytesRef(buffer, 0, nextLength);
return current;
return new BytesRef(buffer, 0, nextLength);
} else {
return null;
}
Expand Down

0 comments on commit 074ccad

Please sign in to comment.