Make the code more compact. See #480

This commit is contained in:
norman 2012-07-30 14:29:50 +02:00
parent 947a12555a
commit c28e3c7300

View File

@ -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) {