nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/regexp/joni/OptMapInfo.java
changeset 27361 86c4ddb4797b
parent 25865 d38d876f1654
equal deleted inserted replaced
27360:a19c14022fa4 27361:86c4ddb4797b
    29 
    29 
    30     void clear() {
    30     void clear() {
    31         mmd.clear();
    31         mmd.clear();
    32         anchor.clear();
    32         anchor.clear();
    33         value = 0;
    33         value = 0;
    34         for (int i=0; i<map.length; i++) map[i] = 0;
    34         for (int i=0; i<map.length; i++) {
       
    35             map[i] = 0;
       
    36         }
    35     }
    37     }
    36 
    38 
    37     void copy(final OptMapInfo other) {
    39     void copy(final OptMapInfo other) {
    38         mmd.copy(other.mmd);
    40         mmd.copy(other.mmd);
    39         anchor.copy(other.anchor);
    41         anchor.copy(other.anchor);
    48             map[c_] = 1;
    50             map[c_] = 1;
    49             value += positionValue(c_);
    51             value += positionValue(c_);
    50         }
    52         }
    51     }
    53     }
    52 
    54 
    53     void addCharAmb(final char[] chars, final int p, final int end, int caseFoldFlag) {
    55     void addCharAmb(final char[] chars, final int p, final int end, final int caseFoldFlag) {
    54         addChar(chars[p]);
    56         addChar(chars[p]);
    55 
    57 
    56         caseFoldFlag &= ~Config.INTERNAL_ENC_CASE_FOLD_MULTI_CHAR;
    58         final char[]items = EncodingHelper.caseFoldCodesByString(caseFoldFlag & ~Config.INTERNAL_ENC_CASE_FOLD_MULTI_CHAR, chars[p]);
    57         final char[]items = EncodingHelper.caseFoldCodesByString(caseFoldFlag, chars[p]);
       
    58 
    59 
    59         for (int i=0; i<items.length; i++) {
    60         for (int i=0; i<items.length; i++) {
    60             addChar(items[i]);
    61             addChar(items[i]);
    61         }
    62         }
    62     }
    63     }
    63 
    64 
    64     // select_opt_map_info
    65     // select_opt_map_info
    65     private static final int z = 1<<15; /* 32768: something big value */
    66     private static final int z = 1<<15; /* 32768: something big value */
    66     void select(final OptMapInfo alt) {
    67     void select(final OptMapInfo alt) {
    67         if (alt.value == 0) return;
    68         if (alt.value == 0) {
       
    69             return;
       
    70         }
    68         if (value == 0) {
    71         if (value == 0) {
    69             copy(alt);
    72             copy(alt);
    70             return;
    73             return;
    71         }
    74         }
    72 
    75 
    73         final int v1 = z / value;
    76         final int v1 = z / value;
    74         final int v2 = z /alt.value;
    77         final int v2 = z /alt.value;
    75 
    78 
    76         if (mmd.compareDistanceValue(alt.mmd, v1, v2) > 0) copy(alt);
    79         if (mmd.compareDistanceValue(alt.mmd, v1, v2) > 0) {
       
    80             copy(alt);
       
    81         }
    77     }
    82     }
    78 
    83 
    79     // alt_merge_opt_map_info
    84     // alt_merge_opt_map_info
    80     void altMerge(final OptMapInfo other) {
    85     void altMerge(final OptMapInfo other) {
    81         /* if (! is_equal_mml(&to->mmd, &add->mmd)) return ; */
    86         /* if (! is_equal_mml(&to->mmd, &add->mmd)) return ; */
    82         if (value == 0) return;
    87         if (value == 0) {
       
    88             return;
       
    89         }
    83         if (other.value == 0 || mmd.max < other.mmd.max) {
    90         if (other.value == 0 || mmd.max < other.mmd.max) {
    84             clear();
    91             clear();
    85             return;
    92             return;
    86         }
    93         }
    87 
    94 
    88         mmd.altMerge(other.mmd);
    95         mmd.altMerge(other.mmd);
    89 
    96 
    90         int val = 0;
    97         int val = 0;
    91         for (int i=0; i<Config.CHAR_TABLE_SIZE; i++) {
    98         for (int i=0; i<Config.CHAR_TABLE_SIZE; i++) {
    92             if (other.map[i] != 0) map[i] = 1;
    99             if (other.map[i] != 0) {
    93             if (map[i] != 0) val += positionValue(i);
   100                 map[i] = 1;
       
   101             }
       
   102             if (map[i] != 0) {
       
   103                 val += positionValue(i);
       
   104             }
    94         }
   105         }
    95 
   106 
    96         value = val;
   107         value = val;
    97         anchor.altMerge(other.anchor);
   108         anchor.altMerge(other.anchor);
    98     }
   109     }
   110 
   121 
   111     // map_position_value
   122     // map_position_value
   112     static int positionValue(final int i) {
   123     static int positionValue(final int i) {
   113         if (i < ByteValTable.length) {
   124         if (i < ByteValTable.length) {
   114             return ByteValTable[i];
   125             return ByteValTable[i];
   115         } else {
       
   116             return 4; /* Take it easy. */
       
   117         }
   126         }
       
   127         return 4; /* Take it easy. */
   118     }
   128     }
   119 
   129 
   120 }
   130 }