22
22
import java .lang .reflect .Constructor ;
23
23
import java .util .ArrayList ;
24
24
import java .util .List ;
25
+ import java .util .Map ;
25
26
import java .util .function .Function ;
27
+ import java .util .stream .Collectors ;
26
28
import java .util .stream .IntStream ;
27
29
28
30
import org .springframework .data .mapping .InstanceCreatorMetadata ;
40
42
* constructor argument extraction.
41
43
*
42
44
* @author Mark Paluch
45
+ * @author Yohan Lee
43
46
* @since 3.1
44
47
*/
45
48
class KotlinInstantiationDelegate {
46
49
47
50
private final KFunction <?> constructor ;
48
51
private final List <KParameter > kParameters ;
52
+ private final Map <KParameter , Integer > indexByKParameter ;
49
53
private final List <Function <Object , Object >> wrappers = new ArrayList <>();
50
54
private final Constructor <?> constructorToInvoke ;
51
55
private final boolean hasDefaultConstructorMarker ;
@@ -62,6 +66,8 @@ public KotlinInstantiationDelegate(PreferredConstructor<?, ?> preferredConstruct
62
66
63
67
this .constructor = kotlinConstructor ;
64
68
this .kParameters = kotlinConstructor .getParameters ();
69
+ this .indexByKParameter = IntStream .range (0 , kParameters .size ()).boxed ()
70
+ .collect (Collectors .toMap (kParameters ::get , Function .identity ()));
65
71
this .constructorToInvoke = constructorToInvoke ;
66
72
this .hasDefaultConstructorMarker = hasDefaultConstructorMarker (constructorToInvoke .getParameters ());
67
73
@@ -118,7 +124,7 @@ public <P extends PersistentProperty<P>> Object[] extractInvocationArguments(Obj
118
124
119
125
KotlinDefaultMask defaultMask = KotlinDefaultMask .forConstructor (constructor , it -> {
120
126
121
- int index = kParameters . indexOf (it );
127
+ int index = indexByKParameter . get (it );
122
128
123
129
Parameter <Object , P > parameter = parameters .get (index );
124
130
Class <Object > type = parameter .getType ().getType ();
0 commit comments