1 /*
2 * Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
256 }
257
258 @HotSpotIntrinsicCandidate
259 public static boolean equals(byte[] value, byte[] other) {
260 if (value.length == other.length) {
261 int len = value.length >> 1;
262 for (int i = 0; i < len; i++) {
263 if (getChar(value, i) != getChar(other, i)) {
264 return false;
265 }
266 }
267 return true;
268 }
269 return false;
270 }
271
272 @HotSpotIntrinsicCandidate
273 public static int compareTo(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 return c1 - c2;
282 }
283 }
284 return len1 - len2;
285 }
286
287 @HotSpotIntrinsicCandidate
288 public static int compareToLatin1(byte[] value, byte[] other) {
289 return -StringLatin1.compareToUTF16(other, value);
290 }
291
292 public static int compareToCI(byte[] value, byte[] other) {
293 int len1 = length(value);
294 int len2 = length(other);
295 int lim = Math.min(len1, len2);
296 for (int k = 0; k < lim; k++) {
297 char c1 = getChar(value, k);
298 char c2 = getChar(other, k);
299 if (c1 != c2) {
300 c1 = Character.toUpperCase(c1);
301 c2 = Character.toUpperCase(c2);
302 if (c1 != c2) {
303 c1 = Character.toLowerCase(c1);
304 c2 = Character.toLowerCase(c2);
305 if (c1 != c2) {
306 return c1 - c2;
307 }
308 }
309 }
|
1 /*
2 * Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
256 }
257
258 @HotSpotIntrinsicCandidate
259 public static boolean equals(byte[] value, byte[] other) {
260 if (value.length == other.length) {
261 int len = value.length >> 1;
262 for (int i = 0; i < len; i++) {
263 if (getChar(value, i) != getChar(other, i)) {
264 return false;
265 }
266 }
267 return true;
268 }
269 return false;
270 }
271
272 @HotSpotIntrinsicCandidate
273 public static int compareTo(byte[] value, byte[] other) {
274 int len1 = length(value);
275 int len2 = length(other);
276 return compareValues(value, other, len1, len2);
277 }
278
279 /*
280 * Checks the boundary and then compares the byte arrays.
281 */
282 public static int compareTo(byte[] value, byte[] other, int len1, int len2) {
283 checkOffset(len1, value);
284 checkOffset(len2, other);
285
286 return compareValues(value, other, len1, len2);
287 }
288
289 private static int compareValues(byte[] value, byte[] other, int len1, int len2) {
290 int lim = Math.min(len1, len2);
291 for (int k = 0; k < lim; k++) {
292 char c1 = getChar(value, k);
293 char c2 = getChar(other, k);
294 if (c1 != c2) {
295 return c1 - c2;
296 }
297 }
298 return len1 - len2;
299 }
300
301 @HotSpotIntrinsicCandidate
302 public static int compareToLatin1(byte[] value, byte[] other) {
303 return -StringLatin1.compareToUTF16(other, value);
304 }
305
306 public static int compareToLatin1(byte[] value, byte[] other, int len1, int len2) {
307 return -StringLatin1.compareToUTF16(other, value, len2, len1);
308 }
309
310 public static int compareToCI(byte[] value, byte[] other) {
311 int len1 = length(value);
312 int len2 = length(other);
313 int lim = Math.min(len1, len2);
314 for (int k = 0; k < lim; k++) {
315 char c1 = getChar(value, k);
316 char c2 = getChar(other, k);
317 if (c1 != c2) {
318 c1 = Character.toUpperCase(c1);
319 c2 = Character.toUpperCase(c2);
320 if (c1 != c2) {
321 c1 = Character.toLowerCase(c1);
322 c2 = Character.toLowerCase(c2);
323 if (c1 != c2) {
324 return c1 - c2;
325 }
326 }
327 }
|