Avoid unnecessary string conversion where possible

Motivation:

HttpResponseStaus, HttpMethod and HttpVersion have methods that return
AsciiString.  There's no need for object-to-string conversion.

Modifications:

Use codeAsText(), name(), text() instead of setInt() and setObject()

Result:

Efficiency
This commit is contained in:
Trustin Lee 2015-01-11 12:45:49 +09:00
parent edb93a6fcc
commit fbc0ce4784

View File

@ -216,9 +216,9 @@ public class SpdyHttpEncoder extends MessageToMessageEncoder<HttpObject> {
// Unfold the first line of the message into name/value pairs
SpdyHeaders frameHeaders = spdySynStreamFrame.headers();
frameHeaders.setObject(SpdyHeaders.HttpNames.METHOD, httpRequest.method());
frameHeaders.set(SpdyHeaders.HttpNames.METHOD, httpRequest.method().name());
frameHeaders.set(SpdyHeaders.HttpNames.PATH, httpRequest.uri());
frameHeaders.setObject(SpdyHeaders.HttpNames.VERSION, httpRequest.protocolVersion());
frameHeaders.set(SpdyHeaders.HttpNames.VERSION, httpRequest.protocolVersion().text());
// Replace the HTTP host header with the SPDY host header
CharSequence host = httpHeaders.get(HttpHeaderNames.HOST);
@ -267,8 +267,8 @@ public class SpdyHttpEncoder extends MessageToMessageEncoder<HttpObject> {
}
SpdyHeaders frameHeaders = spdyHeadersFrame.headers();
// Unfold the first line of the response into name/value pairs
frameHeaders.setInt(SpdyHeaders.HttpNames.STATUS, httpResponse.status().code());
frameHeaders.setObject(SpdyHeaders.HttpNames.VERSION, httpResponse.protocolVersion());
frameHeaders.set(SpdyHeaders.HttpNames.STATUS, httpResponse.status().codeAsText());
frameHeaders.set(SpdyHeaders.HttpNames.VERSION, httpResponse.protocolVersion().text());
// Transfer the remaining HTTP headers
for (Map.Entry<String, String> entry: httpHeaders) {