This is an automated email from the ASF dual-hosted git repository.
markt pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/main by this push:
new 5144218a39 Follow-up to BZ 69381. Additional location for performance
improvement
5144218a39 is described below
commit 5144218a399027a59199cb5cf3aaafe9033f7ffb
Author: Mark Thomas <[email protected]>
AuthorDate: Mon Nov 11 08:56:54 2024 +0000
Follow-up to BZ 69381. Additional location for performance improvement
---
java/org/apache/el/util/ReflectionUtil.java | 18 +++++++++++++++---
1 file changed, 15 insertions(+), 3 deletions(-)
diff --git a/java/org/apache/el/util/ReflectionUtil.java
b/java/org/apache/el/util/ReflectionUtil.java
index 6693d46648..c66421df69 100644
--- a/java/org/apache/el/util/ReflectionUtil.java
+++ b/java/org/apache/el/util/ReflectionUtil.java
@@ -149,7 +149,19 @@ public class ReflectionUtil {
paramCount = paramTypes.length;
}
- Method[] methods = base.getClass().getMethods();
+ Class<?> clazz = base.getClass();
+
+ // Fast path: when no arguments exist, there can only be one matching
method and no need for coercion.
+ if (paramCount == 0) {
+ try {
+ Method method = clazz.getMethod(methodName, paramTypes);
+ return getMethod(clazz, base, method);
+ } catch (NoSuchMethodException | SecurityException e) {
+ // Fall through to broader, slower logic
+ }
+ }
+
+ Method[] methods = clazz.getMethods();
Map<Method,MatchResult> candidates = new HashMap<>();
for (Method m : methods) {
@@ -250,7 +262,7 @@ public class ReflectionUtil {
// If a method is found where every parameter matches exactly,
// and no vars args are present, return it
if (exactMatch == paramCount && varArgsMatch == 0) {
- Method result = getMethod(base.getClass(), base, m);
+ Method result = getMethod(clazz, base, m);
if (result == null) {
throw new MethodNotFoundException(
MessageFactory.get("error.method.notfound", base,
property, paramString(paramTypes)));
@@ -300,7 +312,7 @@ public class ReflectionUtil {
MessageFactory.get("error.method.notfound", base,
property, paramString(paramTypes)));
}
- Method result = getMethod(base.getClass(), base, match);
+ Method result = getMethod(clazz, base, match);
if (result == null) {
throw new MethodNotFoundException(
MessageFactory.get("error.method.notfound", base,
property, paramString(paramTypes)));
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]