Skip to content

Commit

Permalink
Add method caching (field, ctors already cached), seems to help a lot…
Browse files Browse the repository at this point in the history
… too
  • Loading branch information
cowtowncoder committed Sep 22, 2015
1 parent 2489387 commit c426de1
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
Expand Up @@ -561,7 +561,7 @@ protected void _addFactoryMixIns(Class<?> mixin)
MemberKey[] methodKeys = null;
int methodCount = _creatorMethods.size();

for (Method m : mixin.getDeclaredMethods()) {
for (Method m : ClassUtil.getDeclaredMethods(mixin)) {
if (!Modifier.isStatic(m.getModifiers())) {
continue;
}
Expand Down Expand Up @@ -642,7 +642,7 @@ protected void _addMethodMixIns(Class<?> targetClass, AnnotatedMethodMap methods
parents.add(mixInCls);
ClassUtil.findSuperTypes(mixInCls, targetClass, parents);
for (Class<?> mixin : parents) {
for (Method m : mixin.getDeclaredMethods()) {
for (Method m : ClassUtil.getDeclaredMethods(mixin)) {
if (!_isIncludableMemberMethod(m)) {
continue;
}
Expand Down Expand Up @@ -1042,12 +1042,12 @@ private final boolean _isAnnotationBundle(Annotation ann) {
protected Method[] _findClassMethods(Class<?> cls)
{
try {
return cls.getDeclaredMethods();
return ClassUtil.getDeclaredMethods(cls);
} catch (final NoClassDefFoundError ex) {
// One of the methods had a class that was not found in the cls.getClassLoader.
// Maybe the developer was nice and has a different class loader for this context.
final ClassLoader loader = Thread.currentThread().getContextClassLoader();
if(loader == null){
if (loader == null){
// Nope... this is going to end poorly
throw ex;
}
Expand Down
17 changes: 17 additions & 0 deletions src/main/java/com/fasterxml/jackson/databind/util/ClassUtil.java
Expand Up @@ -301,6 +301,13 @@ public static Field[] getDeclaredFields(Class<?> cls) {
return _getMetadata(cls).getDeclaredFields();
}

/**
* @since 2.7
*/
public static Method[] getDeclaredMethods(Class<?> cls) {
return _getMetadata(cls).getDeclaredMethods();
}

/**
* @since 2.7
*/
Expand Down Expand Up @@ -812,6 +819,7 @@ private final static class ClassMetadata
private Annotation[] _annotations;
private Ctor[] _constructors;
private Field[] _fields;
private Method[] _methods;

public ClassMetadata(Class<?> forClass) {
_forClass = forClass;
Expand Down Expand Up @@ -885,6 +893,15 @@ public Field[] getDeclaredFields() {
return fields;
}

public Method[] getDeclaredMethods() {
Method[] methods = _methods;
if (methods == null) {
methods = _forClass.getDeclaredMethods();
_methods = methods;
}
return methods;
}

private boolean isObjectOrPrimitive() {
return (_forClass == CLS_OBJECT) || _forClass.isPrimitive();
}
Expand Down

0 comments on commit c426de1

Please sign in to comment.