justdoit1995 opened a new issue, #59:
URL: https://github.com/apache/dubbo-hessian-lite/issues/59
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;
}
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]