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:
parent
2d36caa9f6
commit
de724063f3
@ -39,6 +39,7 @@ import java.util.TimeZone;
|
|||||||
|
|
||||||
public class DefaultTextHeaders implements TextHeaders {
|
public class DefaultTextHeaders implements TextHeaders {
|
||||||
|
|
||||||
|
private static final int INITIAL_VALUELIST_CAPACITY = 2;
|
||||||
private static final int BUCKET_SIZE = 17;
|
private static final int BUCKET_SIZE = 17;
|
||||||
|
|
||||||
private static int index(int hash) {
|
private static int index(int hash) {
|
||||||
@ -617,7 +618,7 @@ public class DefaultTextHeaders implements TextHeaders {
|
|||||||
throw new NullPointerException("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 h = hashCode(name);
|
||||||
int i = index(h);
|
int i = index(h);
|
||||||
HeaderEntry e = entries[i];
|
HeaderEntry e = entries[i];
|
||||||
@ -638,7 +639,7 @@ public class DefaultTextHeaders implements TextHeaders {
|
|||||||
throw new NullPointerException("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 h = hashCode(name);
|
||||||
int i = index(h);
|
int i = index(h);
|
||||||
HeaderEntry e = entries[i];
|
HeaderEntry e = entries[i];
|
||||||
@ -665,7 +666,7 @@ public class DefaultTextHeaders implements TextHeaders {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
List<String> values = new ArrayList<String>(4);
|
List<String> values = new ArrayList<String>(INITIAL_VALUELIST_CAPACITY);
|
||||||
for (;;) {
|
for (;;) {
|
||||||
if (e.hash == h && nameEquals(e.name, name)) {
|
if (e.hash == h && nameEquals(e.name, name)) {
|
||||||
values.add(e.getValue().toString());
|
values.add(e.getValue().toString());
|
||||||
@ -714,7 +715,7 @@ public class DefaultTextHeaders implements TextHeaders {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
List<CharSequence> values = new ArrayList<CharSequence>(4);
|
List<CharSequence> values = new ArrayList<CharSequence>(INITIAL_VALUELIST_CAPACITY);
|
||||||
for (;;) {
|
for (;;) {
|
||||||
if (e.hash == h && nameEquals(e.name, name)) {
|
if (e.hash == h && nameEquals(e.name, name)) {
|
||||||
values.add(e.getValue());
|
values.add(e.getValue());
|
||||||
|
Loading…
Reference in New Issue
Block a user