Hi,
I noticed that TagUtils.filter does quite a lot of unnecessary work in the common case (assuming the common case is when no character translations are required). In such a case one can of course simply return the original string.
I have written a version of TagUtils.filter that is optimised for the common case. It is roughly 2-3 times faster and doesn't create so many objects. Obviously this method isn't a huge bottleneck or anything but even so it may be worth including in the source tree: no sense throwing away cpu cycles :-)
Anyways, the new method is appended to this message. Apologies for not including a diff, I don't have easy access to CVS at the moment. The change is pretty simple and localised.
cheers, Peter McKenzie
public String filter(String value) {
if (value == null) { return (null); }
char content[] = value.toCharArray(); StringBuffer result = null;
int i = 0;
scanLoop: for (; i < content.length; i++) {
switch (content[i]) {
case '<':
case '>':
case '&':
case '"':
case '\'':
result = new StringBuffer(content.length + 50);
result.append(content, 0, i);
break scanLoop;
default:
}
}
if (result == null) {
// No special characters found so just return the original string.
return value;
}
for (; i < content.length; i++) { switch (content[i]) { case '<': result.append("<"); break; case '>': result.append(">"); break; case '&': result.append("&"); break; case '"': result.append("""); break; case '\'': result.append("'"); break; default: result.append(content[i]); } } return result.toString(); }
_________________________________________________________________ Need more speed? Get Xtra JetStream @ http://xtra.co.nz/jetstream
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]