Skip to content

Commit

Permalink
Merge pull request #101 from cmoen/master
Browse files Browse the repository at this point in the history
Prevent an array copy if it can be provided by the buffer itself
  • Loading branch information
cmoen committed Apr 5, 2016
2 parents 6136d48 + da4da50 commit e609d4f
Showing 1 changed file with 4 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,10 @@ private static int[] readArrayFromChannel(ReadableByteChannel channel) throws IO
tmpBuffer.rewind();
IntBuffer intBuffer = tmpBuffer.asIntBuffer();

if (intBuffer.hasArray() && !intBuffer.isReadOnly()) {
return intBuffer.array();
}

int[] array = new int[length];
intBuffer.get(array);
return array;
Expand Down

0 comments on commit e609d4f

Please sign in to comment.