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 6c86481e6a Fix BZ 69429 - optimize getParameters() for zero parameters
6c86481e6a is described below

commit 6c86481e6a0e3916c492f5e9af9eb33748448440
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Mon Nov 4 16:09:22 2024 +0000

    Fix BZ 69429 - optimize getParameters() for zero parameters
---
 java/org/apache/el/parser/AstMethodParameters.java | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/java/org/apache/el/parser/AstMethodParameters.java 
b/java/org/apache/el/parser/AstMethodParameters.java
index 11a2ac24ca..d127deec9e 100644
--- a/java/org/apache/el/parser/AstMethodParameters.java
+++ b/java/org/apache/el/parser/AstMethodParameters.java
@@ -23,16 +23,24 @@ import java.util.List;
 import org.apache.el.lang.EvaluationContext;
 
 public final class AstMethodParameters extends SimpleNode {
+
+    private static final Object[] EMPTY_OBJECT_ARRAY = new Object[0];
+
     public AstMethodParameters(int id) {
         super(id);
     }
 
     public Object[] getParameters(EvaluationContext ctx) {
+        int numChildren = this.jjtGetNumChildren();
+        // Optimise simple case
+        if (numChildren == 0) {
+            return EMPTY_OBJECT_ARRAY;
+        }
         List<Object> params = new ArrayList<>();
-        for (int i = 0; i < this.jjtGetNumChildren(); i++) {
+        for (int i = 0; i < numChildren; i++) {
             params.add(this.jjtGetChild(i).getValue(ctx));
         }
-        return params.toArray(new Object[0]);
+        return params.toArray(EMPTY_OBJECT_ARRAY);
     }
 
     @Override


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org

Reply via email to