changeset 881:a466f00c5cd2

7010528: javadoc performance regression Reviewed-by: jjg
author bpatel
date Thu, 13 Jan 2011 21:28:38 -0800
parents d33d8c381aa1
children 2d5aff89aaa3
files src/share/classes/com/sun/tools/doclets/formats/html/markup/HtmlTree.java src/share/classes/com/sun/tools/doclets/internal/toolkit/Content.java
diffstat 2 files changed, 33 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/com/sun/tools/doclets/formats/html/markup/HtmlTree.java	Thu Jan 13 11:48:10 2011 -0800
+++ b/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/src/share/classes/com/sun/tools/doclets/internal/toolkit/Content.java	Thu Jan 13 11:48:10 2011 -0800
+++ b/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;
     }
 }