Return singleton from getAll if header doesn't exist. (#9836)
Motivation: It is more efficient to avoid allocating objects when we don't need to. Modification: Don't allocate a `LinkedList` for returning an empty list of header values when the header doesn't exist at all. Result: Less allocations
This commit is contained in:
parent
82e5ca7e7f
commit
9f5970a91a
@ -155,17 +155,22 @@ public class DefaultHeaders<K, V, T extends Headers<K, V, T>> implements Headers
|
||||
public List<V> getAll(K name) {
|
||||
requireNonNull(name, "name");
|
||||
|
||||
LinkedList<V> values = new LinkedList<>();
|
||||
|
||||
int h = hashingStrategy.hashCode(name);
|
||||
int i = index(h);
|
||||
HeaderEntry<K, V> e = entries[i];
|
||||
while (e != null) {
|
||||
|
||||
if (e == null) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
LinkedList<V> values = new LinkedList<>();
|
||||
|
||||
do {
|
||||
if (e.hash == h && hashingStrategy.equals(name, e.key)) {
|
||||
values.addFirst(e.getValue());
|
||||
}
|
||||
e = e.next;
|
||||
}
|
||||
} while (e != null);
|
||||
return values;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user