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 f265740b6e Use lazy initialisation for lambdaArguments f265740b6e is described below commit f265740b6e79ca0410d8c34419a7fd1257a8c8df Author: Mark Thomas <ma...@apache.org> AuthorDate: Thu Oct 3 10:02:47 2024 +0100 Use lazy initialisation for lambdaArguments This aligns with other fields in ELContext that already use lazy initialisation --- java/javax/el/ELContext.java | 17 ++++++++++++----- webapps/docs/changelog.xml | 5 +++++ 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/java/javax/el/ELContext.java b/java/javax/el/ELContext.java index ac9d5fa2ea..98ec843253 100644 --- a/java/javax/el/ELContext.java +++ b/java/javax/el/ELContext.java @@ -38,12 +38,19 @@ public abstract class ELContext { private List<EvaluationListener> listeners; - private Deque<Map<String,Object>> lambdaArguments = new ArrayDeque<>(); + private Deque<Map<String,Object>> lambdaArguments = null; public ELContext() { this.resolved = false; } + private Deque<Map<String,Object>> getLambdaArguments() { + if (lambdaArguments == null) { + lambdaArguments = new ArrayDeque<>(4); + } + return lambdaArguments; + } + public void setPropertyResolved(boolean resolved) { this.resolved = resolved; } @@ -235,7 +242,7 @@ public abstract class ELContext { * @since EL 3.0 */ public boolean isLambdaArgument(String name) { - for (Map<String,Object> arguments : lambdaArguments) { + for (Map<String,Object> arguments : getLambdaArguments()) { if (arguments.containsKey(name)) { return true; } @@ -253,7 +260,7 @@ public abstract class ELContext { * @since EL 3.0 */ public Object getLambdaArgument(String name) { - for (Map<String,Object> arguments : lambdaArguments) { + for (Map<String,Object> arguments : getLambdaArguments()) { Object result = arguments.get(name); if (result != null) { return result; @@ -271,7 +278,7 @@ public abstract class ELContext { * @since EL 3.0 */ public void enterLambdaScope(Map<String,Object> arguments) { - lambdaArguments.push(arguments); + getLambdaArguments().push(arguments); } /** @@ -280,7 +287,7 @@ public abstract class ELContext { * @since EL 3.0 */ public void exitLambdaScope() { - lambdaArguments.pop(); + getLambdaArguments().pop(); } /** diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml index 72406044b3..e32871c8be 100644 --- a/webapps/docs/changelog.xml +++ b/webapps/docs/changelog.xml @@ -196,6 +196,11 @@ include AND or OR operations with more than two operands and expressions that use <code>not empty</code>. (markt) </fix> + <fix> + <bug>69348</bug>: Reduce memory consumption in <code>ELContext</code> by + using lazy initialization for the data structure used to track lambda + arguments. (markt) + </fix> </changelog> </subsection> <subsection name="Web applications"> --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org