Skip to content

Commit 30061d9

Browse files
committed
Merge branch '2.7' into 2.8
2 parents ccd7212 + 0d700fd commit 30061d9

File tree

1 file changed

+107
-109
lines changed

1 file changed

+107
-109
lines changed

src/main/java/com/fasterxml/jackson/databind/util/ClassUtil.java

Lines changed: 107 additions & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -354,115 +354,6 @@ public static Class<?> findClass(String className) throws ClassNotFoundException
354354
throw new ClassNotFoundException(prob.getMessage(), prob);
355355
}
356356

357-
/*
358-
/**********************************************************
359-
/* Caching access to class metadata, added in 2.7
360-
/**********************************************************
361-
*/
362-
363-
/* 17-Sep-2015, tatu: Although access methods should not be significant
364-
* problems for most proper usage, they may become problematic if
365-
* ObjectMapper has to be re-created; and especially so on Android.
366-
* So let's do somewhat aggressive caching.
367-
*/
368-
369-
private final static LRUMap<Class<?>,ClassMetadata> sCached = new LRUMap<Class<?>,ClassMetadata>(48, 48);
370-
371-
/**
372-
* @since 2.7
373-
*/
374-
public static String getPackageName(Class<?> cls) {
375-
return _getMetadata(cls).getPackageName();
376-
}
377-
378-
/**
379-
* @since 2.7
380-
*/
381-
public static boolean hasEnclosingMethod(Class<?> cls) {
382-
return _getMetadata(cls).hasEnclosingMethod();
383-
}
384-
385-
/**
386-
* @since 2.7
387-
*/
388-
public static Field[] getDeclaredFields(Class<?> cls) {
389-
return _getMetadata(cls).getDeclaredFields();
390-
}
391-
392-
/**
393-
* @since 2.7
394-
*/
395-
public static Method[] getDeclaredMethods(Class<?> cls) {
396-
return _getMetadata(cls).getDeclaredMethods();
397-
}
398-
399-
/**
400-
* @since 2.7
401-
*/
402-
public static Annotation[] findClassAnnotations(Class<?> cls) {
403-
return _getMetadata(cls).getDeclaredAnnotations();
404-
}
405-
406-
/**
407-
* @since 2.7
408-
*/
409-
public static Ctor[] getConstructors(Class<?> cls) {
410-
return _getMetadata(cls).getConstructors();
411-
}
412-
413-
// // // Then methods that do NOT cache access but were considered
414-
// // // (and could be added to do caching if it was proven effective)
415-
416-
/**
417-
* @since 2.7
418-
*/
419-
public static Class<?> getDeclaringClass(Class<?> cls) {
420-
// Caching does not seem worthwhile, as per profiling
421-
return isObjectOrPrimitive(cls) ? null : cls.getDeclaringClass();
422-
}
423-
424-
/**
425-
* @since 2.7
426-
*/
427-
public static Type getGenericSuperclass(Class<?> cls) {
428-
return cls.getGenericSuperclass();
429-
}
430-
431-
/**
432-
* @since 2.7
433-
*/
434-
public static Type[] getGenericInterfaces(Class<?> cls) {
435-
return _getMetadata(cls).getGenericInterfaces();
436-
}
437-
438-
/**
439-
* @since 2.7
440-
*/
441-
public static Class<?> getEnclosingClass(Class<?> cls) {
442-
// Caching does not seem worthwhile, as per profiling
443-
return isObjectOrPrimitive(cls) ? null : cls.getEnclosingClass();
444-
}
445-
446-
447-
private static Class<?>[] _interfaces(Class<?> cls) {
448-
return _getMetadata(cls).getInterfaces();
449-
}
450-
451-
private static ClassMetadata _getMetadata(Class<?> cls)
452-
{
453-
ClassMetadata md = sCached.get(cls);
454-
if (md == null) {
455-
md = new ClassMetadata(cls);
456-
// tiny optimization, but in case someone concurrently constructed it,
457-
// let's use that instance, to reduce extra concurrent work.
458-
ClassMetadata old = sCached.putIfAbsent(cls, md);
459-
if (old != null) {
460-
md = old;
461-
}
462-
}
463-
return md;
464-
}
465-
466357
/*
467358
/**********************************************************
468359
/* Method type detection methods
@@ -1012,6 +903,113 @@ public static boolean isObjectOrPrimitive(Class<?> cls) {
1012903
return (cls == CLS_OBJECT) || cls.isPrimitive();
1013904
}
1014905

906+
/*
907+
/**********************************************************
908+
/* Caching access to class metadata, added in 2.7
909+
/**********************************************************
910+
*/
911+
912+
/* 17-Sep-2015, tatu: Although access methods should not be significant
913+
* problems for most proper usage, they may become problematic if
914+
* ObjectMapper has to be re-created; and especially so on Android.
915+
* So let's do somewhat aggressive caching.
916+
*/
917+
private final static LRUMap<Class<?>,ClassMetadata> sCached = new LRUMap<Class<?>,ClassMetadata>(48, 48);
918+
919+
/**
920+
* @since 2.7
921+
*/
922+
public static String getPackageName(Class<?> cls) {
923+
return _getMetadata(cls).getPackageName();
924+
}
925+
926+
/**
927+
* @since 2.7
928+
*/
929+
public static boolean hasEnclosingMethod(Class<?> cls) {
930+
return _getMetadata(cls).hasEnclosingMethod();
931+
}
932+
933+
/**
934+
* @since 2.7
935+
*/
936+
public static Field[] getDeclaredFields(Class<?> cls) {
937+
return _getMetadata(cls).getDeclaredFields();
938+
}
939+
940+
/**
941+
* @since 2.7
942+
*/
943+
public static Method[] getDeclaredMethods(Class<?> cls) {
944+
return _getMetadata(cls).getDeclaredMethods();
945+
}
946+
947+
/**
948+
* @since 2.7
949+
*/
950+
public static Annotation[] findClassAnnotations(Class<?> cls) {
951+
return _getMetadata(cls).getDeclaredAnnotations();
952+
}
953+
954+
/**
955+
* @since 2.7
956+
*/
957+
public static Ctor[] getConstructors(Class<?> cls) {
958+
return _getMetadata(cls).getConstructors();
959+
}
960+
961+
// // // Then methods that do NOT cache access but were considered
962+
// // // (and could be added to do caching if it was proven effective)
963+
964+
/**
965+
* @since 2.7
966+
*/
967+
public static Class<?> getDeclaringClass(Class<?> cls) {
968+
// Caching does not seem worthwhile, as per profiling
969+
return isObjectOrPrimitive(cls) ? null : cls.getDeclaringClass();
970+
}
971+
972+
/**
973+
* @since 2.7
974+
*/
975+
public static Type getGenericSuperclass(Class<?> cls) {
976+
return cls.getGenericSuperclass();
977+
}
978+
979+
/**
980+
* @since 2.7
981+
*/
982+
public static Type[] getGenericInterfaces(Class<?> cls) {
983+
return _getMetadata(cls).getGenericInterfaces();
984+
}
985+
986+
/**
987+
* @since 2.7
988+
*/
989+
public static Class<?> getEnclosingClass(Class<?> cls) {
990+
// Caching does not seem worthwhile, as per profiling
991+
return isObjectOrPrimitive(cls) ? null : cls.getEnclosingClass();
992+
}
993+
994+
private static Class<?>[] _interfaces(Class<?> cls) {
995+
return _getMetadata(cls).getInterfaces();
996+
}
997+
998+
private static ClassMetadata _getMetadata(Class<?> cls)
999+
{
1000+
ClassMetadata md = sCached.get(cls);
1001+
if (md == null) {
1002+
md = new ClassMetadata(cls);
1003+
// tiny optimization, but in case someone concurrently constructed it,
1004+
// let's use that instance, to reduce extra concurrent work.
1005+
ClassMetadata old = sCached.putIfAbsent(cls, md);
1006+
if (old != null) {
1007+
md = old;
1008+
}
1009+
}
1010+
return md;
1011+
}
1012+
10151013
/*
10161014
/**********************************************************
10171015
/* Helper classes

0 commit comments

Comments
 (0)