You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@velocity.apache.org by ge...@apache.org on 2003/10/27 13:35:17 UTC

cvs commit: jakarta-velocity/src/java/org/apache/velocity/util SimplePool.java

geirm       2003/10/27 04:35:17

  Modified:    src/java/org/apache/velocity/util SimplePool.java
  Log:
  Change to the simple pool to remove items from pool on a get(), rather than
  just returning them.  Bug #19042
  
  Revision  Changes    Path
  1.3       +25 -24    jakarta-velocity/src/java/org/apache/velocity/util/SimplePool.java
  
  Index: SimplePool.java
  ===================================================================
  RCS file: /home/cvs/jakarta-velocity/src/java/org/apache/velocity/util/SimplePool.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- SimplePool.java	31 Mar 2001 05:25:22 -0000	1.2
  +++ SimplePool.java	27 Oct 2003 12:35:17 -0000	1.3
  @@ -9,7 +9,7 @@
    *
    * The Apache Software License, Version 1.1
    *
  - * Copyright (c) 1999-2001 The Apache Software Foundation.  All rights
  + * Copyright (c) 1999-2003 The Apache Software Foundation.  All rights
    * reserved.
    *
    * Redistribution and use in source and binary forms, with or without
  @@ -105,13 +105,13 @@
       {
           int idx=-1;
        
  -        synchronized( this ) 
  +        synchronized(this)
           {
               /*
                *  if we aren't full
                */
   
  -            if( current < max - 1 )
  +            if (current < max - 1)
               {
                   /*
                    *  then increment the 
  @@ -120,7 +120,7 @@
                   idx = ++current;
               }
   
  -            if( idx >= 0 ) 
  +            if (idx >= 0)
               {
                   pool[idx] = o;
               }
  @@ -130,11 +130,9 @@
       /**
        * Get an object from the pool, null if the pool is empty.
        */
  -    public  Object get() 
  +    public Object get()
       {
  -        int idx = -1;
  -        
  -        synchronized( this ) 
  +        synchronized(this)
           {
               /*
                *  if we have any in the pool
  @@ -142,22 +140,15 @@
               if( current >= 0 )
               {
                   /*
  -                 *  take one out, so to speak -
  -                 *  separate the two operations
  -                 *  to make it clear that you
  -                 *  don't want idx = --current; :)
  +                 *  remove the current one
                    */
   
  -                idx = current;
  +                Object o = pool[current];
  +                pool[current] = null;
  +
                   current--;
  -               
  -                /*
  -                 *  and since current was >= 0
  -                 *  to get in here, idx must be as well
  -                 *  so save the if() opration
  -                 */
   
  -                return pool[idx];
  +                return o;
               }
           }
           
  @@ -169,5 +160,15 @@
       public int getMax() 
       {
           return max;
  +    }
  +
  +    /**
  +     *   for testing purposes, so we can examine the pool
  +     * 
  +     * @return
  +     */
  +    Object[] getPool()
  +    {
  +        return pool;
       }
   }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-dev-help@jakarta.apache.org