Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Better copy(..) implementation. See #62

  • Loading branch information...
commit af4358c2a5e98fcd767981306ac17f4b8bc3e1f7 1 parent c4b61bc
@normanmaurer normanmaurer authored
Showing with 4 additions and 15 deletions.
  1. +4 −15 buffer/src/main/java/io/netty/buffer/pool/SlabChannelBuffer.java
View
19 buffer/src/main/java/io/netty/buffer/pool/SlabChannelBuffer.java
@@ -26,13 +26,11 @@
import java.util.List;
import io.netty.buffer.AbstractChannelBuffer;
-import io.netty.buffer.BigEndianHeapChannelBuffer;
import io.netty.buffer.ChannelBuffer;
import io.netty.buffer.ChannelBufferFactory;
import io.netty.buffer.ChannelBufferUtil;
import io.netty.buffer.ChannelBuffers;
import io.netty.buffer.HeapChannelBufferFactory;
-import io.netty.buffer.LittleEndianHeapChannelBuffer;
import io.netty.buffer.SlicedChannelBuffer;
import io.netty.buffer.TruncatedChannelBuffer;
@@ -501,20 +499,11 @@ public int setBytes(int index, ScatteringByteChannel in, int length) throws IOEx
@Override
public ChannelBuffer copy(int index, int length) {
checkIndexInBounds(index, length);
+
+ ChannelBuffer dst = factory().getBuffer(order(), length);
+ getBytes(index, dst);
-
- byte[] copiedArray = new byte[length];
- getBytes(index, copiedArray);
-
- // TODO: Should we use Channels static methods here ?
- if (order() == ByteOrder.BIG_ENDIAN) {
- return new BigEndianHeapChannelBuffer(copiedArray);
- } else if (order() == ByteOrder.LITTLE_ENDIAN) {
- return new LittleEndianHeapChannelBuffer(copiedArray);
- } else {
- // This should never happen!
- throw new RuntimeException("Unkown ByteOrder");
- }
+ return dst;
}
Please sign in to comment.
Something went wrong with that request. Please try again.