Skip to content

Commit

Permalink
[SHRINKWRAP-429] Remove some unnecessary memory copy
Browse files Browse the repository at this point in the history
  • Loading branch information
Norman Maurer authored and ALRubinger committed Oct 17, 2012
1 parent 5decc5c commit 4a93d5a
Showing 1 changed file with 1 addition and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ public int read(final ByteBuffer destination) throws IOException {
// Init
final int spaceInBuffer = destination.remaining();
final int numBytesRemainingInContent, numBytesToRead;
final byte[] bytesToCopy;

// Sync up before getting at shared mutable state
synchronized (this) {
Expand All @@ -112,18 +111,13 @@ public int read(final ByteBuffer destination) throws IOException {
// We'll read in either the number of bytes remaining in content or the amount of space in the buffer,
// whichever is smaller
numBytesToRead = numBytesRemainingInContent >= spaceInBuffer ? spaceInBuffer : numBytesRemainingInContent;

// Copy a sub-array of the bytes we'll put into the buffer
bytesToCopy = new byte[numBytesToRead];
System.arraycopy(this.contents, this.position, bytesToCopy, 0, numBytesToRead);
destination.put(this.contents, this.position, numBytesToRead);

// Set the new position
this.position += numBytesToRead;
}

// Put the contents into the buffer
destination.put(bytesToCopy);

// Return the number of bytes read
return numBytesToRead;
}
Expand Down

0 comments on commit 4a93d5a

Please sign in to comment.