Hibernate version: SVN Revision 14993
Name and version of the database you are using: MySQL 5.0.24
In the method readFrom in the class PersistentList every time an element is added, the for loop responsible for the padding adds a null element and this null-element is then replaced with the actual element. In the case when the List loaded with Hibernate hasn't any holes and needs no padding there are List.size() unnecessary calls of List.add(). Couldn't that be optimized?
Code:
public Object readFrom(ResultSet rs, CollectionPersister persister, CollectionAliases descriptor, Object owner)
throws HibernateException, SQLException {
Object element = persister.readElement( rs, owner, descriptor.getSuffixedElementAliases(), getSession() ) ;
int index = ( (Integer) persister.readIndex( rs, descriptor.getSuffixedIndexAliases(), getSession() ) ).intValue();
//pad with nulls from the current last element up to the new index
for ( int i = list.size(); i<=index; i++) {
list.add(i, null);
}
list.set(index, element);
return element;
}
Optimized portion of code:
Code:
//pad with nulls from the current last element up to the new index
for ( int i = list.size(); i<index; i++) {
list.add(i, null);
}
list.set(index, element);
By replacing the <= with < only the gaps are filled and the position of the elements are not filled with nulls before replacing them.