mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
优化XXXToMapCopier的部分性能(pr#1345@Gitee)
This commit is contained in:
@@ -16,10 +16,8 @@ import java.util.Map;
|
|||||||
@SuppressWarnings("rawtypes")
|
@SuppressWarnings("rawtypes")
|
||||||
public class BeanToMapCopier extends AbsCopier<Object, Map> {
|
public class BeanToMapCopier extends AbsCopier<Object, Map> {
|
||||||
|
|
||||||
/**
|
// 提前获取目标值真实类型
|
||||||
* 目标的Map类型(用于泛型类注入)
|
private final Type[] targetTypeArguments;
|
||||||
*/
|
|
||||||
private final Type targetType;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 构造
|
* 构造
|
||||||
@@ -31,7 +29,7 @@ public class BeanToMapCopier extends AbsCopier<Object, Map> {
|
|||||||
*/
|
*/
|
||||||
public BeanToMapCopier(Object source, Map target, Type targetType, CopyOptions copyOptions) {
|
public BeanToMapCopier(Object source, Map target, Type targetType, CopyOptions copyOptions) {
|
||||||
super(source, target, copyOptions);
|
super(source, target, copyOptions);
|
||||||
this.targetType = targetType;
|
this.targetTypeArguments = TypeUtil.getTypeArguments(targetType);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -44,9 +42,6 @@ public class BeanToMapCopier extends AbsCopier<Object, Map> {
|
|||||||
actualEditable = copyOptions.editable;
|
actualEditable = copyOptions.editable;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 提前获取目标值真实类型
|
|
||||||
final Type[] earlyDetectTypeArguments = TypeUtil.getTypeArguments(this.targetType);
|
|
||||||
|
|
||||||
final Map<String, PropDesc> sourcePropDescMap = BeanUtil.getBeanDesc(actualEditable).getPropMap(copyOptions.ignoreCase);
|
final Map<String, PropDesc> sourcePropDescMap = BeanUtil.getBeanDesc(actualEditable).getPropMap(copyOptions.ignoreCase);
|
||||||
sourcePropDescMap.forEach((sFieldName, sDesc) -> {
|
sourcePropDescMap.forEach((sFieldName, sDesc) -> {
|
||||||
if (null == sFieldName || false == sDesc.isReadable(copyOptions.transientSupport)) {
|
if (null == sFieldName || false == sDesc.isReadable(copyOptions.transientSupport)) {
|
||||||
@@ -72,9 +67,9 @@ public class BeanToMapCopier extends AbsCopier<Object, Map> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 尝试转换源值
|
// 尝试转换源值
|
||||||
if(null != earlyDetectTypeArguments && earlyDetectTypeArguments.length > 1){
|
if(null != targetTypeArguments && targetTypeArguments.length > 1){
|
||||||
//sValue = Convert.convertWithCheck(typeArguments[1], sValue, null, this.copyOptions.ignoreError);
|
//sValue = Convert.convertWithCheck(typeArguments[1], sValue, null, this.copyOptions.ignoreError);
|
||||||
sValue = this.copyOptions.convertField(earlyDetectTypeArguments[1], sValue);
|
sValue = this.copyOptions.convertField(targetTypeArguments[1], sValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 自定义值
|
// 自定义值
|
||||||
|
@@ -13,10 +13,8 @@ import java.util.Map;
|
|||||||
@SuppressWarnings({"rawtypes", "unchecked"})
|
@SuppressWarnings({"rawtypes", "unchecked"})
|
||||||
public class MapToMapCopier extends AbsCopier<Map, Map> {
|
public class MapToMapCopier extends AbsCopier<Map, Map> {
|
||||||
|
|
||||||
/**
|
// 提前获取目标值真实类型
|
||||||
* 目标的类型(用于泛型类注入)
|
private final Type[] targetTypeArguments;
|
||||||
*/
|
|
||||||
private final Type targetType;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 构造
|
* 构造
|
||||||
@@ -28,15 +26,11 @@ public class MapToMapCopier extends AbsCopier<Map, Map> {
|
|||||||
*/
|
*/
|
||||||
public MapToMapCopier(Map source, Map target, Type targetType, CopyOptions copyOptions) {
|
public MapToMapCopier(Map source, Map target, Type targetType, CopyOptions copyOptions) {
|
||||||
super(source, target, copyOptions);
|
super(source, target, copyOptions);
|
||||||
this.targetType = targetType;
|
targetTypeArguments = TypeUtil.getTypeArguments(targetType);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Map copy() {
|
public Map copy() {
|
||||||
|
|
||||||
// 提前获取目标值真实类型
|
|
||||||
final Type[] earlyDetectTypeArguments = TypeUtil.getTypeArguments(this.targetType);
|
|
||||||
|
|
||||||
this.source.forEach((sKey, sValue) -> {
|
this.source.forEach((sKey, sValue) -> {
|
||||||
if (null == sKey) {
|
if (null == sKey) {
|
||||||
return;
|
return;
|
||||||
@@ -62,9 +56,9 @@ public class MapToMapCopier extends AbsCopier<Map, Map> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 尝试转换源值
|
// 尝试转换源值
|
||||||
if (null != earlyDetectTypeArguments) {
|
if (null != targetTypeArguments) {
|
||||||
//sValue = Convert.convertWithCheck(typeArguments[1], sValue, null, this.copyOptions.ignoreError);
|
//sValue = Convert.convertWithCheck(typeArguments[1], sValue, null, this.copyOptions.ignoreError);
|
||||||
sValue = this.copyOptions.convertField(earlyDetectTypeArguments[1], sValue);
|
sValue = this.copyOptions.convertField(targetTypeArguments[1], sValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 自定义值
|
// 自定义值
|
||||||
|
Reference in New Issue
Block a user