minor gc optimization: better DefaultHttpHeaders.iterator()
This commit is contained in:
parent
c9b7f1f1b5
commit
1542b36e80
@ -22,6 +22,8 @@ import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.Set;
|
||||
import java.util.TreeSet;
|
||||
|
||||
@ -268,7 +270,7 @@ public class DefaultHttpHeaders extends HttpHeaders {
|
||||
|
||||
@Override
|
||||
public Iterator<Map.Entry<String, String>> iterator() {
|
||||
return entries().iterator();
|
||||
return new HeaderIterator();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -313,7 +315,33 @@ public class DefaultHttpHeaders extends HttpHeaders {
|
||||
return value.toString();
|
||||
}
|
||||
|
||||
private static final class HeaderEntry implements Map.Entry<String, String> {
|
||||
private final class HeaderIterator implements Iterator<Map.Entry<String, String>> {
|
||||
|
||||
private HeaderEntry current = head;
|
||||
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
return current.after != head;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Entry<String, String> next() {
|
||||
current = current.after;
|
||||
|
||||
if (current == head) {
|
||||
throw new NoSuchElementException();
|
||||
}
|
||||
|
||||
return current;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
|
||||
private final class HeaderEntry implements Map.Entry<String, String> {
|
||||
final int hash;
|
||||
final String key;
|
||||
String value;
|
||||
|
@ -177,7 +177,7 @@ public class SpdyHttpEncoder extends MessageToMessageEncoder<HttpObject> {
|
||||
spdyDataFrame.setLast(chunk instanceof LastHttpContent);
|
||||
if (chunk instanceof LastHttpContent) {
|
||||
LastHttpContent trailer = (LastHttpContent) chunk;
|
||||
List<Map.Entry<String, String>> trailers = trailer.trailingHeaders().entries();
|
||||
HttpHeaders trailers = trailer.trailingHeaders();
|
||||
if (trailers.isEmpty()) {
|
||||
out.add(spdyDataFrame);
|
||||
} else {
|
||||
|
@ -71,9 +71,9 @@ public class HttpSnoopServerHandler extends SimpleChannelInboundHandler<Object>
|
||||
buf.append("HOSTNAME: ").append(getHost(request, "unknown")).append("\r\n");
|
||||
buf.append("REQUEST_URI: ").append(request.getUri()).append("\r\n\r\n");
|
||||
|
||||
List<Map.Entry<String, String>> headers = request.headers().entries();
|
||||
HttpHeaders headers = request.headers();
|
||||
if (!headers.isEmpty()) {
|
||||
for (Map.Entry<String, String> h: request.headers().entries()) {
|
||||
for (Map.Entry<String, String> h: headers) {
|
||||
String key = h.getKey();
|
||||
String value = h.getValue();
|
||||
buf.append("HEADER: ").append(key).append(" = ").append(value).append("\r\n");
|
||||
|
@ -114,8 +114,7 @@ public class HttpUploadServerHandler extends SimpleChannelInboundHandler<HttpObj
|
||||
responseContent.append("\r\n\r\n");
|
||||
|
||||
// new getMethod
|
||||
List<Entry<String, String>> headers = request.headers().entries();
|
||||
for (Entry<String, String> entry : headers) {
|
||||
for (Entry<String, String> entry : request.headers()) {
|
||||
responseContent.append("HEADER: " + entry.getKey() + '=' + entry.getValue() + "\r\n");
|
||||
}
|
||||
responseContent.append("\r\n\r\n");
|
||||
|
Loading…
Reference in New Issue
Block a user