mrglavas    2004/07/08 19:51:06

  Modified:    java/src/org/apache/html/dom HTMLOptionElementImpl.java
                        HTMLScriptElementImpl.java
                        HTMLTitleElementImpl.java
  Log:
  Performance fix: Replace building of strings 

  using concatenation in while loops with StringBuffers.

  

  Thanks to Dave Brosius for the patch.
  
  Revision  Changes    Path
  1.8       +7 -7      
xml-xerces/java/src/org/apache/html/dom/HTMLOptionElementImpl.java
  
  Index: HTMLOptionElementImpl.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xerces/java/src/org/apache/html/dom/HTMLOptionElementImpl.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- HTMLOptionElementImpl.java        24 Feb 2004 23:34:00 -0000      1.7
  +++ HTMLOptionElementImpl.java        9 Jul 2004 02:51:06 -0000       1.8
  @@ -53,20 +53,20 @@
     
       public String getText()
       {
  -        Node    child;
  -        String    text;
  +        Node child;
  +        StringBuffer text = new StringBuffer();
           
           // Find the Text nodes contained within this element and return their
           // concatenated value. Required to go around comments, entities, etc.
           child = getFirstChild();
  -        text = "";
           while ( child != null )
           {
  -            if ( child instanceof Text )
  -                text = text + ( (Text) child ).getData();
  +            if ( child instanceof Text ) {
  +                text.append(( (Text) child ).getData());
  +            }
               child = child.getNextSibling();
           }
  -        return text;
  +        return text.toString();
       }
       
       
  
  
  
  1.8       +7 -7      
xml-xerces/java/src/org/apache/html/dom/HTMLScriptElementImpl.java
  
  Index: HTMLScriptElementImpl.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xerces/java/src/org/apache/html/dom/HTMLScriptElementImpl.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- HTMLScriptElementImpl.java        24 Feb 2004 23:34:00 -0000      1.7
  +++ HTMLScriptElementImpl.java        9 Jul 2004 02:51:06 -0000       1.8
  @@ -35,20 +35,20 @@
       
       public String getText()
       {
  -        Node    child;
  -        String    text;
  +        Node child;
  +        StringBuffer text = new StringBuffer();
           
           // Find the Text nodes contained within this element and return their
           // concatenated value. Required to go around comments, entities, etc.
           child = getFirstChild();
  -        text = "";
           while ( child != null )
           {
  -            if ( child instanceof Text )
  -                text = text + ( (Text) child ).getData();
  +            if ( child instanceof Text ) {
  +                text.append(( (Text) child ).getData());
  +            }
               child = child.getNextSibling();
           }
  -        return text;
  +        return text.toString();
       }
       
       
  
  
  
  1.8       +7 -7      
xml-xerces/java/src/org/apache/html/dom/HTMLTitleElementImpl.java
  
  Index: HTMLTitleElementImpl.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xerces/java/src/org/apache/html/dom/HTMLTitleElementImpl.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- HTMLTitleElementImpl.java 24 Feb 2004 23:34:01 -0000      1.7
  +++ HTMLTitleElementImpl.java 9 Jul 2004 02:51:06 -0000       1.8
  @@ -35,20 +35,20 @@
       
       public String getText()
       {
  -        Node    child;
  -        String    text;
  +        Node child;
  +        StringBuffer text = new StringBuffer();
           
           // Find the Text nodes contained within this element and return their
           // concatenated value. Required to go around comments, entities, etc.
           child = getFirstChild();
  -        text = "";
           while ( child != null )
           {
  -            if ( child instanceof Text )
  -                text = text + ( (Text) child ).getData();
  +            if ( child instanceof Text ) {
  +                text.append(( (Text) child ).getData());
  +            }
               child = child.getNextSibling();
           }
  -        return text;
  +        return text.toString();
       }
       
       
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to