From c48c2387aee2c0c4240df6e340b615026da409a0 Mon Sep 17 00:00:00 2001 From: Willie Scholtz Date: Sat, 9 Mar 2024 10:14:06 +0100 Subject: [PATCH] #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 --- .../executor/resultset/PendingConstructorCreation.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/apache/ibatis/executor/resultset/PendingConstructorCreation.java b/src/main/java/org/apache/ibatis/executor/resultset/PendingConstructorCreation.java index 03cbc21397e..14703a04960 100644 --- a/src/main/java/org/apache/ibatis/executor/resultset/PendingConstructorCreation.java +++ b/src/main/java/org/apache/ibatis/executor/resultset/PendingConstructorCreation.java @@ -44,9 +44,11 @@ final class PendingConstructorCreation { private final Map> linkedCreationsByResultMapId; PendingConstructorCreation(Class resultType, List> types, List args) { - this.linkedCollectionMetaInfo = new HashMap<>(); - this.linkedCollectionsByResultMapId = new HashMap<>(); - this.linkedCreationsByResultMapId = new HashMap<>(); + // since all our keys are based on result map id, we know we will never go over args size + final int maxSize = types.size(); + this.linkedCollectionMetaInfo = new HashMap<>(maxSize); + this.linkedCollectionsByResultMapId = new HashMap<>(maxSize); + this.linkedCreationsByResultMapId = new HashMap<>(maxSize); this.resultType = resultType; this.constructorArgTypes = types; this.constructorArgs = args; @@ -67,7 +69,7 @@ Collection initializeCollectionForResultMapping(ObjectFactory objectFact linkedCollectionMetaInfo.put(index, new PendingCreationMetaInfo(resultMap.getType(), resultMapId)); // will be checked before we finally create the object) as we cannot reliably do that here - return (Collection) objectFactory.create(constructorMapping.getJavaType()); + return (Collection) objectFactory.create(parameterType); }); }