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
This commit is contained in:
Carl Mastrangelo 2018-01-26 15:48:24 -08:00
parent e975c5f6fe
commit 9ba942e59b
2 changed files with 5 additions and 4 deletions

View File

@ -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

View File

@ -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<CharSequence> strategy = caseInsensitive? CASE_INSENSITIVE_HASHER : CASE_SENSITIVE_HASHER;
final HashingStrategy<CharSequence> 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,