!1345 优化XXXToMapCopier的部分性能

Merge pull request !1345 from IzayoiYurin/v5-dev
This commit is contained in:
Looly 2025-05-23 13:46:36 +00:00 committed by Gitee
commit 4e1b468096
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
2 changed files with 13 additions and 8 deletions

View File

@ -44,6 +44,9 @@ public class BeanToMapCopier extends AbsCopier<Object, Map> {
actualEditable = copyOptions.editable;
}
// 提前获取目标值真实类型
final Type[] earlyDetectTypeArguments = TypeUtil.getTypeArguments(this.targetType);
final Map<String, PropDesc> sourcePropDescMap = BeanUtil.getBeanDesc(actualEditable).getPropMap(copyOptions.ignoreCase);
sourcePropDescMap.forEach((sFieldName, sDesc) -> {
if (null == sFieldName || false == sDesc.isReadable(copyOptions.transientSupport)) {
@ -68,11 +71,10 @@ public class BeanToMapCopier extends AbsCopier<Object, Map> {
return;
}
// 获取目标值真实类型并转换源值
final Type[] typeArguments = TypeUtil.getTypeArguments(this.targetType);
if(null != typeArguments && typeArguments.length > 1){
// 尝试转换源值
if(null != earlyDetectTypeArguments && earlyDetectTypeArguments.length > 1){
//sValue = Convert.convertWithCheck(typeArguments[1], sValue, null, this.copyOptions.ignoreError);
sValue = this.copyOptions.convertField(typeArguments[1], sValue);
sValue = this.copyOptions.convertField(earlyDetectTypeArguments[1], sValue);
}
// 自定义值

View File

@ -33,6 +33,10 @@ public class MapToMapCopier extends AbsCopier<Map, Map> {
@Override
public Map copy() {
// 提前获取目标值真实类型
final Type[] earlyDetectTypeArguments = TypeUtil.getTypeArguments(this.targetType);
this.source.forEach((sKey, sValue) -> {
if (null == sKey) {
return;
@ -57,11 +61,10 @@ public class MapToMapCopier extends AbsCopier<Map, Map> {
return;
}
// 获取目标值真实类型并转换源值
final Type[] typeArguments = TypeUtil.getTypeArguments(this.targetType);
if (null != typeArguments) {
// 尝试转换源值
if (null != earlyDetectTypeArguments) {
//sValue = Convert.convertWithCheck(typeArguments[1], sValue, null, this.copyOptions.ignoreError);
sValue = this.copyOptions.convertField(typeArguments[1], sValue);
sValue = this.copyOptions.convertField(earlyDetectTypeArguments[1], sValue);
}
// 自定义值