Make the code more compact. See #480
This commit is contained in:
parent
947a12555a
commit
c28e3c7300
@ -38,12 +38,12 @@ final class SocketReceiveBufferAllocator {
|
|||||||
|
|
||||||
ByteBuffer get(int size) {
|
ByteBuffer get(int size) {
|
||||||
if (buf == null) {
|
if (buf == null) {
|
||||||
buf = newBuffer(size);
|
return newBuffer(size);
|
||||||
} else if (buf.capacity() < size) {
|
} else if (buf.capacity() < size) {
|
||||||
buf = newBuffer(size);
|
return newBuffer(size);
|
||||||
} else if (((buf.capacity() / 100) * percentual) > size) {
|
} else if (((buf.capacity() / 100) * percentual) > size) {
|
||||||
if (++exceedCount == maxExceedCount) {
|
if (++exceedCount == maxExceedCount) {
|
||||||
buf = newBuffer(size);
|
return newBuffer(size);
|
||||||
} else {
|
} else {
|
||||||
buf.clear();
|
buf.clear();
|
||||||
}
|
}
|
||||||
@ -59,7 +59,8 @@ final class SocketReceiveBufferAllocator {
|
|||||||
exceedCount = 0;
|
exceedCount = 0;
|
||||||
ByteBufferUtil.destroy(buf);
|
ByteBufferUtil.destroy(buf);
|
||||||
}
|
}
|
||||||
return ByteBuffer.allocateDirect(normalizeCapacity(size));
|
buf = ByteBuffer.allocateDirect(normalizeCapacity(size));
|
||||||
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int normalizeCapacity(int capacity) {
|
private static int normalizeCapacity(int capacity) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user