Skip to content

Commit

Permalink
Reduce the initial capacity of the value list from 4 to 2
Browse files Browse the repository at this point in the history
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
  • Loading branch information
trustin committed Aug 12, 2014
1 parent 2d36caa commit de72406
Showing 1 changed file with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@

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) {
Expand Down Expand Up @@ -617,7 +618,7 @@ public List<CharSequence> getAllUnconverted(CharSequence name) {
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];
Expand All @@ -638,7 +639,7 @@ public List<String> getAll(CharSequence name) {
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];
Expand All @@ -665,7 +666,7 @@ public List<String> getAllAndRemove(CharSequence name) {
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());
Expand Down Expand Up @@ -714,7 +715,7 @@ public List<CharSequence> getAllUnconvertedAndRemove(CharSequence name) {
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());
Expand Down

0 comments on commit de72406

Please sign in to comment.