mirror of https://github.com/apache/lucene.git
LUCENE-9059: Reduce garbage created by ByteBuffersDataOutput. (#1031)
This commit is contained in:
parent
4ad3902137
commit
f76f4eaff8
|
@ -21,7 +21,7 @@ import java.io.UncheckedIOException;
|
|||
import java.nio.ByteBuffer;
|
||||
import java.util.ArrayDeque;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
@ -279,11 +279,13 @@ public final class ByteBuffersDataOutput extends DataOutput implements Accountab
|
|||
* Copy the current content of this object into another {@link DataOutput}.
|
||||
*/
|
||||
public void copyTo(DataOutput output) throws IOException {
|
||||
for (ByteBuffer bb : toBufferList()) {
|
||||
for (ByteBuffer bb : blocks) {
|
||||
if (bb.hasArray()) {
|
||||
output.writeBytes(bb.array(), bb.arrayOffset() + bb.position(), bb.remaining());
|
||||
output.writeBytes(bb.array(), bb.arrayOffset(), bb.position());
|
||||
} else {
|
||||
output.copyBytes(new ByteBuffersDataInput(Arrays.asList(bb)), bb.remaining());
|
||||
bb = bb.asReadOnlyBuffer();
|
||||
bb.flip();
|
||||
output.copyBytes(new ByteBuffersDataInput(Collections.singletonList(bb)), bb.remaining());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -412,7 +414,9 @@ public final class ByteBuffersDataOutput extends DataOutput implements Accountab
|
|||
* lead to hard-to-debug issues, use with great care.
|
||||
*/
|
||||
public void reset() {
|
||||
blocks.stream().forEach(blockReuse);
|
||||
if (blockReuse != NO_REUSE) {
|
||||
blocks.forEach(blockReuse);
|
||||
}
|
||||
blocks.clear();
|
||||
currentBlock = EMPTY;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue