This is an automated email from the ASF dual-hosted git repository.
markt pushed a commit to branch 9.0.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/9.0.x by this push:
new e01c602659 Follow-up to BZ 69381. Additional location for performance
improvement
e01c602659 is described below
commit e01c60265994d6c7b91f3cadff1c44038770bfe3
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 +++++++++++++++---
webapps/docs/changelog.xml | 5 +++++
2 files changed, 20 insertions(+), 3 deletions(-)
diff --git a/java/org/apache/el/util/ReflectionUtil.java
b/java/org/apache/el/util/ReflectionUtil.java
index 2422748cae..d92eba762b 100644
--- a/java/org/apache/el/util/ReflectionUtil.java
+++ b/java/org/apache/el/util/ReflectionUtil.java
@@ -151,7 +151,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) {
@@ -252,7 +264,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)));
@@ -302,7 +314,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)));
diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml
index 341ffc644d..af45efd38b 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -111,6 +111,11 @@
Further optimise EL evaluation of method parameters. Patch provided by
Paolo B. (markt)
</fix>
+ <fix>
+ Follow-up to the fix for <bug>69381</bug>. Apply the optimisation for
+ method lookup performance in expression language to an additional
+ location. (markt)
+ </fix>
</changelog>
</subsection>
</section>
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]