BUG-5410: optimize CaseInsensitiveMap 46/45146/3
authorRobert Varga <rovarga@cisco.com>
Mon, 5 Sep 2016 09:43:47 +0000 (11:43 +0200)
committerRobert Varga <nite@hq.sk>
Wed, 5 Oct 2016 12:57:15 +0000 (12:57 +0000)
This propagates would-be constants to real constatants,
allowing them to be better optimized.

Change-Id: I500e8060db0f3e22ca19be4188169f74e9a03271
Signed-off-by: Robert Varga <rovarga@cisco.com>
third-party/xsd-regex/src/main/java/org/opendaylight/yangtools/xsd/regex/CaseInsensitiveMap.java

index 2fc846812c29b8f16e18632b5f9be13982012aed..b0e9dca173c22d2b8681af53981126703acf6e52 100644 (file)
@@ -24,25 +24,21 @@ package org.opendaylight.yangtools.xsd.regex;
  */
 final class CaseInsensitiveMap {
 
-    private static int CHUNK_SHIFT = 10;           /* 2^10 = 1k */
-    private static int CHUNK_SIZE = (1<<CHUNK_SHIFT);
-    private static int CHUNK_MASK = (CHUNK_SIZE-1);
-    private static int INITIAL_CHUNK_COUNT = 64;   /* up to 0xFFFF */
+    private static final int CHUNK_SHIFT = 10;           /* 2^10 = 1k */
+    private static final int CHUNK_SIZE = (1<<CHUNK_SHIFT);
+    private static final int CHUNK_MASK = (CHUNK_SIZE-1);
+    private static final int INITIAL_CHUNK_COUNT = 64;   /* up to 0xFFFF */
 
-    private static int[][][] caseInsensitiveMap;
+    private static final int[][][] caseInsensitiveMap;
     
-    private static int LOWER_CASE_MATCH = 1;
-    private static int UPPER_CASE_MATCH = 2;
-    
-    static {
-        buildCaseInsensitiveMap();
-    }
+    private static final int LOWER_CASE_MATCH = 1;
+    private static final int UPPER_CASE_MATCH = 2;
 
     /**
      *  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) {
+    static int[] get(int codePoint) {
         return (codePoint < 0x10000) ? getMapping(codePoint) : null;
     }
 
@@ -53,7 +49,7 @@ final class CaseInsensitiveMap {
         return caseInsensitiveMap[chunk][offset];
     }
     
-    private static void buildCaseInsensitiveMap() {
+    static {
         caseInsensitiveMap = new int[INITIAL_CHUNK_COUNT][CHUNK_SIZE][];
         int lc, uc;
         for (int i=0; i<0x10000; i++) {