This is an automated email from the ASF dual-hosted git repository.
markt pushed a commit to branch 10.1.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/10.1.x by this push:
new 5fbf70a2a3 Follow-up to BZ 69381. Additional location for performance
improvement
5fbf70a2a3 is described below
commit 5fbf70a2a3e4f21370e9fff304f54dea874e1002
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 | 9 +++++++++
2 files changed, 24 insertions(+), 3 deletions(-)
diff --git a/java/org/apache/el/util/ReflectionUtil.java
b/java/org/apache/el/util/ReflectionUtil.java
index a94a73fd42..f15ccc1be0 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 f28794f899..13ad8222aa 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -105,6 +105,15 @@
issues do not "pop up" wrt. others).
-->
<section name="Tomcat 10.1.34 (schultz)" rtext="in development">
+ <subsection name="Jasper">
+ <changelog>
+ <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>
<section name="Tomcat 10.1.33 (schultz)" rtext="release in progress">
<subsection name="Other">
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]