Skip to content

Commit 3b1e7af

Browse files
dreis2211Sanne
authored andcommitted
HHH-13675 : Optimize PersistentBag.groupByEqualityHash()
1 parent 1c840f9 commit 3b1e7af

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

hibernate-core/src/main/java/org/hibernate/collection/internal/PersistentBag.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,12 @@
1111
import java.sql.SQLException;
1212
import java.util.ArrayList;
1313
import java.util.Collection;
14+
import java.util.Collections;
15+
import java.util.HashMap;
1416
import java.util.Iterator;
1517
import java.util.List;
1618
import java.util.ListIterator;
1719
import java.util.Map;
18-
import java.util.stream.Collectors;
1920

2021
import org.hibernate.HibernateException;
2122
import org.hibernate.engine.spi.SessionImplementor;
@@ -193,7 +194,14 @@ public boolean equalsSnapshot(CollectionPersister persister) throws HibernateExc
193194
* @return Map of "equality" hashCode to List of objects
194195
*/
195196
private Map<Integer, List<Object>> groupByEqualityHash(List<Object> searchedBag, Type elementType) {
196-
return searchedBag.stream().collect( Collectors.groupingBy( elementType::getHashCode ) );
197+
if ( searchedBag.isEmpty() ) {
198+
return Collections.emptyMap();
199+
}
200+
Map<Integer, List<Object>> map = new HashMap<>();
201+
for (Object o : searchedBag) {
202+
map.computeIfAbsent( elementType.getHashCode( o ), k -> new ArrayList<>() ).add( o );
203+
}
204+
return map;
197205
}
198206

199207
@Override

0 commit comments

Comments
 (0)