mirror of
https://github.com/hibernate/hibernate-orm
synced 2025-02-18 17:15:02 +00:00
HHH-13675 : Optimize PersistentBag.groupByEqualityHash()
This commit is contained in:
parent
1c840f9dd1
commit
3b1e7afb20
@ -11,11 +11,12 @@
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.ListIterator;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.hibernate.HibernateException;
|
||||
import org.hibernate.engine.spi.SessionImplementor;
|
||||
@ -193,7 +194,14 @@ public boolean equalsSnapshot(CollectionPersister persister) throws HibernateExc
|
||||
* @return Map of "equality" hashCode to List of objects
|
||||
*/
|
||||
private Map<Integer, List<Object>> groupByEqualityHash(List<Object> searchedBag, Type elementType) {
|
||||
return searchedBag.stream().collect( Collectors.groupingBy( elementType::getHashCode ) );
|
||||
if ( searchedBag.isEmpty() ) {
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
Map<Integer, List<Object>> map = new HashMap<>();
|
||||
for (Object o : searchedBag) {
|
||||
map.computeIfAbsent( elementType.getHashCode( o ), k -> new ArrayList<>() ).add( o );
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Loading…
x
Reference in New Issue
Block a user