ASF Bugzilla – Attachment 29242 Details for
Bug 53713
Performance tuning solution for JspReader
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
Patch for JspReader.java
JspReader.diff (text/plain), 8.11 KB, created by
Sheldon Shao
on 2012-08-17 14:29:52 UTC
(
hide
)
Description:
Patch for JspReader.java
Filename:
MIME Type:
Creator:
Sheldon Shao
Created:
2012-08-17 14:29:52 UTC
Size:
8.11 KB
patch
obsolete
>Index: org/apache/jasper/compiler/JspReader.java >=================================================================== >--- org/apache/jasper/compiler/JspReader.java (revision 1370136) >+++ org/apache/jasper/compiler/JspReader.java (working copy) >@@ -191,6 +191,70 @@ > } > return ch; > } >+ >+ /** >+ * A better performance solution for calling {@link #mark()} & {@link #nextChar()} >+ * Assume that the parameter mark should be used internal. >+ * >+ * @param mark >+ * @return >+ * @throws JasperException >+ */ >+ int nextChar(Mark mark) throws JasperException { >+ if (!hasMoreInput()) >+ return -1; >+ >+ int ch = current.stream[current.cursor]; >+ >+ mark.init(current, singleFile); >+ >+ current.cursor++; >+ >+ if (ch == '\n') { >+ current.line++; >+ current.col = 0; >+ } else { >+ current.col++; >+ } >+ return ch; >+ } >+ >+ /** >+ * Search the given character, If it was found, then mark the current cursor and the cursor point to next character >+ * >+ * @param mark >+ * @return >+ * @throws JasperException >+ */ >+ Boolean indexOf(char c, Mark mark) throws JasperException { >+ if (!hasMoreInput()) >+ return null; >+ >+ int end = current.stream.length; >+ int ch; >+ int line = current.line; >+ int col = current.col; >+ int i = current.cursor; >+ for(; i < end; i ++) { >+ ch = current.stream[i]; >+ >+ if (ch == c) { >+ mark.update(i, line, col); >+ } >+ if (ch == '\n') { >+ line++; >+ col = 0; >+ } else { >+ col++; >+ } >+ if (ch == c) { >+ current.update(i+1, line, col); >+ return Boolean.TRUE; >+ } >+ } >+ current.update(i, line, col); >+ return Boolean.FALSE; >+ } > > /** > * Back up the current cursor by one char, assumes current.cursor > 0, >@@ -205,10 +269,10 @@ > Mark oldstart = mark(); > reset(start); > CharArrayWriter caw = new CharArrayWriter(); >- while (!stop.equals(mark())) >+ while (!markEquals(stop)) > caw.write(nextChar()); > caw.close(); >- reset(oldstart); >+ setCurrent(oldstart); > return caw.toString(); > } > >@@ -221,10 +285,31 @@ > Mark mark() { > return new Mark(current); > } >+ >+ /** >+ * This method can avoid to call {@link #mark()} when doing comparison. >+ * It is used in {@link #getText(Mark, Mark)} >+ * >+ * @param another >+ * @return >+ */ >+ boolean markEquals(Mark another) { >+ return another.equals(current); >+ } > > void reset(Mark mark) { > current = new Mark(mark); > } >+ >+ /** >+ * Similar with {@link #reset(Mark)}, however, no new Mark will be created. >+ * So the parameter mark must NOT be used in other place. >+ * >+ * @param mark >+ */ >+ void setCurrent(Mark mark) { >+ current = mark; >+ } > > /** > * search the stream for a match to a string >@@ -234,17 +319,42 @@ > * false</strong> otherwise, position in stream unchanged. > */ > boolean matches(String string) throws JasperException { >- Mark mark = mark(); >- int ch = 0; >- int i = 0; >- do { >- ch = nextChar(); >- if (((char) ch) != string.charAt(i++)) { >- reset(mark); >- return false; >- } >- } while (i < string.length()); >- return true; >+ int len = string.length(); >+ int cursor = current.cursor; >+ int streamSize = current.stream.length; >+ if (cursor + len < streamSize) {//Try to scan in memory >+ int line = current.line; >+ int col = current.col; >+ int ch; >+ int i = 0; >+ for(; i < len; i ++) { >+ ch = current.stream[i+cursor]; >+ if (string.charAt(i) != ch) { >+ return false; >+ } >+ if (ch == '\n') { >+ line ++; >+ col = 0; >+ } else { >+ col++; >+ } >+ } >+ current.update(i+cursor, line, col); >+ return true; >+ } >+ else { >+ Mark mark = mark(); >+ int ch = 0; >+ int i = 0; >+ do { >+ ch = nextChar(); >+ if (((char) ch) != string.charAt(i++)) { >+ setCurrent(mark); >+ return false; >+ } >+ } while (i < len); >+ return true; >+ } > } > > boolean matchesETag(String tagName) throws JasperException { >@@ -256,7 +366,7 @@ > if (nextChar() == '>') > return true; > >- reset(mark); >+ setCurrent(mark); > return false; > } > >@@ -271,7 +381,7 @@ > if (nextChar() == '>') > return true; > >- reset(mark); >+ setCurrent(mark); > return false; > } > >@@ -290,7 +400,7 @@ > skipSpaces(); > boolean result = matches( s ); > if( !result ) { >- reset( mark ); >+ setCurrent( mark ); > } > > return result; >@@ -315,25 +425,31 @@ > * otherwise. > */ > Mark skipUntil(String limit) throws JasperException { >- Mark ret = null; >+ Mark ret = mark(); > int limlen = limit.length(); >- int ch; > >+ char firstChar = limit.charAt(0); >+ Boolean result = null; >+ Mark restart = null; > skip: >- for (ret = mark(), ch = nextChar() ; ch != -1 ; >- ret = mark(), ch = nextChar()) { >- if (ch == limit.charAt(0)) { >- Mark restart = mark(); >- for (int i = 1 ; i < limlen ; i++) { >- if (peekChar() == limit.charAt(i)) >- nextChar(); >- else { >- reset(restart); >- continue skip; >- } >- } >- return ret; >- } >+ while((result = indexOf(firstChar, ret)) != null) { >+ if (result.booleanValue()) { >+ if (restart != null) { >+ restart.init(current, singleFile); >+ } >+ else { >+ restart = mark(); >+ } >+ for (int i = 1 ; i < limlen ; i++) { >+ if (peekChar() == limit.charAt(i)) >+ nextChar(); >+ else { >+ setCurrent(restart); >+ continue skip; >+ } >+ } >+ return ret; >+ } > } > return null; > } >@@ -349,18 +465,18 @@ > * otherwise. > */ > Mark skipUntilIgnoreEsc(String limit) throws JasperException { >- Mark ret = null; >+ Mark ret = mark(); > int limlen = limit.length(); > int ch; > int prev = 'x'; // Doesn't matter > >+ char firstChar = limit.charAt(0); > skip: >- for (ret = mark(), ch = nextChar() ; ch != -1 ; >- ret = mark(), prev = ch, ch = nextChar()) { >+ for (ch = nextChar(ret) ; ch != -1 ; prev = ch, ch = nextChar(ret)) { > if (ch == '\\' && prev == '\\') { > ch = 0; // Double \ is not an escape char anymore > } >- else if (ch == limit.charAt(0) && prev != '\\') { >+ else if (ch == firstChar && prev != '\\') { > for (int i = 1 ; i < limlen ; i++) { > if (peekChar() == limit.charAt(i)) > nextChar(); >@@ -477,10 +593,10 @@ > Mark mark = mark(); > if (((ch = nextChar()) == '>') > || ((ch == '-') && (nextChar() == '>'))) { >- reset(mark); >+ setCurrent(mark); > return true; > } else { >- reset(mark); >+ setCurrent(mark); > return false; > } > }
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 53713
:
29223
|
29224
| 29242 |
29243
|
29244
|
29245
|
29246