|
@@ -73,20 +73,19 @@ public final class ObjectUtils {
|
|
|
private static final Map<Class<?>, Map<String, Field>> CLASS_FIELD_MAPPING = Maps.newConcurrentMap();
|
|
|
|
|
|
/**
|
|
|
- * SerializedLambda 反序列化缓存
|
|
|
+ * Protostuff对象类型/Schema映射表
|
|
|
*/
|
|
|
- private static final Map<Class<?>, SerializedLambda> LAMBDA_FUNCTION_MAPPING = Maps.newConcurrentMap();
|
|
|
+ private static final Map<Class<?>, Schema<?>> PROTOSTUFF_SCHEMA_MAPPING = Maps.newConcurrentMap();
|
|
|
|
|
|
/**
|
|
|
- * Protostuff对象类型/Schema映射表
|
|
|
+ * SerializedLambda 反序列化缓存
|
|
|
*/
|
|
|
- private static final Map<Class<?>, Schema<?>> PROTOSTUFF_CLASS_SCHEMA_MAPPING = Maps.newConcurrentMap();
|
|
|
+ private static final Map<Class<?>, SerializedLambda> LAMBDA_FUNCTION_MAPPING = Maps.newConcurrentMap();
|
|
|
|
|
|
/**
|
|
|
* 类对象/属性描述映射表
|
|
|
*/
|
|
|
- private static final Map<Class<?>, List<PropertyDescriptor>> CLASS_PROPERTY_DESCRIPTOR_MAPPING =
|
|
|
- Maps.newConcurrentMap();
|
|
|
+ private static final Map<Class<?>, List<PropertyDescriptor>> PROPERTY_DESCRIPTOR_MAPPING = Maps.newConcurrentMap();
|
|
|
|
|
|
static {
|
|
|
// 注册简单的对象拷贝转换器
|
|
@@ -454,7 +453,8 @@ public final class ObjectUtils {
|
|
|
* @return 字段名称/实例映射表
|
|
|
*/
|
|
|
public static Map<String, Field> getAllFields(@NonNull Class<?> clazz) {
|
|
|
- return CLASS_FIELD_MAPPING.computeIfAbsent(clazz, k -> {
|
|
|
+ Map<String, Field> cache = CLASS_FIELD_MAPPING.get(clazz);
|
|
|
+ return cache != null ? cache : CLASS_FIELD_MAPPING.computeIfAbsent(clazz, k -> {
|
|
|
// 接口对象类型
|
|
|
if (Modifier.isInterface(k.getModifiers())) {
|
|
|
return Collections.emptyMap();
|
|
@@ -797,7 +797,8 @@ public final class ObjectUtils {
|
|
|
*/
|
|
|
@SuppressWarnings("unchecked")
|
|
|
private static <M, T extends Schema<M>> T getProtostuffSchema(@NonNull Class<M> clazz) {
|
|
|
- return (T) PROTOSTUFF_CLASS_SCHEMA_MAPPING.computeIfAbsent(clazz, RuntimeSchema::getSchema);
|
|
|
+ T schema = (T) PROTOSTUFF_SCHEMA_MAPPING.get(clazz);
|
|
|
+ return schema != null ? schema : (T) PROTOSTUFF_SCHEMA_MAPPING.computeIfAbsent(clazz, RuntimeSchema::getSchema);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -844,7 +845,8 @@ public final class ObjectUtils {
|
|
|
* @return 属性描述列表
|
|
|
*/
|
|
|
public static List<PropertyDescriptor> getPropertyDescriptors(@NonNull Class<?> clazz) {
|
|
|
- return CLASS_PROPERTY_DESCRIPTOR_MAPPING.computeIfAbsent(clazz, k -> {
|
|
|
+ List<PropertyDescriptor> descriptors = PROPERTY_DESCRIPTOR_MAPPING.get(clazz);
|
|
|
+ return descriptors != null ? descriptors : PROPERTY_DESCRIPTOR_MAPPING.computeIfAbsent(clazz, k -> {
|
|
|
BeanInfo bean;
|
|
|
try {
|
|
|
bean = Introspector.getBeanInfo(clazz, Object.class);
|
|
@@ -874,7 +876,9 @@ public final class ObjectUtils {
|
|
|
* @return Lambda对象序列化对象实例
|
|
|
*/
|
|
|
private static SerializedLambda lookupFunctionLambda(Serializable function) {
|
|
|
- return LAMBDA_FUNCTION_MAPPING.computeIfAbsent(function.getClass(), k -> {
|
|
|
+ Class<?> clazz = function.getClass();
|
|
|
+ SerializedLambda lambda = LAMBDA_FUNCTION_MAPPING.get(clazz);
|
|
|
+ return lambda != null ? lambda : LAMBDA_FUNCTION_MAPPING.computeIfAbsent(clazz, k -> {
|
|
|
try {
|
|
|
Method method = k.getDeclaredMethod("writeReplace");
|
|
|
method.setAccessible(true);
|