Improve performance (by ~10% on Sun Java 1.3.1_08) for the method escapeEntities(String str, Entities entities) by using the existing StringBuffer instead of String + to the same buffer.
git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/lang/trunk@137322 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
713af7b691
commit
cc411622e9
|
@ -74,7 +74,7 @@
|
|||
* @author <a href="sean@boohai.com">Sean Brown</a>
|
||||
* @author <a href="mailto:ggregory@seagullsw.com">Gary Gregory</a>
|
||||
* @since 2.0
|
||||
* @version $Id: StringEscapeUtils.java,v 1.10 2003/05/16 19:00:07 ggregory Exp $
|
||||
* @version $Id: StringEscapeUtils.java,v 1.11 2003/05/18 00:10:38 ggregory Exp $
|
||||
*/
|
||||
public class StringEscapeUtils {
|
||||
|
||||
|
@ -477,12 +477,16 @@ private static String escapeEntities(String str, Entities entities) {
|
|||
if (entity == null) {
|
||||
if (((int) ch) > 0x7F) {
|
||||
int intValue = ((int) ch);
|
||||
buf.append("&#" + intValue + ";");
|
||||
buf.append("&#");
|
||||
buf.append(intValue);
|
||||
buf.append(';');
|
||||
} else {
|
||||
buf.append(ch);
|
||||
}
|
||||
} else {
|
||||
buf.append("&" + entity + ";");
|
||||
buf.append('&');
|
||||
buf.append(entity);
|
||||
buf.append(';');
|
||||
}
|
||||
}
|
||||
return buf.toString();
|
||||
|
@ -507,7 +511,9 @@ private static String unescapeEntities(String str, Entities entities) {
|
|||
iso = entities.entityValue(entity);
|
||||
}
|
||||
if (iso == null) {
|
||||
buf.append("&" + entity + ";");
|
||||
buf.append('&');
|
||||
buf.append(entity);
|
||||
buf.append(';');
|
||||
} else {
|
||||
buf.append((char) (iso.intValue()));
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue