Hi,
Since I could get flogged with Geir, I had to check his submission :-)
This patch fixes one small bug in the code and changes the way some
other condition is verified to make it more efficient.
Let me know if there are any questions,
Jose Alberto
Index: src/java/org/apache/velocity/runtime/VelocimacroManager.java
===================================================================
RCS file:
/home/cvspublic/jakarta-velocity/src/java/org/apache/velocity/runtime/VelocimacroManager.java,v
retrieving revision 1.3
diff -u -r1.3 VelocimacroManager.java
--- src/java/org/apache/velocity/runtime/VelocimacroManager.java 2000/12/11
03:20:15 1.3
+++ src/java/org/apache/velocity/runtime/VelocimacroManager.java 2000/12/11
+22:55:11
@@ -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;
}