commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mben...@apache.org
Subject svn commit: r1133414 - /commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/FunctionLibrary.java
Date Wed, 08 Jun 2011 14:27:20 GMT
Author: mbenson
Date: Wed Jun  8 14:27:19 2011
New Revision: 1133414

URL: http://svn.apache.org/viewvc?rev=1133414&view=rev
Log:
simplify and bulletproof cache synchronization; thanks to Sebastian Bazley

Modified:
    commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/FunctionLibrary.java

Modified: commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/FunctionLibrary.java
URL: http://svn.apache.org/viewvc/commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/FunctionLibrary.java?rev=1133414&r1=1133413&r2=1133414&view=diff
==============================================================================
--- commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/FunctionLibrary.java (original)
+++ commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/FunctionLibrary.java Wed
Jun  8 14:27:19 2011
@@ -100,30 +100,25 @@ public class FunctionLibrary implements 
     /**
      * Prepare the cache.
      */
-    private Map functionCache() {
+    private synchronized Map functionCache() {
         if (byNamespace == null) {
-            synchronized (this) {
-                //read again
-                if (byNamespace == null) {
-                    byNamespace = new HashMap();
-                    int count = allFunctions.size();
-                    for (int i = 0; i < count; i++) {
-                        Functions funcs = (Functions) allFunctions.get(i);
-                        Set namespaces = funcs.getUsedNamespaces();
-                        for (Iterator it = namespaces.iterator(); it.hasNext();) {
-                            String ns = (String) it.next();
-                            Object candidates = byNamespace.get(ns);
-                            if (candidates == null) {
-                                byNamespace.put(ns, funcs);
-                            } else if (candidates instanceof Functions) {
-                                List lst = new ArrayList();
-                                lst.add(candidates);
-                                lst.add(funcs);
-                                byNamespace.put(ns, lst);
-                            } else {
-                                ((List) candidates).add(funcs);
-                            }
-                        }
+            byNamespace = new HashMap();
+            int count = allFunctions.size();
+            for (int i = 0; i < count; i++) {
+                Functions funcs = (Functions) allFunctions.get(i);
+                Set namespaces = funcs.getUsedNamespaces();
+                for (Iterator it = namespaces.iterator(); it.hasNext();) {
+                    String ns = (String) it.next();
+                    Object candidates = byNamespace.get(ns);
+                    if (candidates == null) {
+                        byNamespace.put(ns, funcs);
+                    } else if (candidates instanceof Functions) {
+                        List lst = new ArrayList();
+                        lst.add(candidates);
+                        lst.add(funcs);
+                        byNamespace.put(ns, lst);
+                    } else {
+                        ((List) candidates).add(funcs);
                     }
                 }
             }



Mime
View raw message