Re: [xmlc] Minor optimization (though used rather a lot)

Jacob Kjome <[email protected]> Thu, 21 Jul 2005 00:08:34 -0500
Newsgroups gmane.comp.java.enhydra.xmlc
Message-ID <[email protected]>
At 04:00 AM 7/1/2005 -0700, you wrote:
 >Someone still working on XMLC? :-)
 >

Yep!

Thanks for the patch.  It has been applied along with attribution to your 
contribution in the 2.2.7 release notes in CVS HEAD.

Jake

 >Trivial optimization to remove duplicate getAttribute() call - usually
 >a HashTable lookup.
 >
 >Final code (exclusive of long comment) reduced to:
 >---------------------------------------
 >    public static XMLCContext getContext(ServletContext servletContext) {
 >        XMLCContext context =
 >(XMLCContext)servletContext.getAttribute(CONTEXT_ATTRIBUTE);
 >        if (null != context) {
 >            return context;
 >        }
 >        context = new XMLCContextInit().createContext(servletContext);
 >        servletContext.setAttribute(CONTEXT_ATTRIBUTE, context);
 >        return context;
 >    }
 >---------------------------------------
 >
 >
 >Index: XMLCContext.java
 >===================================================================
 >RCS file:
 >/cvsroot/xmlc/xmlc/xmlc/modules/xmlc/src/org/enhydra/xml/xmlc/servlet/XMLCCo
 >ntext.java,v
 >retrieving revision 1.5
 >diff -u -r1.5 XMLCContext.java
 >--- XMLCContext.java    26 Jan 2005 08:29:24 -0000    1.5
 >+++ XMLCContext.java    1 Jul 2005 10:42:16 -0000
 >@@ -534,11 +534,12 @@
 >         //reasonable and shouldn't cause problems since the only
 >worry about resetting the
 >         //XMLCContext object is performance.  No real need for
 >synchronization. --Jake
 >         XMLCContext context =
 >(XMLCContext)servletContext.getAttribute(CONTEXT_ATTRIBUTE);
 >-        if (context == null) {
 >-            context = new XMLCContextInit().createContext(servletContext);
 >-            servletContext.setAttribute(CONTEXT_ATTRIBUTE, context);
 >+        if (null != context) {
 >+            return context;
 >         }
 >-        return (XMLCContext)servletContext.getAttribute(CONTEXT_ATTRIBUTE);
 >+        context = new XMLCContextInit().createContext(servletContext);
 >+        servletContext.setAttribute(CONTEXT_ATTRIBUTE, context);
 >+        return context;
 >     }
 >
 >
 >--
 >You receive this message as a subscriber of the [email protected] mailing
 >list.
 >To unsubscribe: mailto:[email protected]
 >For general help: mailto:[email protected]?subject=help
 >ObjectWeb mailing lists service home page: http://www.objectweb.org/wws
message-footer.txt (text/plain, 269 B)
--
You receive this message as a subscriber of the [email protected] mailing list.
To unsubscribe: mailto:[email protected]
For general help: mailto:[email protected]?subject=help
ObjectWeb mailing lists service home page: http://www.objectweb.org/wws