You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@velocity.apache.org by nb...@apache.org on 2008/07/26 00:53:15 UTC

svn commit: r679917 - /velocity/engine/trunk/src/java/org/apache/velocity/runtime/RuntimeInstance.java

Author: nbubna
Date: Fri Jul 25 15:53:14 2008
New Revision: 679917

URL: http://svn.apache.org/viewvc?rev=679917&view=rev
Log:
reduce redundancy and complexity of RuntimeInstance.parse(Reader,String,bool)

Modified:
    velocity/engine/trunk/src/java/org/apache/velocity/runtime/RuntimeInstance.java

Modified: velocity/engine/trunk/src/java/org/apache/velocity/runtime/RuntimeInstance.java
URL: http://svn.apache.org/viewvc/velocity/engine/trunk/src/java/org/apache/velocity/runtime/RuntimeInstance.java?rev=679917&r1=679916&r2=679917&view=diff
==============================================================================
--- velocity/engine/trunk/src/java/org/apache/velocity/runtime/RuntimeInstance.java (original)
+++ velocity/engine/trunk/src/java/org/apache/velocity/runtime/RuntimeInstance.java Fri Jul 25 15:53:14 2008
@@ -1035,62 +1035,44 @@
             }
         }
 
-        SimpleNode ast = null;
         Parser parser = (Parser) parserPool.get();
-
+        boolean keepParser = true;
         if (parser == null)
         {
             /*
-             *  if we couldn't get a parser from the pool
-             *  make one and log it.
+             *  if we couldn't get a parser from the pool make one and log it.
              */
-
             if (log.isInfoEnabled())
             {
                 log.info("Runtime : ran out of parsers. Creating a new one. "
                       + " Please increment the parser.pool.size property."
                       + " The current value is too small.");
             }
-
             parser = createNewParser();
-
+            keepParser = false;
         }
 
-        /*
-         *  now, if we have a parser
-         */
-
-        if (parser != null)
+        try
         {
-            try
+            /*
+             *  dump namespace if we are told to.  Generally, you want to
+             *  do this - you don't in special circumstances, such as
+             *  when a VM is getting init()-ed & parsed
+             */
+            if (dumpNamespace)
             {
-                /*
-                 *  dump namespace if we are told to.  Generally, you want to
-                 *  do this - you don't in special circumstances, such as
-                 *  when a VM is getting init()-ed & parsed
-                 */
-
-                if (dumpNamespace)
-                {
-                    dumpVMNamespace(templateName);
-                }
-
-                ast = parser.parse(reader, templateName);
+                dumpVMNamespace(templateName);
             }
-            finally
+            return parser.parse(reader, templateName);
+        }
+        finally
+        {
+            if (keepParser)
             {
-                /*
-                 *  put it back
-                 */
                 parserPool.put(parser);
-
             }
+
         }
-        else
-        {
-            log.error("Runtime : ran out of parsers and unable to create more.");
-        }
-        return ast;
     }
 
     /**