You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xalan.apache.org by sb...@locus.apache.org on 2000/11/28 16:01:27 UTC

cvs commit: xml-xalan/java/src/org/apache/xml/utils StringBufferPool.java

sboag       00/11/28 07:01:26

  Modified:    java/src/org/apache/xml/utils StringBufferPool.java
  Log:
  Since the free method is not synchronized, do setLength before
  the object is freed.  Fix attributed to Peter Speck <sp...@ruc.dk>.
  
  Revision  Changes    Path
  1.2       +13 -9     xml-xalan/java/src/org/apache/xml/utils/StringBufferPool.java
  
  Index: StringBufferPool.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xml/utils/StringBufferPool.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- StringBufferPool.java	2000/11/23 04:58:45	1.1
  +++ StringBufferPool.java	2000/11/28 15:01:24	1.2
  @@ -58,20 +58,22 @@
   
   /**
    * <meta name="usage" content="internal"/>
  - * NEEDSDOC Class StringBufferPool <needs-comment/>
  + * This class pools string buffers, since they are reused so often.
  + * String buffers are good candidates for pooling, because of 
  + * their supporting character arrays.
    */
   public class StringBufferPool
   {
   
  -  /** NEEDSDOC Field m_stringBufPool          */
  +  /** The global pool of string buffers.   */
     private static ObjectPool m_stringBufPool =
       new ObjectPool(org.apache.xml.utils.FastStringBuffer.class);
   
     /**
  -   * NEEDSDOC Method get 
  +   * Get the first free instance of a string buffer, or create one 
  +   * if there are no free instances.
      *
  -   *
  -   * NEEDSDOC (get) @return
  +   * @return A string buffer ready for use.
      */
     public static FastStringBuffer get()
     {
  @@ -79,14 +81,16 @@
     }
   
     /**
  -   * NEEDSDOC Method free 
  -   *
  +   * Return a string buffer back to the pool.
      *
  -   * NEEDSDOC @param sb
  +   * @param sb Must be a non-null reference to a string buffer.
      */
     public static void free(FastStringBuffer sb)
     {
  -    m_stringBufPool.freeInstance(sb);
  +    // Since this isn't synchronized, setLength must be 
  +    // done before the instance is freed.
  +    // Fix attributed to Peter Speck <sp...@ruc.dk>.
       sb.setLength(0);
  +    m_stringBufPool.freeInstance(sb);
     }
   }