Author: mrglavas
Date: Tue Nov 10 20:23:17 2009
New Revision: 834650

URL: http://svn.apache.org/viewvc?rev=834650&view=rev
Log:
Minor performance improvement. Build map during class initialization to avoid 
synchronization on every get().

Modified:
    
xerces/java/trunk/src/org/apache/xerces/impl/xpath/regex/CaseInsensitiveMap.java

Modified: 
xerces/java/trunk/src/org/apache/xerces/impl/xpath/regex/CaseInsensitiveMap.java
URL: 
http://svn.apache.org/viewvc/xerces/java/trunk/src/org/apache/xerces/impl/xpath/regex/CaseInsensitiveMap.java?rev=834650&r1=834649&r2=834650&view=diff
==============================================================================
--- 
xerces/java/trunk/src/org/apache/xerces/impl/xpath/regex/CaseInsensitiveMap.java
 (original)
+++ 
xerces/java/trunk/src/org/apache/xerces/impl/xpath/regex/CaseInsensitiveMap.java
 Tue Nov 10 20:23:17 2009
@@ -28,24 +28,19 @@
     private static int INITIAL_CHUNK_COUNT = 64;   /* up to 0xFFFF */
 
     private static int[][][] caseInsensitiveMap;
-    private static Boolean mapBuilt = Boolean.FALSE;
     
     private static int LOWER_CASE_MATCH = 1;
-    private static int UPPER_CASE_MATCH = 2; 
+    private static int UPPER_CASE_MATCH = 2;
+    
+    static {
+        buildCaseInsensitiveMap();
+    }
 
     /**
      *  Return a list of code point characters (not including the input value)
      *  that can be substituted in a case insensitive match
      */
     static public int[] get(int codePoint) {
-        if (mapBuilt == Boolean.FALSE) {
-            synchronized (mapBuilt) {
-                if (mapBuilt == Boolean.FALSE) {
-                    buildCaseInsensitiveMap();
-                }
-            } // synchronized
-        } // if mapBuilt
-
         return (codePoint < 0x10000) ? getMapping(codePoint) : null;
     }
 
@@ -57,11 +52,7 @@
     }
     
     private static void buildCaseInsensitiveMap() {
-        caseInsensitiveMap = new int[INITIAL_CHUNK_COUNT][][];
-        for (int i=0; i<INITIAL_CHUNK_COUNT; i++) {
-            caseInsensitiveMap[i] = new int[CHUNK_SIZE][];
-        }
-        
+        caseInsensitiveMap = new int[INITIAL_CHUNK_COUNT][CHUNK_SIZE][];
         int lc, uc;
         for (int i=0; i<0x10000; i++) {
             lc = Character.toLowerCase((char) i);
@@ -96,8 +87,6 @@
                 set(i, map);
             }
         }
-
-        mapBuilt = Boolean.TRUE;
     }
     
     private static int[] expandMap(int[] srcMap, int expandBy) {



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to