7010528: javadoc performance regression
authorbpatel
Thu, 13 Jan 2011 21:28:38 -0800
changeset 8035 465338fc0c82
parent 8034 d3b29ef9c062
child 8036 17b976649c61
7010528: javadoc performance regression Reviewed-by: jjg
langtools/src/share/classes/com/sun/tools/doclets/formats/html/markup/HtmlTree.java
langtools/src/share/classes/com/sun/tools/doclets/internal/toolkit/Content.java
--- a/langtools/src/share/classes/com/sun/tools/doclets/formats/html/markup/HtmlTree.java	Thu Jan 13 11:48:10 2011 -0800
+++ b/langtools/src/share/classes/com/sun/tools/doclets/formats/html/markup/HtmlTree.java	Thu Jan 13 21:28:38 2011 -0800
@@ -755,22 +755,30 @@
         if (!isInline() && !endsWithNewLine(contentBuilder))
             contentBuilder.append(DocletConstants.NL);
         String tagString = htmlTag.toString();
-        contentBuilder.append("<" + tagString);
+        contentBuilder.append("<");
+        contentBuilder.append(tagString);
         Iterator<HtmlAttr> iterator = attrs.keySet().iterator();
         HtmlAttr key;
         String value = "";
         while (iterator.hasNext()) {
             key = iterator.next();
             value = attrs.get(key);
-            contentBuilder.append(" " + key.toString());
-            if (!value.isEmpty())
-                contentBuilder.append("=\"" + value + "\"");
+            contentBuilder.append(" ");
+            contentBuilder.append(key.toString());
+            if (!value.isEmpty()) {
+                contentBuilder.append("=\"");
+                contentBuilder.append(value);
+                contentBuilder.append("\"");
+            }
         }
         contentBuilder.append(">");
         for (Content c : content)
             c.write(contentBuilder);
-        if (htmlTag.endTagRequired())
-            contentBuilder.append("</" + tagString + ">");
+        if (htmlTag.endTagRequired()) {
+            contentBuilder.append("</");
+            contentBuilder.append(tagString);
+            contentBuilder.append(">");
+        }
         if (!isInline())
             contentBuilder.append(DocletConstants.NL);
     }
--- a/langtools/src/share/classes/com/sun/tools/doclets/internal/toolkit/Content.java	Thu Jan 13 11:48:10 2011 -0800
+++ b/langtools/src/share/classes/com/sun/tools/doclets/internal/toolkit/Content.java	Thu Jan 13 21:28:38 2011 -0800
@@ -99,8 +99,24 @@
      * @param contentBuilder content to test for newline character at the end
      * @return true if the content ends with newline.
      */
-    public boolean endsWithNewLine(StringBuilder contentBuilder) {
-        return ((contentBuilder.length() == 0) ||
-                (contentBuilder.toString().endsWith(DocletConstants.NL)));
+    protected boolean endsWithNewLine(StringBuilder contentBuilder) {
+        int contentLength = contentBuilder.length();
+        if (contentLength == 0) {
+            return true;
+        }
+        int nlLength = DocletConstants.NL.length();
+        if (contentLength < nlLength) {
+            return false;
+        }
+        int contentIndex = contentLength - 1;
+        int nlIndex = nlLength - 1;
+        while (nlIndex >= 0) {
+            if (contentBuilder.charAt(contentIndex) != DocletConstants.NL.charAt(nlIndex)) {
+                return false;
+            }
+            contentIndex--;
+            nlIndex--;
+        }
+        return true;
     }
 }