Reduce the initial capacity of the value list from 4 to 2

Motivation:

DefaultTextHeaders.getAll*() methods create an ArrayList whose initial
capacity is 4.  However, it is more likely that the actual number of
values is smaller than that.

Modifications:

Reduce the initial capacity of the value list from 4 to 2

Result:

Slightly reduced memory footprint
This commit is contained in:
Trustin Lee 2014-08-12 10:36:13 -07:00
parent 2d36caa9f6
commit de724063f3

View File

@ -39,6 +39,7 @@ import java.util.TimeZone;
public class DefaultTextHeaders implements TextHeaders {
private static final int INITIAL_VALUELIST_CAPACITY = 2;
private static final int BUCKET_SIZE = 17;
private static int index(int hash) {
@ -617,7 +618,7 @@ public class DefaultTextHeaders implements TextHeaders {
throw new NullPointerException("name");
}
List<CharSequence> values = new ArrayList<CharSequence>(4);
List<CharSequence> values = new ArrayList<CharSequence>(INITIAL_VALUELIST_CAPACITY);
int h = hashCode(name);
int i = index(h);
HeaderEntry e = entries[i];
@ -638,7 +639,7 @@ public class DefaultTextHeaders implements TextHeaders {
throw new NullPointerException("name");
}
List<String> values = new ArrayList<String>(4);
List<String> values = new ArrayList<String>(INITIAL_VALUELIST_CAPACITY);
int h = hashCode(name);
int i = index(h);
HeaderEntry e = entries[i];
@ -665,7 +666,7 @@ public class DefaultTextHeaders implements TextHeaders {
return null;
}
List<String> values = new ArrayList<String>(4);
List<String> values = new ArrayList<String>(INITIAL_VALUELIST_CAPACITY);
for (;;) {
if (e.hash == h && nameEquals(e.name, name)) {
values.add(e.getValue().toString());
@ -714,7 +715,7 @@ public class DefaultTextHeaders implements TextHeaders {
return null;
}
List<CharSequence> values = new ArrayList<CharSequence>(4);
List<CharSequence> values = new ArrayList<CharSequence>(INITIAL_VALUELIST_CAPACITY);
for (;;) {
if (e.hash == h && nameEquals(e.name, name)) {
values.add(e.getValue());