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 ad4080d  Lazy init ELContext#listeners to avoid unnecessary ArrayList 
and ArrayList$Itr instances
ad4080d is described below

commit ad4080dbed63b71f8e2b1a5779fdea0876d2556b
Author: Thomas Andraschko <tandrasc...@apache.org>
AuthorDate: Wed Sep 9 11:15:01 2020 +0200

    Lazy init ELContext#listeners to avoid unnecessary ArrayList and 
ArrayList$Itr instances
---
 java/javax/el/ELContext.java | 20 ++++++++++++++++++--
 1 file changed, 18 insertions(+), 2 deletions(-)

diff --git a/java/javax/el/ELContext.java b/java/javax/el/ELContext.java
index cd68a78..ca184ca 100644
--- a/java/javax/el/ELContext.java
+++ b/java/javax/el/ELContext.java
@@ -36,7 +36,7 @@ public abstract class ELContext {
 
     private ImportHandler importHandler = null;
 
-    private List<EvaluationListener> listeners = new ArrayList<>();
+    private List<EvaluationListener> listeners;
 
     private Deque<Map<String,Object>> lambdaArguments = new LinkedList<>();
 
@@ -143,6 +143,10 @@ public abstract class ELContext {
      * @since EL 3.0
      */
     public void addEvaluationListener(EvaluationListener listener) {
+        if (listeners == null) {
+            listeners = new ArrayList<>();
+        }
+
         listeners.add(listener);
     }
 
@@ -154,7 +158,7 @@ public abstract class ELContext {
      * @since EL 3.0
      */
     public List<EvaluationListener> getEvaluationListeners() {
-        return listeners;
+        return listeners == null ? Collections.emptyList() : listeners;
     }
 
     /**
@@ -165,6 +169,10 @@ public abstract class ELContext {
      * @since EL 3.0
      */
     public void notifyBeforeEvaluation(String expression) {
+        if (listeners == null) {
+            return;
+        }
+
         for (EvaluationListener listener : listeners) {
             try {
                 listener.beforeEvaluation(this, expression);
@@ -183,6 +191,10 @@ public abstract class ELContext {
      * @since EL 3.0
      */
     public void notifyAfterEvaluation(String expression) {
+        if (listeners == null) {
+            return;
+        }
+        
         for (EvaluationListener listener : listeners) {
             try {
                 listener.afterEvaluation(this, expression);
@@ -202,6 +214,10 @@ public abstract class ELContext {
      * @since EL 3.0
      */
     public void notifyPropertyResolved(Object base, Object property) {
+        if (listeners == null) {
+            return;
+        }
+
         for (EvaluationListener listener : listeners) {
             try {
                 listener.propertyResolved(this, base, property);


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

Reply via email to