luehe 2002/12/05 09:56:43
Modified: jasper2/src/share/org/apache/jasper/compiler Generator.java
JspDocumentParser.java JspReader.java Node.java
PageDataImpl.java Parser.java TagPluginManager.java
jasper2/src/share/org/apache/jasper/compiler/tagplugin
TagPlugin.java TagPluginContext.java
Log:
Store scriptlet text as String (instead of char[]), to avoid
unnecessary conversions between String and char[].
Revision Changes Path
1.137 +7 -8
jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/Generator.java
Index: Generator.java
===================================================================
RCS file:
/home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/Generator.java,v
retrieving revision 1.136
retrieving revision 1.137
diff -u -r1.136 -r1.137
--- Generator.java 5 Dec 2002 02:39:03 -0000 1.136
+++ Generator.java 5 Dec 2002 17:56:43 -0000 1.137
@@ -831,7 +831,7 @@
public void visit(Node.Scriptlet n) throws JasperException {
n.setBeginJavaLine(out.getJavaLine());
- out.printMultiLn(new String(n.getText()));
+ out.printMultiLn(n.getText());
out.println();
n.setEndJavaLine(out.getJavaLine());
}
@@ -1713,8 +1713,7 @@
public void visit(Node.TemplateText n) throws JasperException {
- char[] chars = n.getText();
- int size = chars.length;
+ String text = n.getText();
n.setBeginJavaLine(out.getJavaLine());
@@ -1722,8 +1721,8 @@
StringBuffer sb = new StringBuffer("out.write(\"");
int initLength = sb.length();
int count = CHUNKSIZE;
- for (int i = 0 ; i < size ; i++) {
- char ch = chars[i];
+ for (int i = 0 ; i < text.length() ; i++) {
+ char ch = text.charAt(i);
--count;
switch(ch) {
case '"':
1.31 +11 -13
jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/JspDocumentParser.java
Index: JspDocumentParser.java
===================================================================
RCS file:
/home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/JspDocumentParser.java,v
retrieving revision 1.30
retrieving revision 1.31
diff -u -r1.30 -r1.31
--- JspDocumentParser.java 27 Nov 2002 16:42:26 -0000 1.30
+++ JspDocumentParser.java 5 Dec 2002 17:56:43 -0000 1.31
@@ -368,9 +368,9 @@
for (int i = offset; i < limit; i++) {
int ch = buf[i];
if (lastCh == '$' && ch == '{') {
- char[] bufCopy = ttext.toCharArray();
- if (bufCopy.length > 0) {
- new Node.TemplateText(bufCopy, start, current);
+ if (ttext.size() > 0) {
+ new Node.TemplateText(ttext.toString(), start,
+ current);
ttext = new CharArrayWriter();
}
// following "${" to first unquoted "}"
@@ -392,7 +392,8 @@
continue;
}
if (ch == '}') {
- new Node.ELExpression(ttext.toCharArray(), start, current);
+ new Node.ELExpression(ttext.toString(), start,
+ current);
ttext = new CharArrayWriter();
break;
}
@@ -417,9 +418,8 @@
if (lastCh == '$') {
ttext.write('$');
}
- char[] bufCopy = ttext.toCharArray();
- if (bufCopy.length > 0) {
- new Node.TemplateText(bufCopy, start, current);
+ if (ttext.size() > 0) {
+ new Node.TemplateText(ttext.toString(), start, current);
}
}
}
@@ -482,9 +482,7 @@
if (!inDTD) {
Mark start = new Mark(path, locator.getLineNumber(),
locator.getColumnNumber());
- char[] bufCopy = new char[len];
- System.arraycopy(buf, offset, bufCopy, 0, len);
- new Node.Comment(bufCopy, start, current);
+ new Node.Comment(new String(buf, offset, len), start, current);
}
}
1.12 +5 -7
jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/JspReader.java
Index: JspReader.java
===================================================================
RCS file:
/home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/JspReader.java,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- JspReader.java 6 Nov 2002 20:14:19 -0000 1.11
+++ JspReader.java 5 Dec 2002 17:56:43 -0000 1.12
@@ -171,7 +171,7 @@
* Gets Content until the next potential JSP element. Because all elements
* begin with a '<' we can just move until we see the next one.
*/
- char[] nextContent() {
+ String nextContent() {
int cur_cursor = current.cursor;
int len = current.stream.length;
char ch;
@@ -201,13 +201,11 @@
}
len = current.cursor - cur_cursor;
- char[] content = new char[len];
- System.arraycopy(current.stream, cur_cursor, content, 0, len);
-
- return content;
+
+ return new String(current.stream, cur_cursor, len);
}
- char[] getText(Mark start, Mark stop) throws JasperException {
+ String getText(Mark start, Mark stop) throws JasperException {
Mark oldstart = mark();
reset(start);
CharArrayWriter caw = new CharArrayWriter();
@@ -215,7 +213,7 @@
caw.write(nextChar());
caw.close();
reset(oldstart);
- return caw.toCharArray();
+ return caw.toString();
}
int peekChar() {
1.45 +27 -36
jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/Node.java
Index: Node.java
===================================================================
RCS file:
/home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/Node.java,v
retrieving revision 1.44
retrieving revision 1.45
diff -u -r1.44 -r1.45
--- Node.java 5 Dec 2002 02:39:03 -0000 1.44
+++ Node.java 5 Dec 2002 17:56:43 -0000 1.45
@@ -82,7 +82,7 @@
protected Attributes attrs;
protected Nodes body;
- protected char[] text;
+ protected String text;
protected Mark startMark;
protected int beginJavaLine;
protected int endJavaLine;
@@ -121,7 +121,7 @@
* @param start The location of the jsp page
* @param parent The enclosing node
*/
- public Node(char[] text, Mark start, Node parent) {
+ public Node(String text, Mark start, Node parent) {
this.text = text;
this.startMark = start;
this.isDummy = (start == null);
@@ -247,7 +247,7 @@
this.body = body;
}
- public char[] getText() {
+ public String getText() {
return text;
}
@@ -549,7 +549,7 @@
*/
public static class Comment extends Node {
- public Comment(char[] text, Mark start, Node parent) {
+ public Comment(String text, Mark start, Node parent) {
super(text, start, parent);
}
@@ -563,7 +563,7 @@
*/
public static abstract class ScriptingElement extends Node {
- public ScriptingElement(char[] text, Mark start, Node parent) {
+ public ScriptingElement(String text, Mark start, Node parent) {
super(text, start, parent);
}
@@ -578,16 +578,14 @@
* TemplateText nodes in its body. This method handles either case.
* @return The text string
*/
- public char[] getText() {
- char[] ret = text;
+ public String getText() {
+ String ret = text;
if ((ret == null) && (body != null)) {
- CharArrayWriter chars = new CharArrayWriter();
- int size = body.size();
- for (int i=0; i<size; i++) {
- chars.write(body.getNode(i).getText(), 0,
- body.getNode(i).getText().length);
+ StringBuffer buf = new StringBuffer();
+ for (int i=0; i<body.size(); i++) {
+ buf.append(body.getNode(i).getText());
}
- ret = chars.toCharArray();
+ ret = buf.toString();
}
return ret;
}
@@ -598,7 +596,7 @@
*/
public static class Declaration extends ScriptingElement {
- public Declaration(char[] text, Mark start, Node parent) {
+ public Declaration(String text, Mark start, Node parent) {
super(text, start, parent);
}
@@ -617,7 +615,7 @@
*/
public static class Expression extends ScriptingElement {
- public Expression(char[] text, Mark start, Node parent) {
+ public Expression(String text, Mark start, Node parent) {
super(text, start, parent);
}
@@ -635,7 +633,7 @@
*/
public static class Scriptlet extends ScriptingElement {
- public Scriptlet(char[] text, Mark start, Node parent) {
+ public Scriptlet(String text, Mark start, Node parent) {
super(text, start, parent);
}
@@ -654,7 +652,7 @@
*/
public static class ELExpression extends Node {
- public ELExpression(char[] text, Mark start, Node parent) {
+ public ELExpression(String text, Mark start, Node parent) {
super(text, start, parent);
}
@@ -706,7 +704,7 @@
*/
public static class FallBackAction extends Node {
- public FallBackAction(Mark start, char[] text, Node parent) {
+ public FallBackAction(Mark start, String text, Node parent) {
super(text, start, parent);
}
@@ -999,7 +997,7 @@
private Integer numCount;
private boolean useTagPlugin;
/**
- * The following two fields are use for holding the Java
+ * The following two fields are used for holding the Java
* scriptlets that the tag plugins may generate. Meaningful
* only if useTagPlugin is true;
*/
@@ -1397,7 +1395,7 @@
*/
public static class TemplateText extends Node {
- public TemplateText(char[] text, Mark start, Node parent) {
+ public TemplateText(String text, Mark start, Node parent) {
super(text, start, parent);
}
@@ -1409,29 +1407,22 @@
* Trim all whitespace from the left of the template text
*/
public void ltrim() {
- // Whitespace logic borrowed from JspReader.isSpace
int index = 0;
- while ((index < text.length) && (text[index] <= ' ')) {
+ while ((index < text.length()) && (text.charAt(index) <= ' ')) {
index++;
}
- int size = text.length - index;
- char[] newText = new char[size];
- System.arraycopy(text, index, newText, 0, size);
- text = newText;
+ text = text.substring(index);
}
/**
* Trim all whitespace from the right of the template text
*/
public void rtrim() {
- // Whitespace logic borrowed from JspReader.isSpace
- int size = text.length;
- while( (size > 0) && (text[size-1] <= ' ') ) {
- size--;
+ int index = text.length();
+ while( (index > 0) && (text.charAt(index-1) <= ' ') ) {
+ index--;
}
- char[] newText = new char[size];
- System.arraycopy( text, 0, newText, 0, size );
- text = newText;
+ text = text.substring(0, index);
}
}
1.19 +16 -15
jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/PageDataImpl.java
Index: PageDataImpl.java
===================================================================
RCS file:
/home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/PageDataImpl.java,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -r1.18 -r1.19
--- PageDataImpl.java 8 Nov 2002 03:03:01 -0000 1.18
+++ PageDataImpl.java 5 Dec 2002 17:56:43 -0000 1.19
@@ -411,7 +411,7 @@
private void appendTag(String tag,
Attributes attrs,
Node.Nodes body,
- char[] text) throws JasperException {
+ String text) throws JasperException {
buf.append("<").append(tag);
buf.append("\n");
@@ -578,7 +578,7 @@
buf.append("/>\n");
}
- private void appendText(char[] text, boolean createJspTextElement) {
+ private void appendText(String text, boolean createJspTextElement) {
if (createJspTextElement) {
buf.append("<").append(JSP_TEXT);
buf.append("\n");
@@ -600,7 +600,7 @@
* Appends the given text as a CDATA section to the XML view, unless
* the text has already been marked as CDATA.
*/
- private void appendCDATA(char[] text) {
+ private void appendCDATA(String text) {
buf.append(CDATA_START_SECTION);
buf.append(escapeCDATA(text));
buf.append(CDATA_END_SECTION);
@@ -610,13 +610,14 @@
* Escapes any occurrences of "]]>" (by replacing them with "]]>")
* within the given text, so it can be included in a CDATA section.
*/
- private char[] escapeCDATA(char[] text) {
- CharArrayWriter result = new CharArrayWriter(text.length);
- for (int i=0; i<text.length; i++) {
- if (((i+2) < text.length)
- && (text[i] == ']')
- && (text[i+1] == ']')
- && (text[i+2] == '>')) {
+ private String escapeCDATA(String text) {
+ int len = text.length();
+ CharArrayWriter result = new CharArrayWriter(len);
+ for (int i=0; i<len; i++) {
+ if (((i+2) < len)
+ && (text.charAt(i) == ']')
+ && (text.charAt(i+1) == ']')
+ && (text.charAt(i+2) == '>')) {
// match found
result.write(']');
result.write(']');
@@ -626,10 +627,10 @@
result.write(';');
i += 2;
} else {
- result.write(text[i]);
+ result.write(text.charAt(i));
}
}
- return result.toCharArray();
+ return result.toString();
}
/*
1.41 +31 -32
jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/Parser.java
Index: Parser.java
===================================================================
RCS file:
/home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/Parser.java,v
retrieving revision 1.40
retrieving revision 1.41
diff -u -r1.40 -r1.41
--- Parser.java 23 Nov 2002 01:49:40 -0000 1.40
+++ Parser.java 5 Dec 2002 17:56:43 -0000 1.41
@@ -275,19 +275,21 @@
* | '\>'
* | Char
*/
- private String parseQuoted(char[] tx) {
+ private String parseQuoted(String tx) {
StringBuffer buf = new StringBuffer();
- int size = tx.length;
+ int size = tx.length();
int i = 0;
while (i < size) {
- char ch = tx[i];
+ char ch = tx.charAt(i);
if (ch == '&') {
- if (i+5 < size && tx[i+1] == 'a' && tx[i+2] == 'p' &&
- tx[i+3] == 'o' && tx[i+4] == 's' && tx[i+5] == ';') {
+ if (i+5 < size && tx.charAt(i+1) == 'a'
+ && tx.charAt(i+2) == 'p' && tx.charAt(i+3) == 'o'
+ && tx.charAt(i+4) == 's' && tx.charAt(i+5) == ';') {
buf.append('\'');
i += 6;
- } else if (i+5 < size && tx[i+1] == 'q' && tx[i+2] == 'u' &&
- tx[i+3] == 'o' && tx[i+4] == 't' && tx[i+5] == ';') {
+ } else if (i+5 < size && tx.charAt(i+1) == 'q'
+ && tx.charAt(i+2) == 'u' && tx.charAt(i+3) == 'o'
+ && tx.charAt(i+4) == 't' && tx.charAt(i+5) == ';') {
buf.append('"');
i += 6;
} else {
@@ -295,7 +297,7 @@
++i;
}
} else if (ch == '\\' && i+1 < size) {
- ch = tx[i+1];
+ ch = tx.charAt(i+1);
if (ch == '\\' || ch == '\"' || ch == '\'' || ch == '>') {
buf.append(ch);
i += 2;
@@ -311,13 +313,14 @@
return buf.toString();
}
- private char[] parseScriptText(char[] tx) {
+ private String parseScriptText(String tx) {
CharArrayWriter cw = new CharArrayWriter();
- int size = tx.length;
+ int size = tx.length();
int i = 0;
while (i < size) {
- char ch = tx[i];
- if (i+2 < size && ch == '%' && tx[i+1] == '\\' && tx[i+2] == '>') {
+ char ch = tx.charAt(i);
+ if (i+2 < size && ch == '%' && tx.charAt(i+1) == '\\'
+ && tx.charAt(i+2) == '>') {
cw.write('%');
cw.write('>');
i += 3;
@@ -327,7 +330,7 @@
}
}
cw.close();
- return cw.toCharArray();
+ return cw.toString();
}
/*
@@ -637,7 +640,7 @@
}
new Node.Declaration(parseScriptText(reader.getText(start, stop)),
- start, parent);
+ start, parent);
}
/*
@@ -662,7 +665,7 @@
}
new Node.Declaration(parseScriptText(reader.getText(start, stop)),
- start, parent);
+ start, parent);
}
}
@@ -677,7 +680,7 @@
}
new Node.Expression(parseScriptText(reader.getText(start, stop)),
- start, parent);
+ start, parent);
}
/*
@@ -702,7 +705,7 @@
}
new Node.Expression(parseScriptText(reader.getText(start, stop)),
- start, parent);
+ start, parent);
}
}
@@ -748,7 +751,7 @@
}
new Node.Scriptlet(parseScriptText(reader.getText(start, stop)),
- start, parent);
+ start, parent);
}
/*
@@ -773,7 +776,7 @@
}
new Node.Scriptlet(parseScriptText(reader.getText(start, stop)),
- start, parent );
+ start, parent );
}
}
@@ -1079,8 +1082,8 @@
err.jspError(start, "jsp.error.unterminated",
"<jsp:fallback");
}
- char[] text = reader.getText(bodyStart, bodyEnd);
- new Node.FallBackAction(start, text, parent);
+ new Node.FallBackAction(start, reader.getText(bodyStart, bodyEnd),
+ parent);
}
else {
err.jspError( reader.mark(), "jsp.error.unterminated",
@@ -1296,12 +1299,8 @@
// Quoting in template text is handled here.
// JSP2.6 "A literal <% is quoted by <\%"
if (reader.matches("<\\%")) {
- char[] content = reader.nextContent();
- char[] text = new char[content.length + 2];
- text[0] = '<';
- text[1] = '%';
- System.arraycopy(content, 0, text, 2, content.length);
- new Node.TemplateText(text, start, parent);
+ String content = reader.nextContent();
+ new Node.TemplateText("<%" + content, start, parent);
} else {
new Node.TemplateText(reader.nextContent(), start, parent);
}
@@ -1335,7 +1334,7 @@
if( ch == '<' ) break;
if( (lastCh == '$') && (ch == '{') ) {
// Create a template text node
- new Node.TemplateText( ttext.toCharArray(), start, parent);
+ new Node.TemplateText( ttext.toString(), start, parent);
// Mark and parse the EL expression and create its node:
start = reader.mark();
@@ -1368,7 +1367,7 @@
}
// This could happen if we parsed an EL expression and then
// there was no more template text (see above).
- new Node.TemplateText( ttext.toCharArray(), start, parent );
+ new Node.TemplateText( ttext.toString(), start, parent );
}
if( !reader.matchesETagWithoutLessThan( "jsp:text" ) ) {
1.5 +4 -4
jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/TagPluginManager.java
Index: TagPluginManager.java
===================================================================
RCS file:
/home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/TagPluginManager.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- TagPluginManager.java 5 Dec 2002 02:39:03 -0000 1.4
+++ TagPluginManager.java 5 Dec 2002 17:56:43 -0000 1.5
@@ -206,7 +206,7 @@
public void generateBody() {
// Since we'll generate the body anyway, this is really a nop,
- // except for the fact that it let us put the Java sources the
+ // except for the fact that it lets us put the Java sources the
// plugins produce in the correct order (w.r.t the body).
curNodes = node.getAtETag();
}
1.4 +4 -4
jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/tagplugin/TagPlugin.java
Index: TagPlugin.java
===================================================================
RCS file:
/home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/tagplugin/TagPlugin.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- TagPlugin.java 4 Dec 2002 01:41:19 -0000 1.3
+++ TagPlugin.java 5 Dec 2002 17:56:43 -0000 1.4
@@ -64,7 +64,7 @@
/**
* This interface is to be implemented by the plugin author, to supply
* an alternate implementation of the tag handlers. It can be used to
- * specify the Java codes to be generated when a tag is referenced.
+ * specify the Java codes to be generated when a tag is invoked.
*
* An implementation of this interface must be registered in a file
* named "tagPlugins.xml" under WEB-INF.
1.5 +7 -7
jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/tagplugin/TagPluginContext.java
Index: TagPluginContext.java
===================================================================
RCS file:
/home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/tagplugin/TagPluginContext.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- TagPluginContext.java 5 Dec 2002 02:39:03 -0000 1.4
+++ TagPluginContext.java 5 Dec 2002 17:56:43 -0000 1.5
@@ -66,13 +66,13 @@
/**
* This interface allows the plugin author to make inqueries about the
* properties of the current tag, and to use Jasper resources to generate
- * direct Java codes in place of tag handler invokations.
+ * direct Java codes in place of tag handler invocations.
*/
public interface TagPluginContext {
/**
- * @return true if the body of the tag is scriptless.
- */
+ * @return true if the body of the tag is scriptless.
+ */
boolean isScriptless();
/**
@@ -102,7 +102,7 @@
* Abandon optimization for this tag handler, and instruct
* Jaser to generate the tag handler calls, as usual.
* Should be invoked if errors are detected, or when the tag body
- * is judged to be too compilicated for optimization.
+ * is deemed too compilicated for optimization.
*/
void dontUseTagPlugin();
}
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>