Skip to content

Commit c48c238

Browse files
committed
mybatis#101: Specify max size for pending creations
Theoretically, if all of our types are nested mappings, a resize would occur, however we will almost always not have this due to an idArg being necessary, and allocating the default of 16 elements is too much
1 parent 05527aa commit c48c238

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/main/java/org/apache/ibatis/executor/resultset/PendingConstructorCreation.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,11 @@ final class PendingConstructorCreation {
4444
private final Map<String, List<PendingConstructorCreation>> linkedCreationsByResultMapId;
4545

4646
PendingConstructorCreation(Class<?> resultType, List<Class<?>> types, List<Object> args) {
47-
this.linkedCollectionMetaInfo = new HashMap<>();
48-
this.linkedCollectionsByResultMapId = new HashMap<>();
49-
this.linkedCreationsByResultMapId = new HashMap<>();
47+
// since all our keys are based on result map id, we know we will never go over args size
48+
final int maxSize = types.size();
49+
this.linkedCollectionMetaInfo = new HashMap<>(maxSize);
50+
this.linkedCollectionsByResultMapId = new HashMap<>(maxSize);
51+
this.linkedCreationsByResultMapId = new HashMap<>(maxSize);
5052
this.resultType = resultType;
5153
this.constructorArgTypes = types;
5254
this.constructorArgs = args;
@@ -67,7 +69,7 @@ Collection<Object> initializeCollectionForResultMapping(ObjectFactory objectFact
6769
linkedCollectionMetaInfo.put(index, new PendingCreationMetaInfo(resultMap.getType(), resultMapId));
6870

6971
// will be checked before we finally create the object) as we cannot reliably do that here
70-
return (Collection<Object>) objectFactory.create(constructorMapping.getJavaType());
72+
return (Collection<Object>) objectFactory.create(parameterType);
7173
});
7274
}
7375

0 commit comments

Comments
 (0)