minor gc optimization: better DefaultSpdyHeaders.iterator()
This commit is contained in:
parent
ff6a06a9be
commit
b5f5175338
@ -15,11 +15,14 @@
|
|||||||
*/
|
*/
|
||||||
package io.netty.handler.codec.spdy;
|
package io.netty.handler.codec.spdy;
|
||||||
|
|
||||||
|
import java.util.Iterator;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.NoSuchElementException;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.TreeSet;
|
import java.util.TreeSet;
|
||||||
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
|
|
||||||
public class DefaultSpdyHeaders extends SpdyHeaders {
|
public class DefaultSpdyHeaders extends SpdyHeaders {
|
||||||
@ -249,6 +252,11 @@ public class DefaultSpdyHeaders extends SpdyHeaders {
|
|||||||
return all;
|
return all;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Iterator<Map.Entry<String, String>> iterator() {
|
||||||
|
return new HeaderIterator();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean contains(String name) {
|
public boolean contains(String name) {
|
||||||
return get(name) != null;
|
return get(name) != null;
|
||||||
@ -281,7 +289,7 @@ public class DefaultSpdyHeaders extends SpdyHeaders {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isEmpty() {
|
public boolean isEmpty() {
|
||||||
return entries().isEmpty();
|
return head == head.after;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String toString(Object value) {
|
private static String toString(Object value) {
|
||||||
@ -291,6 +299,32 @@ public class DefaultSpdyHeaders extends SpdyHeaders {
|
|||||||
return value.toString();
|
return value.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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 static final class HeaderEntry implements Map.Entry<String, String> {
|
private static final class HeaderEntry implements Map.Entry<String, String> {
|
||||||
final int hash;
|
final int hash;
|
||||||
final String key;
|
final String key;
|
||||||
|
@ -98,7 +98,7 @@ public class DefaultSpdyHeadersFrame extends DefaultSpdyStreamFrame
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected void appendHeaders(StringBuilder buf) {
|
protected void appendHeaders(StringBuilder buf) {
|
||||||
for (Map.Entry<String, String> e: headers().entries()) {
|
for (Map.Entry<String, String> e: headers()) {
|
||||||
buf.append(" ");
|
buf.append(" ");
|
||||||
buf.append(e.getKey());
|
buf.append(e.getKey());
|
||||||
buf.append(": ");
|
buf.append(": ");
|
||||||
|
@ -242,7 +242,7 @@ public class SpdyHttpDecoder extends MessageToMessageDecoder<SpdyFrame> {
|
|||||||
|
|
||||||
// Ignore trailers in a truncated HEADERS frame.
|
// Ignore trailers in a truncated HEADERS frame.
|
||||||
if (!spdyHeadersFrame.isTruncated()) {
|
if (!spdyHeadersFrame.isTruncated()) {
|
||||||
for (Map.Entry<String, String> e: spdyHeadersFrame.headers().entries()) {
|
for (Map.Entry<String, String> e: spdyHeadersFrame.headers()) {
|
||||||
fullHttpMessage.headers().add(e.getKey(), e.getValue());
|
fullHttpMessage.headers().add(e.getKey(), e.getValue());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -311,7 +311,7 @@ public class SpdyHttpDecoder extends MessageToMessageDecoder<SpdyFrame> {
|
|||||||
HttpHeaders.setHost(req, host);
|
HttpHeaders.setHost(req, host);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (Map.Entry<String, String> e: requestFrame.headers().entries()) {
|
for (Map.Entry<String, String> e: requestFrame.headers()) {
|
||||||
req.headers().add(e.getKey(), e.getValue());
|
req.headers().add(e.getKey(), e.getValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -333,7 +333,7 @@ public class SpdyHttpDecoder extends MessageToMessageDecoder<SpdyFrame> {
|
|||||||
SpdyHeaders.removeVersion(spdyVersion, responseFrame);
|
SpdyHeaders.removeVersion(spdyVersion, responseFrame);
|
||||||
|
|
||||||
FullHttpResponse res = new DefaultFullHttpResponse(version, status);
|
FullHttpResponse res = new DefaultFullHttpResponse(version, status);
|
||||||
for (Map.Entry<String, String> e: responseFrame.headers().entries()) {
|
for (Map.Entry<String, String> e: responseFrame.headers()) {
|
||||||
res.headers().add(e.getKey(), e.getValue());
|
res.headers().add(e.getKey(), e.getValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -89,7 +89,7 @@ public class SpdySessionHandlerTest {
|
|||||||
assertTrue(receivedValues.isEmpty());
|
assertTrue(receivedValues.isEmpty());
|
||||||
spdyHeadersFrame.headers().remove(name);
|
spdyHeadersFrame.headers().remove(name);
|
||||||
}
|
}
|
||||||
assertTrue(spdyHeadersFrame.headers().entries().isEmpty());
|
assertTrue(spdyHeadersFrame.headers().isEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void testSpdySessionHandler(int version, boolean server) {
|
private static void testSpdySessionHandler(int version, boolean server) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user