From 9ba942e59bd8f1917be2e32336e5fe95485f8c39 Mon Sep 17 00:00:00 2001 From: Carl Mastrangelo Date: Fri, 26 Jan 2018 15:48:24 -0800 Subject: [PATCH] Swap header check in ReadOnlyHttp2Headers Motivation: Pseudo headers are checked less frequently than normal headers, so it is more efficient to check the latter first. Modifications: Swap the order of the check, and fix minor formatting Result: Possibly more efficient header checks --- .../io/netty/handler/codec/http2/DefaultHttp2Headers.java | 2 +- .../io/netty/handler/codec/http2/ReadOnlyHttp2Headers.java | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/codec-http2/src/main/java/io/netty/handler/codec/http2/DefaultHttp2Headers.java b/codec-http2/src/main/java/io/netty/handler/codec/http2/DefaultHttp2Headers.java index 42d783c409..1d2cc7dd6f 100644 --- a/codec-http2/src/main/java/io/netty/handler/codec/http2/DefaultHttp2Headers.java +++ b/codec-http2/src/main/java/io/netty/handler/codec/http2/DefaultHttp2Headers.java @@ -185,7 +185,7 @@ public class DefaultHttp2Headers @Override public boolean contains(CharSequence name, CharSequence value, boolean caseInsensitive) { - return contains(name, value, caseInsensitive? CASE_INSENSITIVE_HASHER : CASE_SENSITIVE_HASHER); + return contains(name, value, caseInsensitive ? CASE_INSENSITIVE_HASHER : CASE_SENSITIVE_HASHER); } @Override diff --git a/codec-http2/src/main/java/io/netty/handler/codec/http2/ReadOnlyHttp2Headers.java b/codec-http2/src/main/java/io/netty/handler/codec/http2/ReadOnlyHttp2Headers.java index ce9ce7ae65..e5bae06a2b 100644 --- a/codec-http2/src/main/java/io/netty/handler/codec/http2/ReadOnlyHttp2Headers.java +++ b/codec-http2/src/main/java/io/netty/handler/codec/http2/ReadOnlyHttp2Headers.java @@ -774,11 +774,12 @@ public final class ReadOnlyHttp2Headers implements Http2Headers { @Override public boolean contains(CharSequence name, CharSequence value, boolean caseInsensitive) { final int nameHash = AsciiString.hashCode(name); - final HashingStrategy strategy = caseInsensitive? CASE_INSENSITIVE_HASHER : CASE_SENSITIVE_HASHER; + final HashingStrategy strategy = + caseInsensitive ? CASE_INSENSITIVE_HASHER : CASE_SENSITIVE_HASHER; final int valueHash = strategy.hashCode(value); - return contains(name, nameHash, value, valueHash, strategy, pseudoHeaders) - || contains(name, nameHash, value, valueHash, strategy, otherHeaders); + return contains(name, nameHash, value, valueHash, strategy, otherHeaders) + || contains(name, nameHash, value, valueHash, strategy, pseudoHeaders); } private static boolean contains(CharSequence name, int nameHash, CharSequence value, int valueHash,