You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xerces.apache.org by el...@apache.org on 2003/07/29 01:27:36 UTC

cvs commit: xml-xerces/java/src/org/apache/xerces/util XMLStringBuffer.java

elena       2003/07/28 16:27:36

  Modified:    java/src/org/apache/xerces/util XMLStringBuffer.java
  Log:
  Performance patch by Thomas DeWeese from Apache Batik:
  the patch makes XMLStringBuffer use array doubling instead of a fixed 32 char increment.
  For one of Batik test files with a 500Kb embedded image, this patch reduces
  parse time from ~4.5min to .8 sec (n*log(n) is much better than n^2).
  This is not even a particularly extreme case for SVG.
  
  Revision  Changes    Path
  1.5       +15 -13    xml-xerces/java/src/org/apache/xerces/util/XMLStringBuffer.java
  
  Index: XMLStringBuffer.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/util/XMLStringBuffer.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- XMLStringBuffer.java	29 Jan 2002 01:15:18 -0000	1.4
  +++ XMLStringBuffer.java	28 Jul 2003 23:27:36 -0000	1.5
  @@ -91,15 +91,6 @@
       public static final int DEFAULT_SIZE = 32;
   
       //
  -    // Data
  -    //
  -
  -    // private
  -
  -    /** One char buffer. */
  -    private char[] fOneCharBuffer = new char[1];
  -
  -    //
       // Constructors
       //
   
  @@ -159,8 +150,16 @@
        * @param c 
        */
       public void append(char c) {
  -        fOneCharBuffer[0] = c;
  -        append(fOneCharBuffer, 0, 1);
  +        if (this.length + 1 > this.ch.length) {
  +                    int newLength = this.ch.length*2;
  +                    if (newLength < this.ch.length + DEFAULT_SIZE)
  +                        newLength = this.ch.length + DEFAULT_SIZE;
  +                    char[] newch = new char[newLength];
  +                    System.arraycopy(this.ch, 0, newch, 0, this.length);
  +                    this.ch = newch;
  +        }
  +        this.ch[this.length] = c;
  +        this.length++;
       } // append(char)
   
       /**
  @@ -171,7 +170,10 @@
       public void append(String s) {
           int length = s.length();
           if (this.length + length > this.ch.length) {
  -            char[] newch = new char[this.ch.length + length + DEFAULT_SIZE];
  +            int newLength = this.ch.length*2;
  +            if (newLength < this.length + length + DEFAULT_SIZE)
  +                newLength = this.ch.length + length + DEFAULT_SIZE;
  +            char[] newch = new char[newLength];            
               System.arraycopy(this.ch, 0, newch, 0, this.length);
               this.ch = newch;
           }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-cvs-help@xml.apache.org