Implemented buffer pooling.
This commit is contained in:
parent
194dcb7bc9
commit
c2abdfb2e2
|
@ -19,6 +19,7 @@ package org.eclipse.jetty.spdy;
|
|||
import java.nio.ByteBuffer;
|
||||
import java.util.Queue;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
|
||||
public class StandardByteBufferPool implements ByteBufferPool
|
||||
|
@ -61,21 +62,21 @@ public class StandardByteBufferPool implements ByteBufferPool
|
|||
|
||||
public void release(ByteBuffer buffer)
|
||||
{
|
||||
// int bucket = bucketFor(buffer.capacity());
|
||||
// ConcurrentMap<Integer, Queue<ByteBuffer>> buffers = buffersFor(buffer.isDirect());
|
||||
//
|
||||
// // Avoid to create a new queue every time, just to be discarded immediately
|
||||
// Queue<ByteBuffer> byteBuffers = buffers.get(bucket);
|
||||
// if (byteBuffers == null)
|
||||
// {
|
||||
// byteBuffers = new ConcurrentLinkedQueue<>();
|
||||
// Queue<ByteBuffer> existing = buffers.putIfAbsent(bucket, byteBuffers);
|
||||
// if (existing != null)
|
||||
// byteBuffers = existing;
|
||||
// }
|
||||
//
|
||||
// buffer.clear();
|
||||
// byteBuffers.offer(buffer);
|
||||
int bucket = bucketFor(buffer.capacity());
|
||||
ConcurrentMap<Integer, Queue<ByteBuffer>> buffers = buffersFor(buffer.isDirect());
|
||||
|
||||
// Avoid to create a new queue every time, just to be discarded immediately
|
||||
Queue<ByteBuffer> byteBuffers = buffers.get(bucket);
|
||||
if (byteBuffers == null)
|
||||
{
|
||||
byteBuffers = new ConcurrentLinkedQueue<>();
|
||||
Queue<ByteBuffer> existing = buffers.putIfAbsent(bucket, byteBuffers);
|
||||
if (existing != null)
|
||||
byteBuffers = existing;
|
||||
}
|
||||
|
||||
buffer.clear();
|
||||
byteBuffers.offer(buffer);
|
||||
}
|
||||
|
||||
public void clear()
|
||||
|
|
Loading…
Reference in New Issue