geirm       00/12/11 18:04:37

  Modified:    src/java/org/apache/velocity/runtime VelocimacroManager.java
  Log:
  Patch from Jose Alberto Fernandez <[EMAIL PROTECTED]> correcting one (stupid) 
bug and a nice trick for addNamespace()
  
  Revision  Changes    Path
  1.4       +19 -10    
jakarta-velocity/src/java/org/apache/velocity/runtime/VelocimacroManager.java
  
  Index: VelocimacroManager.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-velocity/src/java/org/apache/velocity/runtime/VelocimacroManager.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- VelocimacroManager.java   2000/12/11 03:20:15     1.3
  +++ VelocimacroManager.java   2000/12/12 02:04:36     1.4
  @@ -67,7 +67,7 @@
    *
    * @author <a href="mailto:[EMAIL PROTECTED]">Geir Magnusson Jr.</a>
    * @author <a href="mailto:[EMAIL PROTECTED]">Jose Alberto Fernandez</a>
  - * @version $Id: VelocimacroManager.java,v 1.3 2000/12/11 03:20:15 geirm Exp $ 
  + * @version $Id: VelocimacroManager.java,v 1.4 2000/12/12 02:04:36 geirm Exp $ 
    */
   
   package org.apache.velocity.runtime;
  @@ -236,7 +236,7 @@
       {
           Hashtable h = (Hashtable)  namespaceHash.get( namespace );
   
  -        if ( h == null)               
  +        if (h == null && addIfNew)               
               h = addNamespace( namespace );
     
           return h;
  @@ -250,16 +250,25 @@
        */
       private Hashtable addNamespace( String namespace )
       {
  -        /*
  -         *  if we already have it, don't blow it away
  -         */
  -
  -        if( namespaceHash.get( namespace ) != null )
  -            return null;
  -        
           Hashtable h = new Hashtable();
  +        Object oh;
   
  -        namespaceHash.put( namespace, h );
  +        if ((oh = namespaceHash.put( namespace, h )) != null)
  +        {
  +          /*
  +           * There was already an entry on the table, restore it!
  +           * This condition should never occur, given the code
  +           * and the fact that this method is private.
  +           * But just in case, this way of testing for it is much
  +           * more efficient than testing before hand using get().
  +           */
  +          namespaceHash.put( namespace, oh );
  +          /*
  +           * Should't we be returning the old entry (oh)?
  +           * The previous code was just returning null in this case.
  +           */
  +          return null;
  +        }
           
           return h;
       }
  
  
  

Reply via email to