Permalink
Browse files

Mini optimisations

  • Loading branch information...
1 parent 64f7110 commit dbe01fe8410ce30523c754793ff02d0bd0ca9ee3 @jhy jhy committed Aug 7, 2010
@@ -13,7 +13,7 @@
* <p/>
* Draft implementation. Do not consume.
*/
-public class Entities {
+class Entities {
public enum EscapeMode {
base, extended
}
@@ -35,11 +35,11 @@ static String escape(String string, CharsetEncoder encoder, EscapeMode escapeMod
for (int pos = 0; pos < string.length(); pos++) {
Character c = string.charAt(pos);
if (map.containsKey(c))
- accum.append("&").append(map.get(c)).append(";");
+ accum.append('&').append(map.get(c)).append(';');
else if (encoder.canEncode(c))
- accum.append(c);
+ accum.append(c.charValue());
else
- accum.append("&#").append((int) c).append(";");
+ accum.append("&#").append((int) c).append(';');
}
return accum.toString();
@@ -397,7 +397,8 @@ public void head(Node node, int depth) {
}
public void tail(Node node, int depth) {
- node.outerHtmlTail(accum, depth, out);
+ if (!node.nodeName().equals("#text")) // saves a void hit.
+ node.outerHtmlTail(accum, depth, out);
}
}
}
@@ -12,7 +12,7 @@
@author Jonathan Hedley, jonathan@hedley.net */
public class TextNode extends Node {
private static final String TEXT_KEY = "text";
- private static final Pattern spaceNormaliser = Pattern.compile("\\s{2,}|(\\r\\n|\\r|\\n)");
+ private static final Pattern spaceNormaliser = Pattern.compile("\\s{2,}|(?:\\r\\n|\\r|\\n)");
/**
Create a new TextNode representing the supplied (unencoded) text).

0 comments on commit dbe01fe

Please sign in to comment.