You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by kk...@apache.org on 2014/06/11 17:48:18 UTC
svn commit: r1601934 - in /tomcat/tc7.0.x/trunk:
java/org/apache/jasper/compiler/JspReader.java
java/org/apache/jasper/compiler/Parser.java webapps/docs/changelog.xml
Author: kkolinko
Date: Wed Jun 11 15:48:17 2014
New Revision: 1601934
URL: http://svn.apache.org/r1601934
Log:
Move code that parses EL expressions within JSP template text from Parser to JspReader class.
This is done to get access to JspReader.nextChar(mark) to avoid calling reader.mark() in a loop, as that method allocates new Mark object on each call.
Also removed duplicate "start = reader.mark();" call, as parseELExpression() does update 'start'.
It is backport of r1601924.
Modified:
tomcat/tc7.0.x/trunk/java/org/apache/jasper/compiler/JspReader.java
tomcat/tc7.0.x/trunk/java/org/apache/jasper/compiler/Parser.java
tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml
Modified: tomcat/tc7.0.x/trunk/java/org/apache/jasper/compiler/JspReader.java
URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/java/org/apache/jasper/compiler/JspReader.java?rev=1601934&r1=1601933&r2=1601934&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/java/org/apache/jasper/compiler/JspReader.java (original)
+++ tomcat/tc7.0.x/trunk/java/org/apache/jasper/compiler/JspReader.java Wed Jun 11 15:48:17 2014
@@ -493,6 +493,46 @@ class JspReader {
return ret;
}
+ /**
+ * Parse ELExpressionBody that is a body of ${} or #{} expression. Initial
+ * reader position is expected to be just after '${' or '#{' characters.
+ * <p>
+ * In case of success, this method returns <code>Mark</code> for the last
+ * character before the terminating '}' and reader is positioned just after
+ * the '}' character. If no terminating '}' is encountered, this method
+ * returns <code>null</code>.
+ *
+ * @return Mark for the last character of EL expression or <code>null</code>
+ */
+ Mark skipELExpression() throws JasperException {
+ // ELExpressionBody.
+ // Starts with "#{" or "${". Ends with "}".
+ // May contain quoted "{", "}", '{', or '}'.
+ Mark last = mark();
+ boolean singleQuoted = false, doubleQuoted = false;
+ int currentChar;
+ do {
+ currentChar = nextChar(last);
+ while (currentChar == '\\' && (singleQuoted || doubleQuoted)) {
+ // skip character following '\' within quotes
+ // No need to update 'last', as neither of these characters
+ // can be the closing '}'.
+ nextChar();
+ currentChar = nextChar();
+ }
+ if (currentChar == -1) {
+ return null;
+ }
+ if (currentChar == '"' && !singleQuoted) {
+ doubleQuoted = !doubleQuoted;
+ } else if (currentChar == '\'' && !doubleQuoted) {
+ singleQuoted = !singleQuoted;
+ }
+ } while (currentChar != '}' || (singleQuoted || doubleQuoted));
+
+ return last;
+ }
+
final boolean isSpace() throws JasperException {
// Note: If this logic changes, also update Node.TemplateText.rtrim()
return peekChar() <= ' ';
Modified: tomcat/tc7.0.x/trunk/java/org/apache/jasper/compiler/Parser.java
URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/java/org/apache/jasper/compiler/Parser.java?rev=1601934&r1=1601933&r2=1601934&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/java/org/apache/jasper/compiler/Parser.java (original)
+++ tomcat/tc7.0.x/trunk/java/org/apache/jasper/compiler/Parser.java Wed Jun 11 15:48:17 2014
@@ -732,32 +732,15 @@ class Parser implements TagConstants {
}
/*
- * ELExpressionBody (following "${" to first unquoted "}") // XXX add formal
- * production and confirm implementation against it, // once it's decided
+ * ELExpressionBody (following "${" to first unquoted "}")
*/
private void parseELExpression(Node parent, char type)
throws JasperException {
start = reader.mark();
- Mark last = null;
- boolean singleQuoted = false, doubleQuoted = false;
- int currentChar;
- do {
- // XXX could move this logic to JspReader
- last = reader.mark(); // XXX somewhat wasteful
- currentChar = reader.nextChar();
- while (currentChar == '\\' && (singleQuoted || doubleQuoted)) {
- // skip character following '\' within quotes
- reader.nextChar();
- currentChar = reader.nextChar();
- }
- if (currentChar == -1)
- err.jspError(start, "jsp.error.unterminated", type + "{");
- if (currentChar == '"' && !singleQuoted) {
- doubleQuoted = !doubleQuoted;
- } else if (currentChar == '\'' && !doubleQuoted) {
- singleQuoted = !singleQuoted;
- }
- } while (currentChar != '}' || (singleQuoted || doubleQuoted));
+ Mark last = reader.skipELExpression();
+ if (last == null) {
+ err.jspError(start, "jsp.error.unterminated", type + "{");
+ }
new Node.ELExpression(type, reader.getText(start, last), start, parent);
}
@@ -1383,7 +1366,6 @@ class Parser implements TagConstants {
new Node.TemplateText(ttext.toString(), start, parent);
// Mark and parse the EL expression and create its node:
- start = reader.mark();
parseELExpression(parent, (char) ch);
start = reader.mark();
Modified: tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml
URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml?rev=1601934&r1=1601933&r2=1601934&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml (original)
+++ tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml Wed Jun 11 15:48:17 2014
@@ -128,6 +128,11 @@
<bug>56612</bug>: Correctly parse two consecutive escaped single quotes
when used in UEL expression in a JSP. (markt)
</fix>
+ <update>
+ Move code that parses EL expressions within JSP template text from
+ <code>Parser</code> to <code>JspReader</code> class for better
+ performance. (kkolinko)
+ </update>
</changelog>
</subsection>
<subsection name="WebSocket">
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org