2007-12-01 00:00:00 +00:00
|
|
|
/*
|
2022-03-17 09:20:24 +00:00
|
|
|
* Copyright (c) 2000, 2022, Oracle and/or its affiliates. All rights reserved.
|
2007-12-01 00:00:00 +00:00
|
|
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
|
|
*
|
|
|
|
* This code is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License version 2 only, as
|
2010-05-25 15:58:33 -07:00
|
|
|
* published by the Free Software Foundation. Oracle designates this
|
2007-12-01 00:00:00 +00:00
|
|
|
* particular file as subject to the "Classpath" exception as provided
|
2010-05-25 15:58:33 -07:00
|
|
|
* by Oracle in the LICENSE file that accompanied this code.
|
2007-12-01 00:00:00 +00:00
|
|
|
*
|
|
|
|
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
|
|
* version 2 for more details (a copy is included in the LICENSE file that
|
|
|
|
* accompanied this code).
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License version
|
|
|
|
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
|
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*
|
2010-05-25 15:58:33 -07:00
|
|
|
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
|
|
|
* or visit www.oracle.com if you need additional information or have any
|
|
|
|
* questions.
|
2007-12-01 00:00:00 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
package java.lang;
|
|
|
|
|
2020-09-30 20:05:07 +00:00
|
|
|
import jdk.internal.vm.annotation.IntrinsicCandidate;
|
8141132: JEP 254: Compact Strings
Adopt a more space-efficient internal representation for strings.
Co-authored-by: Brent Christian <brent.christian@oracle.com>
Co-authored-by: Vivek Deshpande <vivek.r.deshpande@intel.com>
Co-authored-by: Charlie Hunt <charlie.hunt@oracle.com>
Co-authored-by: Vladimir Kozlov <vladimir.kozlov@oracle.com>
Co-authored-by: Roger Riggs <roger.riggs@oracle.com>
Co-authored-by: Xueming Shen <xueming.shen@oracle.com>
Co-authored-by: Aleksey Shipilev <aleksey.shipilev@oracle.com>
Co-authored-by: Sandhya Viswanathan <sandhya.viswanathan@intel.com>
Reviewed-by: alanb, bdelsart, coleenp, iklam, jiangli, jrose, kevinw, naoto, pliden, roland, smarks, twisti
2015-11-03 09:42:11 +01:00
|
|
|
|
2007-12-01 00:00:00 +00:00
|
|
|
/**
|
|
|
|
* Utility class for string encoding and decoding.
|
|
|
|
*/
|
|
|
|
class StringCoding {
|
|
|
|
|
|
|
|
private StringCoding() { }
|
|
|
|
|
2021-01-22 11:27:13 +00:00
|
|
|
public static boolean hasNegatives(byte[] ba, int off, int len) {
|
2022-03-17 09:20:24 +00:00
|
|
|
return countPositives(ba, off, len) != len;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Count the number of leading positive bytes in the range.
|
|
|
|
*
|
|
|
|
* @implSpec the implementation must return len if there are no negative
|
|
|
|
* bytes in the range. If there are negative bytes, the implementation must return
|
|
|
|
* a value that is less than or equal to the index of the first negative byte
|
|
|
|
* in the range.
|
|
|
|
*/
|
|
|
|
@IntrinsicCandidate
|
|
|
|
public static int countPositives(byte[] ba, int off, int len) {
|
|
|
|
int limit = off + len;
|
|
|
|
for (int i = off; i < limit; i++) {
|
2021-01-22 11:27:13 +00:00
|
|
|
if (ba[i] < 0) {
|
2022-03-17 09:20:24 +00:00
|
|
|
return i - off;
|
2017-12-13 07:51:57 -08:00
|
|
|
}
|
|
|
|
}
|
2022-03-17 09:20:24 +00:00
|
|
|
return len;
|
2017-12-13 07:51:57 -08:00
|
|
|
}
|
|
|
|
|
2020-09-30 20:05:07 +00:00
|
|
|
@IntrinsicCandidate
|
2021-01-22 11:27:13 +00:00
|
|
|
public static int implEncodeISOArray(byte[] sa, int sp,
|
2021-09-29 12:58:14 +00:00
|
|
|
byte[] da, int dp, int len) {
|
2017-12-13 07:51:57 -08:00
|
|
|
int i = 0;
|
|
|
|
for (; i < len; i++) {
|
|
|
|
char c = StringUTF16.getChar(sa, sp++);
|
|
|
|
if (c > '\u00FF')
|
|
|
|
break;
|
|
|
|
da[dp++] = (byte)c;
|
|
|
|
}
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
2021-09-29 12:58:14 +00:00
|
|
|
@IntrinsicCandidate
|
|
|
|
public static int implEncodeAsciiArray(char[] sa, int sp,
|
|
|
|
byte[] da, int dp, int len)
|
|
|
|
{
|
|
|
|
int i = 0;
|
|
|
|
for (; i < len; i++) {
|
|
|
|
char c = sa[sp++];
|
|
|
|
if (c >= '\u0080')
|
|
|
|
break;
|
|
|
|
da[dp++] = (byte)c;
|
|
|
|
}
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
2007-12-01 00:00:00 +00:00
|
|
|
}
|