218 // Pass 2: Allocate and fill in <high, low> pair
219 byte[] buf = newBytesFor(n);
220 for (int i = index, j = 0; i < end; i++, j++) {
221 int cp = val[i];
222 if (Character.isBmpCodePoint(cp)) {
223 putChar(buf, j, cp);
224 } else {
225 putChar(buf, j++, Character.highSurrogate(cp));
226 putChar(buf, j, Character.lowSurrogate(cp));
227 }
228 }
229 return buf;
230 }
231
232 public static byte[] toBytes(char c) {
233 byte[] result = new byte[2];
234 putChar(result, 0, c);
235 return result;
236 }
237
238 @HotSpotIntrinsicCandidate
239 public static void getChars(byte[] value, int srcBegin, int srcEnd, char dst[], int dstBegin) {
240 // We need a range check here because 'getChar' has no checks
241 if (srcBegin < srcEnd) {
242 checkBoundsOffCount(srcBegin, srcEnd - srcBegin, value);
243 }
244 for (int i = srcBegin; i < srcEnd; i++) {
245 dst[dstBegin++] = getChar(value, i);
246 }
247 }
248
249 /* @see java.lang.String.getBytes(int, int, byte[], int) */
250 public static void getBytes(byte[] value, int srcBegin, int srcEnd, byte dst[], int dstBegin) {
251 srcBegin <<= 1;
252 srcEnd <<= 1;
253 for (int i = srcBegin + (1 >> LO_BYTE_SHIFT); i < srcEnd; i += 2) {
254 dst[dstBegin++] = value[i];
255 }
256 }
257
|
218 // Pass 2: Allocate and fill in <high, low> pair
219 byte[] buf = newBytesFor(n);
220 for (int i = index, j = 0; i < end; i++, j++) {
221 int cp = val[i];
222 if (Character.isBmpCodePoint(cp)) {
223 putChar(buf, j, cp);
224 } else {
225 putChar(buf, j++, Character.highSurrogate(cp));
226 putChar(buf, j, Character.lowSurrogate(cp));
227 }
228 }
229 return buf;
230 }
231
232 public static byte[] toBytes(char c) {
233 byte[] result = new byte[2];
234 putChar(result, 0, c);
235 return result;
236 }
237
238 static byte[] toBytesSupplementary(int cp) {
239 byte[] result = new byte[4];
240 putChar(result, 0, Character.highSurrogate(cp));
241 putChar(result, 1, Character.lowSurrogate(cp));
242 return result;
243 }
244
245 @HotSpotIntrinsicCandidate
246 public static void getChars(byte[] value, int srcBegin, int srcEnd, char dst[], int dstBegin) {
247 // We need a range check here because 'getChar' has no checks
248 if (srcBegin < srcEnd) {
249 checkBoundsOffCount(srcBegin, srcEnd - srcBegin, value);
250 }
251 for (int i = srcBegin; i < srcEnd; i++) {
252 dst[dstBegin++] = getChar(value, i);
253 }
254 }
255
256 /* @see java.lang.String.getBytes(int, int, byte[], int) */
257 public static void getBytes(byte[] value, int srcBegin, int srcEnd, byte dst[], int dstBegin) {
258 srcBegin <<= 1;
259 srcEnd <<= 1;
260 for (int i = srcBegin + (1 >> LO_BYTE_SHIFT); i < srcEnd; i += 2) {
261 dst[dstBegin++] = value[i];
262 }
263 }
264
|