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
commit 35f06b3e9669de9653746dbca4ca415475870eae Author: Mark Thomas <ma...@apache.org> AuthorDate: Thu Sep 26 16:33:02 2024 +0100 Complete fix for BZ 69338. Optimise "not empty" --- .../{AstEmpty.java => AstAbstractEmpty.java} | 37 ++++++++++---------- java/org/apache/el/parser/AstEmpty.java | 39 ++-------------------- java/org/apache/el/parser/AstNotEmpty.java | 24 +++++++++++++ java/org/apache/el/parser/ELParser.jjt | 3 ++ webapps/docs/changelog.xml | 3 +- 5 files changed, 50 insertions(+), 56 deletions(-) diff --git a/java/org/apache/el/parser/AstEmpty.java b/java/org/apache/el/parser/AstAbstractEmpty.java similarity index 62% copy from java/org/apache/el/parser/AstEmpty.java copy to java/org/apache/el/parser/AstAbstractEmpty.java index d01e7f18ec..844d183291 100644 --- a/java/org/apache/el/parser/AstEmpty.java +++ b/java/org/apache/el/parser/AstAbstractEmpty.java @@ -24,36 +24,37 @@ import javax.el.ELException; import org.apache.el.lang.EvaluationContext; -/** - * @author Jacob Hookom [ja...@hookom.net] - */ -public final class AstEmpty extends SimpleNode { +public abstract class AstAbstractEmpty extends SimpleNode { + + private final Boolean RETURN_EMPTY; + private final Boolean RETURN_NOT_EMPTY; + - public AstEmpty(int id) { + public AstAbstractEmpty(int id, boolean invert) { super(id); + if (invert) { + RETURN_EMPTY = Boolean.FALSE; + RETURN_NOT_EMPTY = Boolean.TRUE; + } else { + RETURN_EMPTY = Boolean.TRUE; + RETURN_NOT_EMPTY = Boolean.FALSE; + } } - @Override public Class<?> getType(EvaluationContext ctx) throws ELException { return Boolean.class; } - @Override public Object getValue(EvaluationContext ctx) throws ELException { Object obj = this.children[0].getValue(ctx); - if (obj == null) { - return Boolean.TRUE; - } else if (obj instanceof String) { - return Boolean.valueOf(((String) obj).length() == 0); - } else if (obj instanceof Object[]) { - return Boolean.valueOf(((Object[]) obj).length == 0); - } else if (obj instanceof Collection<?>) { - return Boolean.valueOf(((Collection<?>) obj).isEmpty()); - } else if (obj instanceof Map<?,?>) { - return Boolean.valueOf(((Map<?,?>) obj).isEmpty()); + if (obj == null || obj instanceof String && ((String) obj).length() == 0 || + obj instanceof Object[] && ((Object[]) obj).length == 0 || + obj instanceof Collection<?> && ((Collection<?>) obj).isEmpty() || + obj instanceof Map<?,?> && ((Map<?,?>) obj).isEmpty()) { + return RETURN_EMPTY; } - return Boolean.FALSE; + return RETURN_NOT_EMPTY; } } diff --git a/java/org/apache/el/parser/AstEmpty.java b/java/org/apache/el/parser/AstEmpty.java index d01e7f18ec..0517091b9c 100644 --- a/java/org/apache/el/parser/AstEmpty.java +++ b/java/org/apache/el/parser/AstEmpty.java @@ -17,43 +17,8 @@ /* Generated By:JJTree: Do not edit this line. AstEmpty.java */ package org.apache.el.parser; -import java.util.Collection; -import java.util.Map; - -import javax.el.ELException; - -import org.apache.el.lang.EvaluationContext; - -/** - * @author Jacob Hookom [ja...@hookom.net] - */ -public final class AstEmpty extends SimpleNode { - +public final class AstEmpty extends AstAbstractEmpty { public AstEmpty(int id) { - super(id); - } - - - @Override - public Class<?> getType(EvaluationContext ctx) throws ELException { - return Boolean.class; - } - - - @Override - public Object getValue(EvaluationContext ctx) throws ELException { - Object obj = this.children[0].getValue(ctx); - if (obj == null) { - return Boolean.TRUE; - } else if (obj instanceof String) { - return Boolean.valueOf(((String) obj).length() == 0); - } else if (obj instanceof Object[]) { - return Boolean.valueOf(((Object[]) obj).length == 0); - } else if (obj instanceof Collection<?>) { - return Boolean.valueOf(((Collection<?>) obj).isEmpty()); - } else if (obj instanceof Map<?,?>) { - return Boolean.valueOf(((Map<?,?>) obj).isEmpty()); - } - return Boolean.FALSE; + super(id, false); } } diff --git a/java/org/apache/el/parser/AstNotEmpty.java b/java/org/apache/el/parser/AstNotEmpty.java new file mode 100644 index 0000000000..0066c07afb --- /dev/null +++ b/java/org/apache/el/parser/AstNotEmpty.java @@ -0,0 +1,24 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/* Generated By:JJTree: Do not edit this line. AstEmpty.java */ +package org.apache.el.parser; + +public final class AstNotEmpty extends AstAbstractEmpty { + public AstNotEmpty(int id) { + super(id, true); + } +} diff --git a/java/org/apache/el/parser/ELParser.jjt b/java/org/apache/el/parser/ELParser.jjt index 01364520e1..c28b8f19ce 100644 --- a/java/org/apache/el/parser/ELParser.jjt +++ b/java/org/apache/el/parser/ELParser.jjt @@ -255,6 +255,9 @@ void Multiplication() : {} void Unary() : {} { <MINUS> Unary() #Negative + | + LOOKAHEAD(2) + (<NOT0>|<NOT1>) <EMPTY> Unary() #NotEmpty | (<NOT0>|<NOT1>) Unary() #Not | diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml index 61001544a9..109168f0b4 100644 --- a/webapps/docs/changelog.xml +++ b/webapps/docs/changelog.xml @@ -167,7 +167,8 @@ </fix> <fix> <bug>69338</bug>: Improve the performance of processing expressions that - include AND or OR operations with more than two operands. (markt) + include AND or OR operations with more than two operands and expressions + that use <code>not empty</code>. (markt) </fix> </changelog> </subsection> --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org