Skip to content

Commit

Permalink
core, api, benchmarks: Random acts of garbage reduction
Browse files Browse the repository at this point in the history
I noticed some opportunities to reduce allocations on hot paths
  • Loading branch information
njhill committed Aug 28, 2020
1 parent ab6d9bd commit 7491f36
Showing 1 changed file with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -144,12 +144,15 @@ public void readBytes(final OutputStream dest, int length) throws IOException {

@Override
public ReadableBuffer readBytes(int length) {
if (length <= 0) {
return ReadableBuffers.empty();
}
checkReadable(length);
readableBytes -= length;

ReadableBuffer newBuffer = null;
CompositeReadableBuffer newComposite = null;
while (length > 0) {
do {
ReadableBuffer buffer = buffers.peek();
int readable = buffer.readableBytes();
ReadableBuffer readBuffer;
Expand All @@ -171,8 +174,8 @@ public ReadableBuffer readBytes(int length) {
}
newComposite.addBuffer(readBuffer);
}
}
return newBuffer != null ? newBuffer : ReadableBuffers.empty();
} while (length > 0);
return newBuffer;
}

@Override
Expand Down

0 comments on commit 7491f36

Please sign in to comment.