-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Unnecessary List-method calls in PersistentList.readFrom
PostPosted: Thu Dec 04, 2008 5:59 am 
Newbie

Joined: Thu Dec 04, 2008 5:21 am
Posts: 1
Location: Saarbrücken, Germany
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.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.