Small performance improvements

Modifications:

- Added a static modifier for CompositeByteBuf.Component.
This class is an inner class, but does not use its embedded reference to the object which created it. This reference makes the instances of the class larger, and may keep the reference to the creator object alive longer than necessary.
- Removed unnecessary boxing/unboxing operations in HttpResponseDecoder, RtspResponseDecoder, PerMessageDeflateClientExtensionHandshaker and PerMessageDeflateServerExtensionHandshaker
A boxed primitive is created from a String, just to extract the unboxed primitive value.
- Removed unnecessary 3 times calculations in DiskAttribute.addContent(...).
- Removed unnecessary checks if file exists before call mkdirs() in NativeLibraryLoader and PlatformDependent.
Because the method mkdirs() has this check inside.
- Removed unnecessary `instanceof AsciiString` check in StompSubframeAggregator.contentLength(StompHeadersSubframe) and StompSubframeDecoder.getContentLength(StompHeaders, long).
Because StompHeaders.get(CharSequence) always returns java.lang.String.
This commit is contained in:
Idel Pivnitskiy 2014-07-19 16:48:54 +04:00 committed by Norman Maurer
parent 7133a9a48f
commit dd26d47adc
10 changed files with 17 additions and 34 deletions

View File

@ -1319,7 +1319,7 @@ public class CompositeByteBuf extends AbstractReferenceCountedByteBuf {
return result + ", components=" + components.size() + ')'; return result + ", components=" + components.size() + ')';
} }
private final class Component { private static final class Component {
final ByteBuf buf; final ByteBuf buf;
final int length; final int length;
int offset; int offset;

View File

@ -110,7 +110,7 @@ public class HttpResponseDecoder extends HttpObjectDecoder {
protected HttpMessage createMessage(String[] initialLine) { protected HttpMessage createMessage(String[] initialLine) {
return new DefaultHttpResponse( return new DefaultHttpResponse(
HttpVersion.valueOf(initialLine[0]), HttpVersion.valueOf(initialLine[0]),
new HttpResponseStatus(Integer.valueOf(initialLine[1]), initialLine[2]), validateHeaders); new HttpResponseStatus(Integer.parseInt(initialLine[1]), initialLine[2]), validateHeaders);
} }
@Override @Override

View File

@ -83,13 +83,14 @@ public class DiskAttribute extends AbstractDiskHttpData implements Attribute {
@Override @Override
public void addContent(ByteBuf buffer, boolean last) throws IOException { public void addContent(ByteBuf buffer, boolean last) throws IOException {
int localsize = buffer.readableBytes(); final long newDefinedSize = size + buffer.readableBytes();
checkSize(size + localsize); checkSize(newDefinedSize);
if (definedSize > 0 && definedSize < size + localsize) { if (definedSize > 0 && definedSize < newDefinedSize) {
definedSize = size + localsize; definedSize = newDefinedSize;
} }
super.addContent(buffer, last); super.addContent(buffer, last);
} }
@Override @Override
public int hashCode() { public int hashCode() {
return getName().hashCode(); return getName().hashCode();

View File

@ -120,7 +120,7 @@ public final class PerMessageDeflateClientExtensionHandshaker implements WebSock
if (CLIENT_MAX_WINDOW.equalsIgnoreCase(parameter.getKey())) { if (CLIENT_MAX_WINDOW.equalsIgnoreCase(parameter.getKey())) {
// allowed client_window_size_bits // allowed client_window_size_bits
if (allowClientWindowSize) { if (allowClientWindowSize) {
clientWindowSize = Integer.valueOf(parameter.getValue()); clientWindowSize = Integer.parseInt(parameter.getValue());
} else { } else {
succeed = false; succeed = false;
} }

View File

@ -111,7 +111,7 @@ public final class PerMessageDeflateServerExtensionHandshaker implements WebSock
} else if (SERVER_MAX_WINDOW.equalsIgnoreCase(parameter.getKey())) { } else if (SERVER_MAX_WINDOW.equalsIgnoreCase(parameter.getKey())) {
// use provided windowSize if it is allowed // use provided windowSize if it is allowed
if (allowServerWindowSize) { if (allowServerWindowSize) {
serverWindowSize = Integer.valueOf(parameter.getValue()); serverWindowSize = Integer.parseInt(parameter.getValue());
if (serverWindowSize > MAX_WINDOW_SIZE || serverWindowSize < MIN_WINDOW_SIZE) { if (serverWindowSize > MAX_WINDOW_SIZE || serverWindowSize < MIN_WINDOW_SIZE) {
deflateEnabled = false; deflateEnabled = false;
} }

View File

@ -78,7 +78,7 @@ public class RtspResponseDecoder extends RtspObjectDecoder {
protected HttpMessage createMessage(String[] initialLine) throws Exception { protected HttpMessage createMessage(String[] initialLine) throws Exception {
return new DefaultHttpResponse( return new DefaultHttpResponse(
RtspVersions.valueOf(initialLine[0]), RtspVersions.valueOf(initialLine[0]),
new HttpResponseStatus(Integer.valueOf(initialLine[1]), initialLine[2]), validateHeaders); new HttpResponseStatus(Integer.parseInt(initialLine[1]), initialLine[2]), validateHeaders);
} }
@Override @Override

View File

@ -18,7 +18,6 @@ package io.netty.handler.codec.stomp;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandler; import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelPipeline; import io.netty.channel.ChannelPipeline;
import io.netty.handler.codec.AsciiString;
import io.netty.handler.codec.MessageAggregator; import io.netty.handler.codec.MessageAggregator;
import io.netty.handler.codec.TooLongFrameException; import io.netty.handler.codec.TooLongFrameException;
@ -70,12 +69,8 @@ public class StompSubframeAggregator
@Override @Override
protected long contentLength(StompHeadersSubframe start) throws Exception { protected long contentLength(StompHeadersSubframe start) throws Exception {
CharSequence value = start.headers().get(StompHeaders.CONTENT_LENGTH); String value = start.headers().get(StompHeaders.CONTENT_LENGTH);
if (value instanceof AsciiString) { return Long.parseLong(value);
return ((AsciiString) value).parseLong();
}
return Long.parseLong(value.toString());
} }
@Override @Override

View File

@ -18,7 +18,6 @@ package io.netty.handler.codec.stomp;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled; import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.AsciiString;
import io.netty.handler.codec.DecoderException; import io.netty.handler.codec.DecoderException;
import io.netty.handler.codec.DecoderResult; import io.netty.handler.codec.DecoderResult;
import io.netty.handler.codec.ReplayingDecoder; import io.netty.handler.codec.ReplayingDecoder;
@ -220,14 +219,10 @@ public class StompSubframeDecoder extends ReplayingDecoder<State> {
} }
private static long getContentLength(StompHeaders headers, long defaultValue) { private static long getContentLength(StompHeaders headers, long defaultValue) {
CharSequence contentLength = headers.get(StompHeaders.CONTENT_LENGTH); String contentLength = headers.get(StompHeaders.CONTENT_LENGTH);
if (contentLength != null) { if (contentLength != null) {
try { try {
if (contentLength instanceof AsciiString) { return Long.parseLong(contentLength);
return ((AsciiString) contentLength).parseLong();
} else {
return Long.parseLong(contentLength.toString());
}
} catch (NumberFormatException ignored) { } catch (NumberFormatException ignored) {
return defaultValue; return defaultValue;
} }

View File

@ -44,11 +44,7 @@ public final class NativeLibraryLoader {
String workdir = SystemPropertyUtil.get("io.netty.native.workdir"); String workdir = SystemPropertyUtil.get("io.netty.native.workdir");
if (workdir != null) { if (workdir != null) {
File f = new File(workdir); File f = new File(workdir);
if (!f.exists()) { f.mkdirs();
// ok to ignore as createTempFile will take care
//noinspection ResultOfMethodCallIgnored
f.mkdirs();
}
try { try {
f = f.getAbsoluteFile(); f = f.getAbsoluteFile();
@ -130,9 +126,7 @@ public final class NativeLibraryLoader {
} }
File f = new File(path); File f = new File(path);
if (!f.exists()) { f.mkdirs();
f.mkdirs();
}
if (!f.isDirectory()) { if (!f.isDirectory()) {
return null; return null;

View File

@ -759,9 +759,7 @@ public final class PlatformDependent {
} }
File f = new File(path); File f = new File(path);
if (!f.exists()) { f.mkdirs();
f.mkdirs();
}
if (!f.isDirectory()) { if (!f.isDirectory()) {
return null; return null;