src/java.base/share/classes/java/lang/StringUTF16.java

Print this page
rev 13834 : 8151384: Examine sun.misc.ASCIICaseInsensitiveComparator
Reviewed-by: shade, sherman


 253             }
 254         }
 255         return len1 - len2;
 256     }
 257 
 258     @HotSpotIntrinsicCandidate
 259     public static int compareToLatin1(byte[] value, byte[] other) {
 260         int len1 = length(value);
 261         int len2 = StringLatin1.length(other);
 262         int lim = Math.min(len1, len2);
 263         for (int k = 0; k < lim; k++) {
 264             char c1 = getChar(value, k);
 265             char c2 = StringLatin1.getChar(other, k);
 266             if (c1 != c2) {
 267                 return c1 - c2;
 268             }
 269         }
 270         return len1 - len2;
 271     }
 272 












































 273     public static int hashCode(byte[] value) {
 274         int h = 0;
 275         int length = value.length >> 1;
 276         for (int i = 0; i < length; i++) {
 277             h = 31 * h + getChar(value, i);
 278         }
 279         return h;
 280     }
 281 
 282     public static int indexOf(byte[] value, int ch, int fromIndex) {
 283         int max = value.length >> 1;
 284         if (fromIndex < 0) {
 285             fromIndex = 0;
 286         } else if (fromIndex >= max) {
 287             // Note: fromIndex might be near -1>>>1.
 288             return -1;
 289         }
 290         if (ch < Character.MIN_SUPPLEMENTARY_CODE_POINT) {
 291             // handle most cases here (ch is a BMP code point or a
 292             // negative value (invalid code point))




 253             }
 254         }
 255         return len1 - len2;
 256     }
 257 
 258     @HotSpotIntrinsicCandidate
 259     public static int compareToLatin1(byte[] value, byte[] other) {
 260         int len1 = length(value);
 261         int len2 = StringLatin1.length(other);
 262         int lim = Math.min(len1, len2);
 263         for (int k = 0; k < lim; k++) {
 264             char c1 = getChar(value, k);
 265             char c2 = StringLatin1.getChar(other, k);
 266             if (c1 != c2) {
 267                 return c1 - c2;
 268             }
 269         }
 270         return len1 - len2;
 271     }
 272 
 273     public static int compareToCI(byte[] value, byte[] other) {
 274         int len1 = length(value);
 275         int len2 = length(other);
 276         int lim = Math.min(len1, len2);
 277         for (int k = 0; k < lim; k++) {
 278             char c1 = getChar(value, k);
 279             char c2 = getChar(other, k);
 280             if (c1 != c2) {
 281                 c1 = Character.toUpperCase(c1);
 282                 c2 = Character.toUpperCase(c2);
 283                 if (c1 != c2) {
 284                     c1 = Character.toLowerCase(c1);
 285                     c2 = Character.toLowerCase(c2);
 286                     if (c1 != c2) {
 287                         return c1 - c2;
 288                     }
 289                 }
 290             }
 291         }
 292         return len1 - len2;
 293     }
 294 
 295     public static int compareToCI_Latin1(byte[] value, byte[] other) {
 296         int len1 = length(value);
 297         int len2 = StringLatin1.length(other);
 298         int lim = Math.min(len1, len2);
 299         for (int k = 0; k < lim; k++) {
 300             char c1 = getChar(value, k);
 301             char c2 = StringLatin1.getChar(other, k);
 302             if (c1 != c2) {
 303                 c1 = Character.toUpperCase(c1);
 304                 c2 = Character.toUpperCase(c2);
 305                 if (c1 != c2) {
 306                     c1 = Character.toLowerCase(c1);
 307                     c2 = Character.toLowerCase(c2);
 308                     if (c1 != c2) {
 309                         return c1 - c2;
 310                     }
 311                 }
 312             }
 313         }
 314         return len1 - len2;
 315     }
 316 
 317     public static int hashCode(byte[] value) {
 318         int h = 0;
 319         int length = value.length >> 1;
 320         for (int i = 0; i < length; i++) {
 321             h = 31 * h + getChar(value, i);
 322         }
 323         return h;
 324     }
 325 
 326     public static int indexOf(byte[] value, int ch, int fromIndex) {
 327         int max = value.length >> 1;
 328         if (fromIndex < 0) {
 329             fromIndex = 0;
 330         } else if (fromIndex >= max) {
 331             // Note: fromIndex might be near -1>>>1.
 332             return -1;
 333         }
 334         if (ch < Character.MIN_SUPPLEMENTARY_CODE_POINT) {
 335             // handle most cases here (ch is a BMP code point or a
 336             // negative value (invalid code point))