Headers remove infrequently used member variables

Motivation:
There are two member variables (addAllVisitor, setAllVisitor) which are likely not to be used in the majority of use cases.

Modifications:
Remove these member variables and rely on a method to return a new object when needed.

Result:
Two less member variables for each DefaultHeaders instance.
This commit is contained in:
Scott Mitchell 2015-01-21 15:10:07 -05:00
parent 27a2017f7f
commit c4a5c3966c

View File

@ -90,8 +90,6 @@ public class DefaultHeaders<T> implements Headers<T> {
private final ValueConverter<T> valueConverter;
private final NameConverter<T> nameConverter;
private final int bucketSize;
private EntryVisitor<T> setAllVisitor;
private EntryVisitor<T> addAllVisitor;
int size;
@SuppressWarnings("unchecked")
@ -1307,12 +1305,8 @@ public class DefaultHeaders<T> implements Headers<T> {
return removed;
}
/**
* Lazy initialization of the visitor which will set all headers.
*/
private EntryVisitor<T> setAllVisitor() {
if (setAllVisitor == null) {
setAllVisitor = new EntryVisitor<T>() {
return new EntryVisitor<T>() {
@Override
public boolean visit(Entry<T, T> entry) {
set(entry.getKey(), entry.getValue());
@ -1320,15 +1314,9 @@ public class DefaultHeaders<T> implements Headers<T> {
}
};
}
return setAllVisitor;
}
/**
* Lazy initialization of the visitor which will add all headers.
*/
private EntryVisitor<T> addAllVisitor() {
if (addAllVisitor == null) {
addAllVisitor = new EntryVisitor<T>() {
return new EntryVisitor<T>() {
@Override
public boolean visit(Entry<T, T> entry) {
add(entry.getKey(), entry.getValue());
@ -1336,8 +1324,6 @@ public class DefaultHeaders<T> implements Headers<T> {
}
};
}
return addAllVisitor;
}
private final class HeaderEntry implements Map.Entry<T, T> {
final int hash;