This is an automated email from the ASF dual-hosted git repository.
markt pushed a commit to branch 11.0.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/11.0.x by this push:
new 0341bf0cb5 Use lazy initialisation for lambdaArguments
0341bf0cb5 is described below
commit 0341bf0cb56eac6f8ed6a5ca76ca477d50129f03
Author: Mark Thomas <[email protected]>
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/jakarta/el/ELContext.java | 17 ++++++++++++-----
webapps/docs/changelog.xml | 5 +++++
2 files changed, 17 insertions(+), 5 deletions(-)
diff --git a/java/jakarta/el/ELContext.java b/java/jakarta/el/ELContext.java
index 12840d1597..98f0856796 100644
--- a/java/jakarta/el/ELContext.java
+++ b/java/jakarta/el/ELContext.java
@@ -40,12 +40,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 d9a2af27b2..088221d442 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -205,6 +205,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: [email protected]
For additional commands, e-mail: [email protected]