Skip to content

Commit

Permalink
Revert "Cache the result of findMethod"
Browse files Browse the repository at this point in the history
This reverts commit 4d87c32.
  • Loading branch information
daniellansun committed Jan 4, 2025
1 parent 4d87c32 commit 3ee80f0
Showing 1 changed file with 2 additions and 22 deletions.
24 changes: 2 additions & 22 deletions src/main/java/groovy/lang/MetaClassImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@
import org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite;
import org.codehaus.groovy.runtime.callsite.StaticMetaClassSite;
import org.codehaus.groovy.runtime.callsite.StaticMetaMethodSite;
import org.codehaus.groovy.runtime.memoize.LRUCache;
import org.codehaus.groovy.runtime.metaclass.ClosureMetaMethod;
import org.codehaus.groovy.runtime.metaclass.MetaClassRegistryImpl;
import org.codehaus.groovy.runtime.metaclass.MetaMethodIndex;
Expand Down Expand Up @@ -3166,28 +3165,9 @@ private static void filterMatchingMethodForCategory(FastArray list, MetaMethod m
list.add(method);
}

private static final MetaMethod NULL_METAMETHOD = new MetaMethod() {
@Override
public int getModifiers() { return 0; }
@Override
public String getName() { return ""; }
@Override
public Class getReturnType() { return null; }
@Override
public CachedClass getDeclaringClass() { return null; }
@Override
public Object invoke(Object object, Object[] arguments) { return null; }
};
private static final LRUCache<Method, MetaMethod> METHOD_CACHE = new LRUCache<>(512);
private MetaMethod findMethod(Method method) {
MetaMethod result = METHOD_CACHE.getAndPut(method, m -> {
CachedMethod cachedMethod = CachedMethod.find(m);
MetaMethod metaMethod = cachedMethod == null ? null : findMethod(cachedMethod);
if (metaMethod == null) metaMethod = NULL_METAMETHOD;
return metaMethod;
});
if (result == NULL_METAMETHOD) result = null;
return result;
CachedMethod cachedMethod = CachedMethod.find(method);
return cachedMethod == null ? null : findMethod(cachedMethod);
}

/**
Expand Down

0 comments on commit 3ee80f0

Please sign in to comment.