DATACMNS-1101 - Replace ArrayList indirections in ReflectionEntityInstantiator/PreferredConstructor.
Iterate over simple ArrayList and construct array of params instead of copying elements between multiple Lists.
This commit is contained in:
committed by
Oliver Gierke
parent
b2ce4b8f1b
commit
6495a50df7
@@ -16,9 +16,8 @@
|
||||
package org.springframework.data.convert;
|
||||
|
||||
import java.lang.reflect.Array;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.beans.BeanInstantiationException;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
@@ -66,17 +65,16 @@ public enum ReflectionEntityInstantiator implements EntityInstantiator {
|
||||
}
|
||||
}
|
||||
|
||||
List<Object> params = new ArrayList<>();
|
||||
if (null != provider && constructor.hasParameters()) {
|
||||
for (Parameter<?, P> parameter : constructor.getParameters()) {
|
||||
params.add(provider.getParameterValue(parameter));
|
||||
}
|
||||
Object[] params = new Object[constructor.getConstructor().getParameterCount()];
|
||||
int i = 0;
|
||||
for (Parameter<?, P> parameter : constructor.getParameters()) {
|
||||
params[i++] = provider.getParameterValue(parameter);
|
||||
}
|
||||
|
||||
try {
|
||||
return BeanUtils.instantiateClass(constructor.getConstructor(), params.toArray());
|
||||
return BeanUtils.instantiateClass(constructor.getConstructor(), params);
|
||||
} catch (BeanInstantiationException e) {
|
||||
throw new MappingInstantiationException(entity, params, e);
|
||||
throw new MappingInstantiationException(entity, Arrays.asList(params), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,7 +29,6 @@ import java.util.concurrent.locks.ReentrantReadWriteLock;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.data.annotation.PersistenceConstructor;
|
||||
import org.springframework.data.util.Lazy;
|
||||
import org.springframework.data.util.Streamable;
|
||||
import org.springframework.data.util.TypeInformation;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ReflectionUtils;
|
||||
@@ -85,8 +84,8 @@ public class PreferredConstructor<T, P extends PersistentProperty<P>> {
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public Streamable<Parameter<Object, P>> getParameters() {
|
||||
return Streamable.of(parameters);
|
||||
public List<Parameter<Object, P>> getParameters() {
|
||||
return parameters;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user