File tree Expand file tree Collapse file tree 1 file changed +7
-3
lines changed
spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/support Expand file tree Collapse file tree 1 file changed +7
-3
lines changed Original file line number Diff line number Diff line change @@ -84,7 +84,7 @@ public <S extends T> List<S> save(Iterable<S> entities) {
84
84
85
85
Assert .notNull (entities , "The given Iterable of entities not be null!" );
86
86
87
- List <S > result = new ArrayList <S >();
87
+ List <S > result = new ArrayList <S >(tryDetermineRealSizeOrReturn ( entities , 10 ) );
88
88
89
89
for (S entity : entities ) {
90
90
save (entity );
@@ -183,7 +183,7 @@ public List<T> findAll() {
183
183
*/
184
184
public Iterable <T > findAll (Iterable <ID > ids ) {
185
185
186
- Set <ID > parameters = new HashSet <ID >();
186
+ Set <ID > parameters = new HashSet <ID >(tryDetermineRealSizeOrReturn ( ids , 10 ) );
187
187
for (ID id : ids ) {
188
188
parameters .add (id );
189
189
}
@@ -272,7 +272,7 @@ private <S extends T> List<S> convertIterableToList(Iterable<S> entities) {
272
272
return (List <S >) entities ;
273
273
}
274
274
275
- int capacity = (entities instanceof Collection ) ? (( Collection <?>) entities ). size () : 10 ;
275
+ int capacity = tryDetermineRealSizeOrReturn (entities , 10 ) ;
276
276
277
277
if (capacity == 0 || entities == null ) {
278
278
return Collections .<S > emptyList ();
@@ -285,4 +285,8 @@ private <S extends T> List<S> convertIterableToList(Iterable<S> entities) {
285
285
286
286
return list ;
287
287
}
288
+
289
+ private int tryDetermineRealSizeOrReturn (Iterable <?> iterable , int defaultSize ) {
290
+ return iterable == null ? 0 : (iterable instanceof Collection ) ? ((Collection <?>) iterable ).size () : defaultSize ;
291
+ }
288
292
}
You can’t perform that action at this time.
0 commit comments