dubbo-hessian-lite
dubbo-hessian-lite copied to clipboard
put a length param into this createList method so that the collection will not resize
this class: com.alibaba.com.caucho.hessian.io.CollectionDeserializer.class
CollectionDeserializer.readLengthList.createList()
you can put a length param into this createList method and initialize the collection with length so that the collection will not resize it will avoid the resize of the collection and save cpu resources
before:
private Collection createList()
throws IOException {
Collection list = null;
if (_type == null)
list = new ArrayList();
else if (!_type.isInterface()) {
try {
list = (Collection) _type.newInstance();
} catch (Exception e) {
}
}
if (list != null) {
} else if (SortedSet.class.isAssignableFrom(_type))
list = new TreeSet();
else if (Set.class.isAssignableFrom(_type))
list = new HashSet();
else if (List.class.isAssignableFrom(_type))
list = new ArrayList();
else if (Collection.class.isAssignableFrom(_type))
list = new ArrayList();
else {
try {
list = (Collection) _type.newInstance();
} catch (Exception e) {
throw new IOExceptionWrapper(e);
}
}
return list;
}
after:
private Collection createList(int length)
throws IOException {
Collection list = null;
if (_type == null)
list = new ArrayList();
else if (!_type.isInterface()) {
try {
list = (Collection) _type.newInstance();
} catch (Exception e) {
}
}
if (list != null) {
} else if (SortedSet.class.isAssignableFrom(_type))
list = new TreeSet(length);
else if (Set.class.isAssignableFrom(_type))
list = new HashSet(length);
else if (List.class.isAssignableFrom(_type))
list = new ArrayList(length);
else if (Collection.class.isAssignableFrom(_type))
list = new ArrayList(length);
else {
try {
list = (Collection) _type.newInstance();
} catch (Exception e) {
throw new IOExceptionWrapper(e);
}
}
return list;
}