From 963376990927b1169304ccad7546168a74d012bf Mon Sep 17 00:00:00 2001 From: alain Date: Fri, 28 Jun 2013 15:57:26 -0700 Subject: [PATCH] Improve performance of encodeHeader --- .../io/netty/handler/codec/http/HttpObjectEncoder.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/codec-http/src/main/java/io/netty/handler/codec/http/HttpObjectEncoder.java b/codec-http/src/main/java/io/netty/handler/codec/http/HttpObjectEncoder.java index 970db26f9e..98b6c9dafe 100644 --- a/codec-http/src/main/java/io/netty/handler/codec/http/HttpObjectEncoder.java +++ b/codec-http/src/main/java/io/netty/handler/codec/http/HttpObjectEncoder.java @@ -125,11 +125,17 @@ public abstract class HttpObjectEncoder extends MessageTo } private static void encodeHeader(ByteBuf buf, String header, String value) { - buf.writeBytes(header.getBytes(CharsetUtil.US_ASCII)); + encodeAscii(header, buf); buf.writeBytes(HEADER_SEPARATOR); - buf.writeBytes(value.getBytes(CharsetUtil.US_ASCII)); + encodeAscii(value, buf); buf.writeBytes(CRLF); } + private static void encodeAscii(String s, ByteBuf buf) { + for (int i = 0; i < s.length(); i++) { + buf.writeByte(s.charAt(i)); + } + } + protected abstract void encodeInitialLine(ByteBuf buf, H message) throws Exception; }