Skip to content

Commit 9452a57

Browse files
committed
Optimize Plugin
1 parent 87baeb2 commit 9452a57

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/main/java/org/apache/ibatis/plugin/Plugin.java

+8-2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
import java.util.HashSet;
2323
import java.util.Map;
2424
import java.util.Set;
25+
import java.util.concurrent.ConcurrentHashMap;
26+
import java.util.concurrent.ConcurrentMap;
2527

2628
import org.apache.ibatis.reflection.ExceptionUtil;
2729
import org.apache.ibatis.util.MapUtil;
@@ -34,6 +36,7 @@ public class Plugin implements InvocationHandler {
3436
private final Object target;
3537
private final Interceptor interceptor;
3638
private final Map<Class<?>, Set<Method>> signatureMap;
39+
private final ConcurrentMap<Method, Boolean> methodMap = new ConcurrentHashMap<>();
3740

3841
private Plugin(Object target, Interceptor interceptor, Map<Class<?>, Set<Method>> signatureMap) {
3942
this.target = target;
@@ -53,9 +56,12 @@ public static Object wrap(Object target, Interceptor interceptor) {
5356

5457
@Override
5558
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
56-
try {
59+
boolean intercepted = MapUtil.computeIfAbsent(methodMap, method, key -> {
5760
Set<Method> methods = signatureMap.get(method.getDeclaringClass());
58-
if (methods != null && methods.contains(method)) {
61+
return methods != null && methods.contains(method);
62+
});
63+
try {
64+
if (intercepted) {
5965
return interceptor.intercept(new Invocation(target, method, args));
6066
}
6167
return method.invoke(target, args);

0 commit comments

Comments
 (0)