author | jlaskey |
Tue, 22 May 2018 12:04:05 -0300 | |
changeset 50215 | 2fb27c352cae |
parent 50098 | 92560438d306 |
child 51714 | 975d3636a2f9 |
permissions | -rw-r--r-- |
33663 | 1 |
/* |
49115
ecfaa82c53be
8137326: Methods for comparing CharSequence, StringBuilder, and StringBuffer
joehw
parents:
47216
diff
changeset
|
2 |
* Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved. |
33663 | 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 |
|
23 |
* questions. |
|
24 |
*/ |
|
25 |
||
26 |
package java.lang; |
|
27 |
||
28 |
import java.util.Arrays; |
|
29 |
import java.util.Locale; |
|
30 |
import java.util.Spliterator; |
|
50215 | 31 |
import java.util.function.Consumer; |
33663 | 32 |
import java.util.function.IntConsumer; |
50215 | 33 |
import java.util.stream.Stream; |
34 |
import java.util.stream.StreamSupport; |
|
33663 | 35 |
import jdk.internal.HotSpotIntrinsicCandidate; |
44642
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
36 |
import jdk.internal.vm.annotation.ForceInline; |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
37 |
import jdk.internal.vm.annotation.DontInline; |
33663 | 38 |
|
39 |
import static java.lang.String.UTF16; |
|
40 |
import static java.lang.String.LATIN1; |
|
41 |
||
42 |
final class StringUTF16 { |
|
43 |
||
44 |
public static byte[] newBytesFor(int len) { |
|
45 |
if (len < 0) { |
|
46 |
throw new NegativeArraySizeException(); |
|
47 |
} |
|
48 |
if (len > MAX_LENGTH) { |
|
49 |
throw new OutOfMemoryError("UTF16 String size is " + len + |
|
50 |
", should be less than " + MAX_LENGTH); |
|
51 |
} |
|
52 |
return new byte[len << 1]; |
|
53 |
} |
|
54 |
||
55 |
@HotSpotIntrinsicCandidate |
|
44642
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
56 |
// intrinsic performs no bounds checks |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
57 |
static void putChar(byte[] val, int index, int c) { |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
58 |
assert index >= 0 && index < length(val) : "Trusted caller missed bounds check"; |
33663 | 59 |
index <<= 1; |
60 |
val[index++] = (byte)(c >> HI_BYTE_SHIFT); |
|
61 |
val[index] = (byte)(c >> LO_BYTE_SHIFT); |
|
62 |
} |
|
63 |
||
64 |
@HotSpotIntrinsicCandidate |
|
44642
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
65 |
// intrinsic performs no bounds checks |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
66 |
static char getChar(byte[] val, int index) { |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
67 |
assert index >= 0 && index < length(val) : "Trusted caller missed bounds check"; |
33663 | 68 |
index <<= 1; |
69 |
return (char)(((val[index++] & 0xff) << HI_BYTE_SHIFT) | |
|
70 |
((val[index] & 0xff) << LO_BYTE_SHIFT)); |
|
71 |
} |
|
72 |
||
73 |
public static int length(byte[] value) { |
|
74 |
return value.length >> 1; |
|
75 |
} |
|
76 |
||
44642
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
77 |
private static int codePointAt(byte[] value, int index, int end, boolean checked) { |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
78 |
assert index < end; |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
79 |
if (checked) { |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
80 |
checkIndex(index, value); |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
81 |
} |
33663 | 82 |
char c1 = getChar(value, index); |
83 |
if (Character.isHighSurrogate(c1) && ++index < end) { |
|
44642
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
84 |
if (checked) { |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
85 |
checkIndex(index, value); |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
86 |
} |
33663 | 87 |
char c2 = getChar(value, index); |
88 |
if (Character.isLowSurrogate(c2)) { |
|
89 |
return Character.toCodePoint(c1, c2); |
|
90 |
} |
|
91 |
} |
|
92 |
return c1; |
|
93 |
} |
|
94 |
||
44642
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
95 |
public static int codePointAt(byte[] value, int index, int end) { |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
96 |
return codePointAt(value, index, end, false /* unchecked */); |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
97 |
} |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
98 |
|
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
99 |
private static int codePointBefore(byte[] value, int index, boolean checked) { |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
100 |
--index; |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
101 |
if (checked) { |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
102 |
checkIndex(index, value); |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
103 |
} |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
104 |
char c2 = getChar(value, index); |
33663 | 105 |
if (Character.isLowSurrogate(c2) && index > 0) { |
44642
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
106 |
--index; |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
107 |
if (checked) { |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
108 |
checkIndex(index, value); |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
109 |
} |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
110 |
char c1 = getChar(value, index); |
33663 | 111 |
if (Character.isHighSurrogate(c1)) { |
112 |
return Character.toCodePoint(c1, c2); |
|
113 |
} |
|
114 |
} |
|
115 |
return c2; |
|
116 |
} |
|
117 |
||
44642
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
118 |
public static int codePointBefore(byte[] value, int index) { |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
119 |
return codePointBefore(value, index, false /* unchecked */); |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
120 |
} |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
121 |
|
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
122 |
private static int codePointCount(byte[] value, int beginIndex, int endIndex, boolean checked) { |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
123 |
assert beginIndex <= endIndex; |
33663 | 124 |
int count = endIndex - beginIndex; |
44642
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
125 |
int i = beginIndex; |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
126 |
if (checked && i < endIndex) { |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
127 |
checkBoundsBeginEnd(i, endIndex, value); |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
128 |
} |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
129 |
for (; i < endIndex - 1; ) { |
33663 | 130 |
if (Character.isHighSurrogate(getChar(value, i++)) && |
131 |
Character.isLowSurrogate(getChar(value, i))) { |
|
132 |
count--; |
|
133 |
i++; |
|
134 |
} |
|
135 |
} |
|
136 |
return count; |
|
137 |
} |
|
138 |
||
44642
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
139 |
public static int codePointCount(byte[] value, int beginIndex, int endIndex) { |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
140 |
return codePointCount(value, beginIndex, endIndex, false /* unchecked */); |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
141 |
} |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
142 |
|
33663 | 143 |
public static char[] toChars(byte[] value) { |
144 |
char[] dst = new char[value.length >> 1]; |
|
145 |
getChars(value, 0, dst.length, dst, 0); |
|
146 |
return dst; |
|
147 |
} |
|
148 |
||
149 |
@HotSpotIntrinsicCandidate |
|
150 |
public static byte[] toBytes(char[] value, int off, int len) { |
|
151 |
byte[] val = newBytesFor(len); |
|
152 |
for (int i = 0; i < len; i++) { |
|
34711
65544417508e
8145428: Optimize StringUTF16 compress/copy methods for C1
shade
parents:
34517
diff
changeset
|
153 |
putChar(val, i, value[off]); |
65544417508e
8145428: Optimize StringUTF16 compress/copy methods for C1
shade
parents:
34517
diff
changeset
|
154 |
off++; |
33663 | 155 |
} |
156 |
return val; |
|
157 |
} |
|
158 |
||
159 |
public static byte[] compress(char[] val, int off, int len) { |
|
160 |
byte[] ret = new byte[len]; |
|
161 |
if (compress(val, off, ret, 0, len) == len) { |
|
162 |
return ret; |
|
163 |
} |
|
164 |
return null; |
|
165 |
} |
|
166 |
||
167 |
public static byte[] compress(byte[] val, int off, int len) { |
|
168 |
byte[] ret = new byte[len]; |
|
169 |
if (compress(val, off, ret, 0, len) == len) { |
|
170 |
return ret; |
|
171 |
} |
|
172 |
return null; |
|
173 |
} |
|
174 |
||
175 |
// compressedCopy char[] -> byte[] |
|
176 |
@HotSpotIntrinsicCandidate |
|
38790
b74a24c96491
8155608: String intrinsic range checks are not strict enough
thartmann
parents:
36411
diff
changeset
|
177 |
public static int compress(char[] src, int srcOff, byte[] dst, int dstOff, int len) { |
33663 | 178 |
for (int i = 0; i < len; i++) { |
34711
65544417508e
8145428: Optimize StringUTF16 compress/copy methods for C1
shade
parents:
34517
diff
changeset
|
179 |
char c = src[srcOff]; |
65544417508e
8145428: Optimize StringUTF16 compress/copy methods for C1
shade
parents:
34517
diff
changeset
|
180 |
if (c > 0xFF) { |
65544417508e
8145428: Optimize StringUTF16 compress/copy methods for C1
shade
parents:
34517
diff
changeset
|
181 |
len = 0; |
65544417508e
8145428: Optimize StringUTF16 compress/copy methods for C1
shade
parents:
34517
diff
changeset
|
182 |
break; |
33663 | 183 |
} |
34711
65544417508e
8145428: Optimize StringUTF16 compress/copy methods for C1
shade
parents:
34517
diff
changeset
|
184 |
dst[dstOff] = (byte)c; |
65544417508e
8145428: Optimize StringUTF16 compress/copy methods for C1
shade
parents:
34517
diff
changeset
|
185 |
srcOff++; |
65544417508e
8145428: Optimize StringUTF16 compress/copy methods for C1
shade
parents:
34517
diff
changeset
|
186 |
dstOff++; |
33663 | 187 |
} |
188 |
return len; |
|
189 |
} |
|
190 |
||
191 |
// compressedCopy byte[] -> byte[] |
|
192 |
@HotSpotIntrinsicCandidate |
|
193 |
public static int compress(byte[] src, int srcOff, byte[] dst, int dstOff, int len) { |
|
34517
c6e795a80c80
8142303: C2 compilation fails with "bad AD file"
thartmann
parents:
33663
diff
changeset
|
194 |
// We need a range check here because 'getChar' has no checks |
44642
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
195 |
checkBoundsOffCount(srcOff, len, src); |
33663 | 196 |
for (int i = 0; i < len; i++) { |
34711
65544417508e
8145428: Optimize StringUTF16 compress/copy methods for C1
shade
parents:
34517
diff
changeset
|
197 |
char c = getChar(src, srcOff); |
65544417508e
8145428: Optimize StringUTF16 compress/copy methods for C1
shade
parents:
34517
diff
changeset
|
198 |
if (c > 0xFF) { |
65544417508e
8145428: Optimize StringUTF16 compress/copy methods for C1
shade
parents:
34517
diff
changeset
|
199 |
len = 0; |
65544417508e
8145428: Optimize StringUTF16 compress/copy methods for C1
shade
parents:
34517
diff
changeset
|
200 |
break; |
33663 | 201 |
} |
34711
65544417508e
8145428: Optimize StringUTF16 compress/copy methods for C1
shade
parents:
34517
diff
changeset
|
202 |
dst[dstOff] = (byte)c; |
65544417508e
8145428: Optimize StringUTF16 compress/copy methods for C1
shade
parents:
34517
diff
changeset
|
203 |
srcOff++; |
65544417508e
8145428: Optimize StringUTF16 compress/copy methods for C1
shade
parents:
34517
diff
changeset
|
204 |
dstOff++; |
33663 | 205 |
} |
206 |
return len; |
|
207 |
} |
|
208 |
||
209 |
public static byte[] toBytes(int[] val, int index, int len) { |
|
210 |
final int end = index + len; |
|
211 |
// Pass 1: Compute precise size of char[] |
|
212 |
int n = len; |
|
213 |
for (int i = index; i < end; i++) { |
|
214 |
int cp = val[i]; |
|
215 |
if (Character.isBmpCodePoint(cp)) |
|
216 |
continue; |
|
217 |
else if (Character.isValidCodePoint(cp)) |
|
218 |
n++; |
|
219 |
else throw new IllegalArgumentException(Integer.toString(cp)); |
|
220 |
} |
|
221 |
// Pass 2: Allocate and fill in <high, low> pair |
|
222 |
byte[] buf = newBytesFor(n); |
|
223 |
for (int i = index, j = 0; i < end; i++, j++) { |
|
224 |
int cp = val[i]; |
|
225 |
if (Character.isBmpCodePoint(cp)) { |
|
226 |
putChar(buf, j, cp); |
|
227 |
} else { |
|
228 |
putChar(buf, j++, Character.highSurrogate(cp)); |
|
229 |
putChar(buf, j, Character.lowSurrogate(cp)); |
|
230 |
} |
|
231 |
} |
|
232 |
return buf; |
|
233 |
} |
|
234 |
||
235 |
public static byte[] toBytes(char c) { |
|
236 |
byte[] result = new byte[2]; |
|
237 |
putChar(result, 0, c); |
|
238 |
return result; |
|
239 |
} |
|
240 |
||
49129
fb9f590b9eee
4993841: (str) java.lang.Character should have a toString(int) method
naoto
parents:
49115
diff
changeset
|
241 |
static byte[] toBytesSupplementary(int cp) { |
fb9f590b9eee
4993841: (str) java.lang.Character should have a toString(int) method
naoto
parents:
49115
diff
changeset
|
242 |
byte[] result = new byte[4]; |
fb9f590b9eee
4993841: (str) java.lang.Character should have a toString(int) method
naoto
parents:
49115
diff
changeset
|
243 |
putChar(result, 0, Character.highSurrogate(cp)); |
fb9f590b9eee
4993841: (str) java.lang.Character should have a toString(int) method
naoto
parents:
49115
diff
changeset
|
244 |
putChar(result, 1, Character.lowSurrogate(cp)); |
fb9f590b9eee
4993841: (str) java.lang.Character should have a toString(int) method
naoto
parents:
49115
diff
changeset
|
245 |
return result; |
fb9f590b9eee
4993841: (str) java.lang.Character should have a toString(int) method
naoto
parents:
49115
diff
changeset
|
246 |
} |
fb9f590b9eee
4993841: (str) java.lang.Character should have a toString(int) method
naoto
parents:
49115
diff
changeset
|
247 |
|
33663 | 248 |
@HotSpotIntrinsicCandidate |
249 |
public static void getChars(byte[] value, int srcBegin, int srcEnd, char dst[], int dstBegin) { |
|
34517
c6e795a80c80
8142303: C2 compilation fails with "bad AD file"
thartmann
parents:
33663
diff
changeset
|
250 |
// We need a range check here because 'getChar' has no checks |
38790
b74a24c96491
8155608: String intrinsic range checks are not strict enough
thartmann
parents:
36411
diff
changeset
|
251 |
if (srcBegin < srcEnd) { |
44642
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
252 |
checkBoundsOffCount(srcBegin, srcEnd - srcBegin, value); |
38790
b74a24c96491
8155608: String intrinsic range checks are not strict enough
thartmann
parents:
36411
diff
changeset
|
253 |
} |
33663 | 254 |
for (int i = srcBegin; i < srcEnd; i++) { |
255 |
dst[dstBegin++] = getChar(value, i); |
|
256 |
} |
|
257 |
} |
|
258 |
||
259 |
/* @see java.lang.String.getBytes(int, int, byte[], int) */ |
|
260 |
public static void getBytes(byte[] value, int srcBegin, int srcEnd, byte dst[], int dstBegin) { |
|
261 |
srcBegin <<= 1; |
|
262 |
srcEnd <<= 1; |
|
263 |
for (int i = srcBegin + (1 >> LO_BYTE_SHIFT); i < srcEnd; i += 2) { |
|
264 |
dst[dstBegin++] = value[i]; |
|
265 |
} |
|
266 |
} |
|
267 |
||
268 |
@HotSpotIntrinsicCandidate |
|
269 |
public static boolean equals(byte[] value, byte[] other) { |
|
270 |
if (value.length == other.length) { |
|
271 |
int len = value.length >> 1; |
|
272 |
for (int i = 0; i < len; i++) { |
|
273 |
if (getChar(value, i) != getChar(other, i)) { |
|
274 |
return false; |
|
275 |
} |
|
276 |
} |
|
277 |
return true; |
|
278 |
} |
|
279 |
return false; |
|
280 |
} |
|
281 |
||
282 |
@HotSpotIntrinsicCandidate |
|
283 |
public static int compareTo(byte[] value, byte[] other) { |
|
284 |
int len1 = length(value); |
|
285 |
int len2 = length(other); |
|
49115
ecfaa82c53be
8137326: Methods for comparing CharSequence, StringBuilder, and StringBuffer
joehw
parents:
47216
diff
changeset
|
286 |
return compareValues(value, other, len1, len2); |
ecfaa82c53be
8137326: Methods for comparing CharSequence, StringBuilder, and StringBuffer
joehw
parents:
47216
diff
changeset
|
287 |
} |
ecfaa82c53be
8137326: Methods for comparing CharSequence, StringBuilder, and StringBuffer
joehw
parents:
47216
diff
changeset
|
288 |
|
ecfaa82c53be
8137326: Methods for comparing CharSequence, StringBuilder, and StringBuffer
joehw
parents:
47216
diff
changeset
|
289 |
/* |
ecfaa82c53be
8137326: Methods for comparing CharSequence, StringBuilder, and StringBuffer
joehw
parents:
47216
diff
changeset
|
290 |
* Checks the boundary and then compares the byte arrays. |
ecfaa82c53be
8137326: Methods for comparing CharSequence, StringBuilder, and StringBuffer
joehw
parents:
47216
diff
changeset
|
291 |
*/ |
ecfaa82c53be
8137326: Methods for comparing CharSequence, StringBuilder, and StringBuffer
joehw
parents:
47216
diff
changeset
|
292 |
public static int compareTo(byte[] value, byte[] other, int len1, int len2) { |
ecfaa82c53be
8137326: Methods for comparing CharSequence, StringBuilder, and StringBuffer
joehw
parents:
47216
diff
changeset
|
293 |
checkOffset(len1, value); |
ecfaa82c53be
8137326: Methods for comparing CharSequence, StringBuilder, and StringBuffer
joehw
parents:
47216
diff
changeset
|
294 |
checkOffset(len2, other); |
ecfaa82c53be
8137326: Methods for comparing CharSequence, StringBuilder, and StringBuffer
joehw
parents:
47216
diff
changeset
|
295 |
|
ecfaa82c53be
8137326: Methods for comparing CharSequence, StringBuilder, and StringBuffer
joehw
parents:
47216
diff
changeset
|
296 |
return compareValues(value, other, len1, len2); |
ecfaa82c53be
8137326: Methods for comparing CharSequence, StringBuilder, and StringBuffer
joehw
parents:
47216
diff
changeset
|
297 |
} |
ecfaa82c53be
8137326: Methods for comparing CharSequence, StringBuilder, and StringBuffer
joehw
parents:
47216
diff
changeset
|
298 |
|
ecfaa82c53be
8137326: Methods for comparing CharSequence, StringBuilder, and StringBuffer
joehw
parents:
47216
diff
changeset
|
299 |
private static int compareValues(byte[] value, byte[] other, int len1, int len2) { |
33663 | 300 |
int lim = Math.min(len1, len2); |
301 |
for (int k = 0; k < lim; k++) { |
|
302 |
char c1 = getChar(value, k); |
|
303 |
char c2 = getChar(other, k); |
|
304 |
if (c1 != c2) { |
|
305 |
return c1 - c2; |
|
306 |
} |
|
307 |
} |
|
308 |
return len1 - len2; |
|
309 |
} |
|
310 |
||
311 |
@HotSpotIntrinsicCandidate |
|
312 |
public static int compareToLatin1(byte[] value, byte[] other) { |
|
39157 | 313 |
return -StringLatin1.compareToUTF16(other, value); |
33663 | 314 |
} |
315 |
||
49115
ecfaa82c53be
8137326: Methods for comparing CharSequence, StringBuilder, and StringBuffer
joehw
parents:
47216
diff
changeset
|
316 |
public static int compareToLatin1(byte[] value, byte[] other, int len1, int len2) { |
ecfaa82c53be
8137326: Methods for comparing CharSequence, StringBuilder, and StringBuffer
joehw
parents:
47216
diff
changeset
|
317 |
return -StringLatin1.compareToUTF16(other, value, len2, len1); |
ecfaa82c53be
8137326: Methods for comparing CharSequence, StringBuilder, and StringBuffer
joehw
parents:
47216
diff
changeset
|
318 |
} |
ecfaa82c53be
8137326: Methods for comparing CharSequence, StringBuilder, and StringBuffer
joehw
parents:
47216
diff
changeset
|
319 |
|
36411
f0cd8358b5ea
8151384: Improve String.CASE_INSENSITIVE_ORDER and remove sun.misc.ASCIICaseInsensitiveComparator
chegar
parents:
34711
diff
changeset
|
320 |
public static int compareToCI(byte[] value, byte[] other) { |
f0cd8358b5ea
8151384: Improve String.CASE_INSENSITIVE_ORDER and remove sun.misc.ASCIICaseInsensitiveComparator
chegar
parents:
34711
diff
changeset
|
321 |
int len1 = length(value); |
f0cd8358b5ea
8151384: Improve String.CASE_INSENSITIVE_ORDER and remove sun.misc.ASCIICaseInsensitiveComparator
chegar
parents:
34711
diff
changeset
|
322 |
int len2 = length(other); |
f0cd8358b5ea
8151384: Improve String.CASE_INSENSITIVE_ORDER and remove sun.misc.ASCIICaseInsensitiveComparator
chegar
parents:
34711
diff
changeset
|
323 |
int lim = Math.min(len1, len2); |
f0cd8358b5ea
8151384: Improve String.CASE_INSENSITIVE_ORDER and remove sun.misc.ASCIICaseInsensitiveComparator
chegar
parents:
34711
diff
changeset
|
324 |
for (int k = 0; k < lim; k++) { |
f0cd8358b5ea
8151384: Improve String.CASE_INSENSITIVE_ORDER and remove sun.misc.ASCIICaseInsensitiveComparator
chegar
parents:
34711
diff
changeset
|
325 |
char c1 = getChar(value, k); |
f0cd8358b5ea
8151384: Improve String.CASE_INSENSITIVE_ORDER and remove sun.misc.ASCIICaseInsensitiveComparator
chegar
parents:
34711
diff
changeset
|
326 |
char c2 = getChar(other, k); |
f0cd8358b5ea
8151384: Improve String.CASE_INSENSITIVE_ORDER and remove sun.misc.ASCIICaseInsensitiveComparator
chegar
parents:
34711
diff
changeset
|
327 |
if (c1 != c2) { |
f0cd8358b5ea
8151384: Improve String.CASE_INSENSITIVE_ORDER and remove sun.misc.ASCIICaseInsensitiveComparator
chegar
parents:
34711
diff
changeset
|
328 |
c1 = Character.toUpperCase(c1); |
f0cd8358b5ea
8151384: Improve String.CASE_INSENSITIVE_ORDER and remove sun.misc.ASCIICaseInsensitiveComparator
chegar
parents:
34711
diff
changeset
|
329 |
c2 = Character.toUpperCase(c2); |
f0cd8358b5ea
8151384: Improve String.CASE_INSENSITIVE_ORDER and remove sun.misc.ASCIICaseInsensitiveComparator
chegar
parents:
34711
diff
changeset
|
330 |
if (c1 != c2) { |
f0cd8358b5ea
8151384: Improve String.CASE_INSENSITIVE_ORDER and remove sun.misc.ASCIICaseInsensitiveComparator
chegar
parents:
34711
diff
changeset
|
331 |
c1 = Character.toLowerCase(c1); |
f0cd8358b5ea
8151384: Improve String.CASE_INSENSITIVE_ORDER and remove sun.misc.ASCIICaseInsensitiveComparator
chegar
parents:
34711
diff
changeset
|
332 |
c2 = Character.toLowerCase(c2); |
f0cd8358b5ea
8151384: Improve String.CASE_INSENSITIVE_ORDER and remove sun.misc.ASCIICaseInsensitiveComparator
chegar
parents:
34711
diff
changeset
|
333 |
if (c1 != c2) { |
f0cd8358b5ea
8151384: Improve String.CASE_INSENSITIVE_ORDER and remove sun.misc.ASCIICaseInsensitiveComparator
chegar
parents:
34711
diff
changeset
|
334 |
return c1 - c2; |
f0cd8358b5ea
8151384: Improve String.CASE_INSENSITIVE_ORDER and remove sun.misc.ASCIICaseInsensitiveComparator
chegar
parents:
34711
diff
changeset
|
335 |
} |
f0cd8358b5ea
8151384: Improve String.CASE_INSENSITIVE_ORDER and remove sun.misc.ASCIICaseInsensitiveComparator
chegar
parents:
34711
diff
changeset
|
336 |
} |
f0cd8358b5ea
8151384: Improve String.CASE_INSENSITIVE_ORDER and remove sun.misc.ASCIICaseInsensitiveComparator
chegar
parents:
34711
diff
changeset
|
337 |
} |
f0cd8358b5ea
8151384: Improve String.CASE_INSENSITIVE_ORDER and remove sun.misc.ASCIICaseInsensitiveComparator
chegar
parents:
34711
diff
changeset
|
338 |
} |
f0cd8358b5ea
8151384: Improve String.CASE_INSENSITIVE_ORDER and remove sun.misc.ASCIICaseInsensitiveComparator
chegar
parents:
34711
diff
changeset
|
339 |
return len1 - len2; |
f0cd8358b5ea
8151384: Improve String.CASE_INSENSITIVE_ORDER and remove sun.misc.ASCIICaseInsensitiveComparator
chegar
parents:
34711
diff
changeset
|
340 |
} |
f0cd8358b5ea
8151384: Improve String.CASE_INSENSITIVE_ORDER and remove sun.misc.ASCIICaseInsensitiveComparator
chegar
parents:
34711
diff
changeset
|
341 |
|
f0cd8358b5ea
8151384: Improve String.CASE_INSENSITIVE_ORDER and remove sun.misc.ASCIICaseInsensitiveComparator
chegar
parents:
34711
diff
changeset
|
342 |
public static int compareToCI_Latin1(byte[] value, byte[] other) { |
39157 | 343 |
return -StringLatin1.compareToCI_UTF16(other, value); |
36411
f0cd8358b5ea
8151384: Improve String.CASE_INSENSITIVE_ORDER and remove sun.misc.ASCIICaseInsensitiveComparator
chegar
parents:
34711
diff
changeset
|
344 |
} |
f0cd8358b5ea
8151384: Improve String.CASE_INSENSITIVE_ORDER and remove sun.misc.ASCIICaseInsensitiveComparator
chegar
parents:
34711
diff
changeset
|
345 |
|
33663 | 346 |
public static int hashCode(byte[] value) { |
347 |
int h = 0; |
|
348 |
int length = value.length >> 1; |
|
349 |
for (int i = 0; i < length; i++) { |
|
350 |
h = 31 * h + getChar(value, i); |
|
351 |
} |
|
352 |
return h; |
|
353 |
} |
|
354 |
||
355 |
public static int indexOf(byte[] value, int ch, int fromIndex) { |
|
356 |
int max = value.length >> 1; |
|
357 |
if (fromIndex < 0) { |
|
358 |
fromIndex = 0; |
|
359 |
} else if (fromIndex >= max) { |
|
360 |
// Note: fromIndex might be near -1>>>1. |
|
361 |
return -1; |
|
362 |
} |
|
363 |
if (ch < Character.MIN_SUPPLEMENTARY_CODE_POINT) { |
|
364 |
// handle most cases here (ch is a BMP code point or a |
|
365 |
// negative value (invalid code point)) |
|
366 |
return indexOfChar(value, ch, fromIndex, max); |
|
367 |
} else { |
|
368 |
return indexOfSupplementary(value, ch, fromIndex, max); |
|
369 |
} |
|
370 |
} |
|
371 |
||
372 |
@HotSpotIntrinsicCandidate |
|
373 |
public static int indexOf(byte[] value, byte[] str) { |
|
374 |
if (str.length == 0) { |
|
375 |
return 0; |
|
376 |
} |
|
44642
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
377 |
if (value.length < str.length) { |
33663 | 378 |
return -1; |
379 |
} |
|
44642
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
380 |
return indexOfUnsafe(value, length(value), str, length(str), 0); |
33663 | 381 |
} |
382 |
||
383 |
@HotSpotIntrinsicCandidate |
|
384 |
public static int indexOf(byte[] value, int valueCount, byte[] str, int strCount, int fromIndex) { |
|
44642
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
385 |
checkBoundsBeginEnd(fromIndex, valueCount, value); |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
386 |
checkBoundsBeginEnd(0, strCount, str); |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
387 |
return indexOfUnsafe(value, valueCount, str, strCount, fromIndex); |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
388 |
} |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
389 |
|
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
390 |
|
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
391 |
private static int indexOfUnsafe(byte[] value, int valueCount, byte[] str, int strCount, int fromIndex) { |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
392 |
assert fromIndex >= 0; |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
393 |
assert strCount > 0; |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
394 |
assert strCount <= length(str); |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
395 |
assert valueCount >= strCount; |
33663 | 396 |
char first = getChar(str, 0); |
397 |
int max = (valueCount - strCount); |
|
398 |
for (int i = fromIndex; i <= max; i++) { |
|
399 |
// Look for first character. |
|
400 |
if (getChar(value, i) != first) { |
|
401 |
while (++i <= max && getChar(value, i) != first); |
|
402 |
} |
|
403 |
// Found first character, now look at the rest of value |
|
404 |
if (i <= max) { |
|
405 |
int j = i + 1; |
|
406 |
int end = j + strCount - 1; |
|
407 |
for (int k = 1; j < end && getChar(value, j) == getChar(str, k); j++, k++); |
|
408 |
if (j == end) { |
|
409 |
// Found whole string. |
|
410 |
return i; |
|
411 |
} |
|
412 |
} |
|
413 |
} |
|
414 |
return -1; |
|
415 |
} |
|
416 |
||
44642
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
417 |
|
33663 | 418 |
/** |
419 |
* Handles indexOf Latin1 substring in UTF16 string. |
|
420 |
*/ |
|
421 |
@HotSpotIntrinsicCandidate |
|
422 |
public static int indexOfLatin1(byte[] value, byte[] str) { |
|
423 |
if (str.length == 0) { |
|
424 |
return 0; |
|
425 |
} |
|
44642
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
426 |
if (length(value) < str.length) { |
33663 | 427 |
return -1; |
428 |
} |
|
44642
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
429 |
return indexOfLatin1Unsafe(value, length(value), str, str.length, 0); |
33663 | 430 |
} |
431 |
||
432 |
@HotSpotIntrinsicCandidate |
|
433 |
public static int indexOfLatin1(byte[] src, int srcCount, byte[] tgt, int tgtCount, int fromIndex) { |
|
44642
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
434 |
checkBoundsBeginEnd(fromIndex, srcCount, src); |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
435 |
String.checkBoundsBeginEnd(0, tgtCount, tgt.length); |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
436 |
return indexOfLatin1Unsafe(src, srcCount, tgt, tgtCount, fromIndex); |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
437 |
} |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
438 |
|
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
439 |
public static int indexOfLatin1Unsafe(byte[] src, int srcCount, byte[] tgt, int tgtCount, int fromIndex) { |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
440 |
assert fromIndex >= 0; |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
441 |
assert tgtCount > 0; |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
442 |
assert tgtCount <= tgt.length; |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
443 |
assert srcCount >= tgtCount; |
33663 | 444 |
char first = (char)(tgt[0] & 0xff); |
445 |
int max = (srcCount - tgtCount); |
|
446 |
for (int i = fromIndex; i <= max; i++) { |
|
447 |
// Look for first character. |
|
448 |
if (getChar(src, i) != first) { |
|
449 |
while (++i <= max && getChar(src, i) != first); |
|
450 |
} |
|
451 |
// Found first character, now look at the rest of v2 |
|
452 |
if (i <= max) { |
|
453 |
int j = i + 1; |
|
454 |
int end = j + tgtCount - 1; |
|
455 |
for (int k = 1; |
|
456 |
j < end && getChar(src, j) == (tgt[k] & 0xff); |
|
457 |
j++, k++); |
|
458 |
if (j == end) { |
|
459 |
// Found whole string. |
|
460 |
return i; |
|
461 |
} |
|
462 |
} |
|
463 |
} |
|
464 |
return -1; |
|
465 |
} |
|
466 |
||
467 |
@HotSpotIntrinsicCandidate |
|
468 |
private static int indexOfChar(byte[] value, int ch, int fromIndex, int max) { |
|
44642
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
469 |
checkBoundsBeginEnd(fromIndex, max, value); |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
470 |
return indexOfCharUnsafe(value, ch, fromIndex, max); |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
471 |
} |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
472 |
|
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
473 |
private static int indexOfCharUnsafe(byte[] value, int ch, int fromIndex, int max) { |
33663 | 474 |
for (int i = fromIndex; i < max; i++) { |
475 |
if (getChar(value, i) == ch) { |
|
476 |
return i; |
|
477 |
} |
|
478 |
} |
|
479 |
return -1; |
|
480 |
} |
|
481 |
||
482 |
/** |
|
483 |
* Handles (rare) calls of indexOf with a supplementary character. |
|
484 |
*/ |
|
485 |
private static int indexOfSupplementary(byte[] value, int ch, int fromIndex, int max) { |
|
486 |
if (Character.isValidCodePoint(ch)) { |
|
487 |
final char hi = Character.highSurrogate(ch); |
|
488 |
final char lo = Character.lowSurrogate(ch); |
|
44642
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
489 |
checkBoundsBeginEnd(fromIndex, max, value); |
33663 | 490 |
for (int i = fromIndex; i < max - 1; i++) { |
491 |
if (getChar(value, i) == hi && getChar(value, i + 1 ) == lo) { |
|
492 |
return i; |
|
493 |
} |
|
494 |
} |
|
495 |
} |
|
496 |
return -1; |
|
497 |
} |
|
498 |
||
44642
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
499 |
// srcCoder == UTF16 && tgtCoder == UTF16 |
33663 | 500 |
public static int lastIndexOf(byte[] src, int srcCount, |
501 |
byte[] tgt, int tgtCount, int fromIndex) { |
|
44642
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
502 |
assert fromIndex >= 0; |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
503 |
assert tgtCount > 0; |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
504 |
assert tgtCount <= length(tgt); |
33663 | 505 |
int min = tgtCount - 1; |
506 |
int i = min + fromIndex; |
|
507 |
int strLastIndex = tgtCount - 1; |
|
44642
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
508 |
|
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
509 |
checkIndex(strLastIndex, tgt); |
33663 | 510 |
char strLastChar = getChar(tgt, strLastIndex); |
511 |
||
44642
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
512 |
checkIndex(i, src); |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
513 |
|
33663 | 514 |
startSearchForLastChar: |
515 |
while (true) { |
|
516 |
while (i >= min && getChar(src, i) != strLastChar) { |
|
517 |
i--; |
|
518 |
} |
|
519 |
if (i < min) { |
|
520 |
return -1; |
|
521 |
} |
|
522 |
int j = i - 1; |
|
523 |
int start = j - strLastIndex; |
|
524 |
int k = strLastIndex - 1; |
|
525 |
while (j > start) { |
|
526 |
if (getChar(src, j--) != getChar(tgt, k--)) { |
|
527 |
i--; |
|
528 |
continue startSearchForLastChar; |
|
529 |
} |
|
530 |
} |
|
531 |
return start + 1; |
|
532 |
} |
|
533 |
} |
|
534 |
||
535 |
public static int lastIndexOf(byte[] value, int ch, int fromIndex) { |
|
536 |
if (ch < Character.MIN_SUPPLEMENTARY_CODE_POINT) { |
|
537 |
// handle most cases here (ch is a BMP code point or a |
|
538 |
// negative value (invalid code point)) |
|
539 |
int i = Math.min(fromIndex, (value.length >> 1) - 1); |
|
540 |
for (; i >= 0; i--) { |
|
541 |
if (getChar(value, i) == ch) { |
|
542 |
return i; |
|
543 |
} |
|
544 |
} |
|
545 |
return -1; |
|
546 |
} else { |
|
547 |
return lastIndexOfSupplementary(value, ch, fromIndex); |
|
548 |
} |
|
549 |
} |
|
550 |
||
551 |
/** |
|
552 |
* Handles (rare) calls of lastIndexOf with a supplementary character. |
|
553 |
*/ |
|
554 |
private static int lastIndexOfSupplementary(final byte[] value, int ch, int fromIndex) { |
|
555 |
if (Character.isValidCodePoint(ch)) { |
|
556 |
char hi = Character.highSurrogate(ch); |
|
557 |
char lo = Character.lowSurrogate(ch); |
|
558 |
int i = Math.min(fromIndex, (value.length >> 1) - 2); |
|
559 |
for (; i >= 0; i--) { |
|
560 |
if (getChar(value, i) == hi && getChar(value, i + 1) == lo) { |
|
561 |
return i; |
|
562 |
} |
|
563 |
} |
|
564 |
} |
|
565 |
return -1; |
|
566 |
} |
|
567 |
||
568 |
public static String replace(byte[] value, char oldChar, char newChar) { |
|
569 |
int len = value.length >> 1; |
|
570 |
int i = -1; |
|
571 |
while (++i < len) { |
|
572 |
if (getChar(value, i) == oldChar) { |
|
573 |
break; |
|
574 |
} |
|
575 |
} |
|
576 |
if (i < len) { |
|
577 |
byte buf[] = new byte[value.length]; |
|
578 |
for (int j = 0; j < i; j++) { |
|
579 |
putChar(buf, j, getChar(value, j)); // TBD:arraycopy? |
|
580 |
} |
|
581 |
while (i < len) { |
|
582 |
char c = getChar(value, i); |
|
583 |
putChar(buf, i, c == oldChar ? newChar : c); |
|
584 |
i++; |
|
585 |
} |
|
586 |
// Check if we should try to compress to latin1 |
|
587 |
if (String.COMPACT_STRINGS && |
|
588 |
!StringLatin1.canEncode(oldChar) && |
|
589 |
StringLatin1.canEncode(newChar)) { |
|
590 |
byte[] val = compress(buf, 0, len); |
|
591 |
if (val != null) { |
|
592 |
return new String(val, LATIN1); |
|
593 |
} |
|
594 |
} |
|
595 |
return new String(buf, UTF16); |
|
596 |
} |
|
597 |
return null; |
|
598 |
} |
|
599 |
||
600 |
public static boolean regionMatchesCI(byte[] value, int toffset, |
|
601 |
byte[] other, int ooffset, int len) { |
|
602 |
int last = toffset + len; |
|
44642
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
603 |
assert toffset >= 0 && ooffset >= 0; |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
604 |
assert ooffset + len <= length(other); |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
605 |
assert last <= length(value); |
33663 | 606 |
while (toffset < last) { |
607 |
char c1 = getChar(value, toffset++); |
|
608 |
char c2 = getChar(other, ooffset++); |
|
609 |
if (c1 == c2) { |
|
610 |
continue; |
|
611 |
} |
|
612 |
// try converting both characters to uppercase. |
|
613 |
// If the results match, then the comparison scan should |
|
614 |
// continue. |
|
615 |
char u1 = Character.toUpperCase(c1); |
|
616 |
char u2 = Character.toUpperCase(c2); |
|
617 |
if (u1 == u2) { |
|
618 |
continue; |
|
619 |
} |
|
620 |
// Unfortunately, conversion to uppercase does not work properly |
|
621 |
// for the Georgian alphabet, which has strange rules about case |
|
622 |
// conversion. So we need to make one last check before |
|
623 |
// exiting. |
|
624 |
if (Character.toLowerCase(u1) == Character.toLowerCase(u2)) { |
|
625 |
continue; |
|
626 |
} |
|
627 |
return false; |
|
628 |
} |
|
629 |
return true; |
|
630 |
} |
|
631 |
||
632 |
public static boolean regionMatchesCI_Latin1(byte[] value, int toffset, |
|
633 |
byte[] other, int ooffset, |
|
634 |
int len) { |
|
39157 | 635 |
return StringLatin1.regionMatchesCI_UTF16(other, ooffset, value, toffset, len); |
33663 | 636 |
} |
637 |
||
638 |
public static String toLowerCase(String str, byte[] value, Locale locale) { |
|
639 |
if (locale == null) { |
|
640 |
throw new NullPointerException(); |
|
641 |
} |
|
642 |
int first; |
|
643 |
boolean hasSurr = false; |
|
644 |
final int len = value.length >> 1; |
|
645 |
||
646 |
// Now check if there are any characters that need to be changed, or are surrogate |
|
647 |
for (first = 0 ; first < len; first++) { |
|
648 |
int cp = (int)getChar(value, first); |
|
649 |
if (Character.isSurrogate((char)cp)) { |
|
650 |
hasSurr = true; |
|
651 |
break; |
|
652 |
} |
|
653 |
if (cp != Character.toLowerCase(cp)) { // no need to check Character.ERROR |
|
654 |
break; |
|
655 |
} |
|
656 |
} |
|
657 |
if (first == len) |
|
658 |
return str; |
|
659 |
byte[] result = new byte[value.length]; |
|
660 |
System.arraycopy(value, 0, result, 0, first << 1); // Just copy the first few |
|
661 |
// lowerCase characters. |
|
662 |
String lang = locale.getLanguage(); |
|
663 |
if (lang == "tr" || lang == "az" || lang == "lt") { |
|
664 |
return toLowerCaseEx(str, value, result, first, locale, true); |
|
665 |
} |
|
666 |
if (hasSurr) { |
|
667 |
return toLowerCaseEx(str, value, result, first, locale, false); |
|
668 |
} |
|
669 |
int bits = 0; |
|
670 |
for (int i = first; i < len; i++) { |
|
671 |
int cp = (int)getChar(value, i); |
|
672 |
if (cp == '\u03A3' || // GREEK CAPITAL LETTER SIGMA |
|
673 |
Character.isSurrogate((char)cp)) { |
|
674 |
return toLowerCaseEx(str, value, result, i, locale, false); |
|
675 |
} |
|
676 |
if (cp == '\u0130') { // LATIN CAPITAL LETTER I WITH DOT ABOVE |
|
677 |
return toLowerCaseEx(str, value, result, i, locale, true); |
|
678 |
} |
|
679 |
cp = Character.toLowerCase(cp); |
|
680 |
if (!Character.isBmpCodePoint(cp)) { |
|
681 |
return toLowerCaseEx(str, value, result, i, locale, false); |
|
682 |
} |
|
683 |
bits |= cp; |
|
684 |
putChar(result, i, cp); |
|
685 |
} |
|
34711
65544417508e
8145428: Optimize StringUTF16 compress/copy methods for C1
shade
parents:
34517
diff
changeset
|
686 |
if (bits > 0xFF) { |
33663 | 687 |
return new String(result, UTF16); |
688 |
} else { |
|
689 |
return newString(result, 0, len); |
|
690 |
} |
|
691 |
} |
|
692 |
||
693 |
private static String toLowerCaseEx(String str, byte[] value, |
|
694 |
byte[] result, int first, Locale locale, |
|
695 |
boolean localeDependent) { |
|
44642
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
696 |
assert(result.length == value.length); |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
697 |
assert(first >= 0); |
33663 | 698 |
int resultOffset = first; |
699 |
int length = value.length >> 1; |
|
700 |
int srcCount; |
|
701 |
for (int i = first; i < length; i += srcCount) { |
|
702 |
int srcChar = getChar(value, i); |
|
703 |
int lowerChar; |
|
704 |
char[] lowerCharArray; |
|
705 |
srcCount = 1; |
|
706 |
if (Character.isSurrogate((char)srcChar)) { |
|
707 |
srcChar = codePointAt(value, i, length); |
|
708 |
srcCount = Character.charCount(srcChar); |
|
709 |
} |
|
710 |
if (localeDependent || |
|
711 |
srcChar == '\u03A3' || // GREEK CAPITAL LETTER SIGMA |
|
712 |
srcChar == '\u0130') { // LATIN CAPITAL LETTER I WITH DOT ABOVE |
|
713 |
lowerChar = ConditionalSpecialCasing.toLowerCaseEx(str, i, locale); |
|
714 |
} else { |
|
715 |
lowerChar = Character.toLowerCase(srcChar); |
|
716 |
} |
|
717 |
if (Character.isBmpCodePoint(lowerChar)) { // Character.ERROR is not a bmp |
|
718 |
putChar(result, resultOffset++, lowerChar); |
|
719 |
} else { |
|
720 |
if (lowerChar == Character.ERROR) { |
|
721 |
lowerCharArray = ConditionalSpecialCasing.toLowerCaseCharArray(str, i, locale); |
|
722 |
} else { |
|
723 |
lowerCharArray = Character.toChars(lowerChar); |
|
724 |
} |
|
725 |
/* Grow result if needed */ |
|
726 |
int mapLen = lowerCharArray.length; |
|
727 |
if (mapLen > srcCount) { |
|
728 |
byte[] result2 = newBytesFor((result.length >> 1) + mapLen - srcCount); |
|
729 |
System.arraycopy(result, 0, result2, 0, resultOffset << 1); |
|
730 |
result = result2; |
|
731 |
} |
|
44642
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
732 |
assert resultOffset >= 0; |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
733 |
assert resultOffset + mapLen <= length(result); |
33663 | 734 |
for (int x = 0; x < mapLen; ++x) { |
735 |
putChar(result, resultOffset++, lowerCharArray[x]); |
|
736 |
} |
|
737 |
} |
|
738 |
} |
|
739 |
return newString(result, 0, resultOffset); |
|
740 |
} |
|
741 |
||
742 |
public static String toUpperCase(String str, byte[] value, Locale locale) { |
|
743 |
if (locale == null) { |
|
744 |
throw new NullPointerException(); |
|
745 |
} |
|
746 |
int first; |
|
747 |
boolean hasSurr = false; |
|
748 |
final int len = value.length >> 1; |
|
749 |
||
750 |
// Now check if there are any characters that need to be changed, or are surrogate |
|
751 |
for (first = 0 ; first < len; first++) { |
|
752 |
int cp = (int)getChar(value, first); |
|
753 |
if (Character.isSurrogate((char)cp)) { |
|
754 |
hasSurr = true; |
|
755 |
break; |
|
756 |
} |
|
757 |
if (cp != Character.toUpperCaseEx(cp)) { // no need to check Character.ERROR |
|
758 |
break; |
|
759 |
} |
|
760 |
} |
|
761 |
if (first == len) { |
|
762 |
return str; |
|
763 |
} |
|
764 |
byte[] result = new byte[value.length]; |
|
765 |
System.arraycopy(value, 0, result, 0, first << 1); // Just copy the first few |
|
766 |
// upperCase characters. |
|
767 |
String lang = locale.getLanguage(); |
|
768 |
if (lang == "tr" || lang == "az" || lang == "lt") { |
|
769 |
return toUpperCaseEx(str, value, result, first, locale, true); |
|
770 |
} |
|
771 |
if (hasSurr) { |
|
772 |
return toUpperCaseEx(str, value, result, first, locale, false); |
|
773 |
} |
|
774 |
int bits = 0; |
|
775 |
for (int i = first; i < len; i++) { |
|
776 |
int cp = (int)getChar(value, i); |
|
777 |
if (Character.isSurrogate((char)cp)) { |
|
778 |
return toUpperCaseEx(str, value, result, i, locale, false); |
|
779 |
} |
|
780 |
cp = Character.toUpperCaseEx(cp); |
|
781 |
if (!Character.isBmpCodePoint(cp)) { // Character.ERROR is not bmp |
|
782 |
return toUpperCaseEx(str, value, result, i, locale, false); |
|
783 |
} |
|
784 |
bits |= cp; |
|
785 |
putChar(result, i, cp); |
|
786 |
} |
|
34711
65544417508e
8145428: Optimize StringUTF16 compress/copy methods for C1
shade
parents:
34517
diff
changeset
|
787 |
if (bits > 0xFF) { |
33663 | 788 |
return new String(result, UTF16); |
789 |
} else { |
|
790 |
return newString(result, 0, len); |
|
791 |
} |
|
792 |
} |
|
793 |
||
794 |
private static String toUpperCaseEx(String str, byte[] value, |
|
795 |
byte[] result, int first, |
|
796 |
Locale locale, boolean localeDependent) |
|
797 |
{ |
|
44642
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
798 |
assert(result.length == value.length); |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
799 |
assert(first >= 0); |
33663 | 800 |
int resultOffset = first; |
801 |
int length = value.length >> 1; |
|
802 |
int srcCount; |
|
803 |
for (int i = first; i < length; i += srcCount) { |
|
804 |
int srcChar = getChar(value, i); |
|
805 |
int upperChar; |
|
806 |
char[] upperCharArray; |
|
807 |
srcCount = 1; |
|
808 |
if (Character.isSurrogate((char)srcChar)) { |
|
809 |
srcChar = codePointAt(value, i, length); |
|
810 |
srcCount = Character.charCount(srcChar); |
|
811 |
} |
|
812 |
if (localeDependent) { |
|
813 |
upperChar = ConditionalSpecialCasing.toUpperCaseEx(str, i, locale); |
|
814 |
} else { |
|
815 |
upperChar = Character.toUpperCaseEx(srcChar); |
|
816 |
} |
|
817 |
if (Character.isBmpCodePoint(upperChar)) { |
|
818 |
putChar(result, resultOffset++, upperChar); |
|
819 |
} else { |
|
820 |
if (upperChar == Character.ERROR) { |
|
821 |
if (localeDependent) { |
|
822 |
upperCharArray = |
|
823 |
ConditionalSpecialCasing.toUpperCaseCharArray(str, i, locale); |
|
824 |
} else { |
|
825 |
upperCharArray = Character.toUpperCaseCharArray(srcChar); |
|
826 |
} |
|
827 |
} else { |
|
828 |
upperCharArray = Character.toChars(upperChar); |
|
829 |
} |
|
830 |
/* Grow result if needed */ |
|
831 |
int mapLen = upperCharArray.length; |
|
832 |
if (mapLen > srcCount) { |
|
833 |
byte[] result2 = newBytesFor((result.length >> 1) + mapLen - srcCount); |
|
834 |
System.arraycopy(result, 0, result2, 0, resultOffset << 1); |
|
835 |
result = result2; |
|
44642
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
836 |
} |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
837 |
assert resultOffset >= 0; |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
838 |
assert resultOffset + mapLen <= length(result); |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
839 |
for (int x = 0; x < mapLen; ++x) { |
33663 | 840 |
putChar(result, resultOffset++, upperCharArray[x]); |
44642
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
841 |
} |
33663 | 842 |
} |
843 |
} |
|
844 |
return newString(result, 0, resultOffset); |
|
845 |
} |
|
846 |
||
847 |
public static String trim(byte[] value) { |
|
848 |
int length = value.length >> 1; |
|
849 |
int len = length; |
|
850 |
int st = 0; |
|
851 |
while (st < len && getChar(value, st) <= ' ') { |
|
852 |
st++; |
|
853 |
} |
|
854 |
while (st < len && getChar(value, len - 1) <= ' ') { |
|
855 |
len--; |
|
856 |
} |
|
857 |
return ((st > 0) || (len < length )) ? |
|
858 |
new String(Arrays.copyOfRange(value, st << 1, len << 1), UTF16) : |
|
859 |
null; |
|
860 |
} |
|
861 |
||
50098
92560438d306
8200377: String::strip, String::stripLeading, String::stripTrailing
jlaskey
parents:
49129
diff
changeset
|
862 |
|
92560438d306
8200377: String::strip, String::stripLeading, String::stripTrailing
jlaskey
parents:
49129
diff
changeset
|
863 |
public static int indexOfNonWhitespace(byte[] value) { |
92560438d306
8200377: String::strip, String::stripLeading, String::stripTrailing
jlaskey
parents:
49129
diff
changeset
|
864 |
int length = value.length >> 1; |
92560438d306
8200377: String::strip, String::stripLeading, String::stripTrailing
jlaskey
parents:
49129
diff
changeset
|
865 |
int left = 0; |
92560438d306
8200377: String::strip, String::stripLeading, String::stripTrailing
jlaskey
parents:
49129
diff
changeset
|
866 |
while (left < length) { |
92560438d306
8200377: String::strip, String::stripLeading, String::stripTrailing
jlaskey
parents:
49129
diff
changeset
|
867 |
int codepoint = codePointAt(value, left, length); |
92560438d306
8200377: String::strip, String::stripLeading, String::stripTrailing
jlaskey
parents:
49129
diff
changeset
|
868 |
if (codepoint != ' ' && codepoint != '\t' && !Character.isWhitespace(codepoint)) { |
92560438d306
8200377: String::strip, String::stripLeading, String::stripTrailing
jlaskey
parents:
49129
diff
changeset
|
869 |
break; |
92560438d306
8200377: String::strip, String::stripLeading, String::stripTrailing
jlaskey
parents:
49129
diff
changeset
|
870 |
} |
92560438d306
8200377: String::strip, String::stripLeading, String::stripTrailing
jlaskey
parents:
49129
diff
changeset
|
871 |
left += Character.charCount(codepoint); |
92560438d306
8200377: String::strip, String::stripLeading, String::stripTrailing
jlaskey
parents:
49129
diff
changeset
|
872 |
} |
92560438d306
8200377: String::strip, String::stripLeading, String::stripTrailing
jlaskey
parents:
49129
diff
changeset
|
873 |
return left; |
92560438d306
8200377: String::strip, String::stripLeading, String::stripTrailing
jlaskey
parents:
49129
diff
changeset
|
874 |
} |
92560438d306
8200377: String::strip, String::stripLeading, String::stripTrailing
jlaskey
parents:
49129
diff
changeset
|
875 |
|
92560438d306
8200377: String::strip, String::stripLeading, String::stripTrailing
jlaskey
parents:
49129
diff
changeset
|
876 |
public static int lastIndexOfNonWhitespace(byte[] value) { |
92560438d306
8200377: String::strip, String::stripLeading, String::stripTrailing
jlaskey
parents:
49129
diff
changeset
|
877 |
int length = value.length >> 1; |
92560438d306
8200377: String::strip, String::stripLeading, String::stripTrailing
jlaskey
parents:
49129
diff
changeset
|
878 |
int right = length; |
92560438d306
8200377: String::strip, String::stripLeading, String::stripTrailing
jlaskey
parents:
49129
diff
changeset
|
879 |
while (0 < right) { |
92560438d306
8200377: String::strip, String::stripLeading, String::stripTrailing
jlaskey
parents:
49129
diff
changeset
|
880 |
int codepoint = codePointBefore(value, right); |
92560438d306
8200377: String::strip, String::stripLeading, String::stripTrailing
jlaskey
parents:
49129
diff
changeset
|
881 |
if (codepoint != ' ' && codepoint != '\t' && !Character.isWhitespace(codepoint)) { |
92560438d306
8200377: String::strip, String::stripLeading, String::stripTrailing
jlaskey
parents:
49129
diff
changeset
|
882 |
break; |
92560438d306
8200377: String::strip, String::stripLeading, String::stripTrailing
jlaskey
parents:
49129
diff
changeset
|
883 |
} |
92560438d306
8200377: String::strip, String::stripLeading, String::stripTrailing
jlaskey
parents:
49129
diff
changeset
|
884 |
right -= Character.charCount(codepoint); |
92560438d306
8200377: String::strip, String::stripLeading, String::stripTrailing
jlaskey
parents:
49129
diff
changeset
|
885 |
} |
92560438d306
8200377: String::strip, String::stripLeading, String::stripTrailing
jlaskey
parents:
49129
diff
changeset
|
886 |
return right; |
92560438d306
8200377: String::strip, String::stripLeading, String::stripTrailing
jlaskey
parents:
49129
diff
changeset
|
887 |
} |
92560438d306
8200377: String::strip, String::stripLeading, String::stripTrailing
jlaskey
parents:
49129
diff
changeset
|
888 |
|
92560438d306
8200377: String::strip, String::stripLeading, String::stripTrailing
jlaskey
parents:
49129
diff
changeset
|
889 |
public static String strip(byte[] value) { |
92560438d306
8200377: String::strip, String::stripLeading, String::stripTrailing
jlaskey
parents:
49129
diff
changeset
|
890 |
int length = value.length >> 1; |
92560438d306
8200377: String::strip, String::stripLeading, String::stripTrailing
jlaskey
parents:
49129
diff
changeset
|
891 |
int left = indexOfNonWhitespace(value); |
92560438d306
8200377: String::strip, String::stripLeading, String::stripTrailing
jlaskey
parents:
49129
diff
changeset
|
892 |
if (left == length) { |
92560438d306
8200377: String::strip, String::stripLeading, String::stripTrailing
jlaskey
parents:
49129
diff
changeset
|
893 |
return ""; |
92560438d306
8200377: String::strip, String::stripLeading, String::stripTrailing
jlaskey
parents:
49129
diff
changeset
|
894 |
} |
92560438d306
8200377: String::strip, String::stripLeading, String::stripTrailing
jlaskey
parents:
49129
diff
changeset
|
895 |
int right = lastIndexOfNonWhitespace(value); |
92560438d306
8200377: String::strip, String::stripLeading, String::stripTrailing
jlaskey
parents:
49129
diff
changeset
|
896 |
return ((left > 0) || (right < length)) ? newString(value, left, right - left) : null; |
92560438d306
8200377: String::strip, String::stripLeading, String::stripTrailing
jlaskey
parents:
49129
diff
changeset
|
897 |
} |
92560438d306
8200377: String::strip, String::stripLeading, String::stripTrailing
jlaskey
parents:
49129
diff
changeset
|
898 |
|
92560438d306
8200377: String::strip, String::stripLeading, String::stripTrailing
jlaskey
parents:
49129
diff
changeset
|
899 |
public static String stripLeading(byte[] value) { |
92560438d306
8200377: String::strip, String::stripLeading, String::stripTrailing
jlaskey
parents:
49129
diff
changeset
|
900 |
int length = value.length >> 1; |
92560438d306
8200377: String::strip, String::stripLeading, String::stripTrailing
jlaskey
parents:
49129
diff
changeset
|
901 |
int left = indexOfNonWhitespace(value); |
92560438d306
8200377: String::strip, String::stripLeading, String::stripTrailing
jlaskey
parents:
49129
diff
changeset
|
902 |
if (left == length) { |
92560438d306
8200377: String::strip, String::stripLeading, String::stripTrailing
jlaskey
parents:
49129
diff
changeset
|
903 |
return ""; |
92560438d306
8200377: String::strip, String::stripLeading, String::stripTrailing
jlaskey
parents:
49129
diff
changeset
|
904 |
} |
92560438d306
8200377: String::strip, String::stripLeading, String::stripTrailing
jlaskey
parents:
49129
diff
changeset
|
905 |
return (left != 0) ? newString(value, left, length - left) : null; |
92560438d306
8200377: String::strip, String::stripLeading, String::stripTrailing
jlaskey
parents:
49129
diff
changeset
|
906 |
} |
92560438d306
8200377: String::strip, String::stripLeading, String::stripTrailing
jlaskey
parents:
49129
diff
changeset
|
907 |
|
92560438d306
8200377: String::strip, String::stripLeading, String::stripTrailing
jlaskey
parents:
49129
diff
changeset
|
908 |
public static String stripTrailing(byte[] value) { |
92560438d306
8200377: String::strip, String::stripLeading, String::stripTrailing
jlaskey
parents:
49129
diff
changeset
|
909 |
int length = value.length >> 1; |
92560438d306
8200377: String::strip, String::stripLeading, String::stripTrailing
jlaskey
parents:
49129
diff
changeset
|
910 |
int right = lastIndexOfNonWhitespace(value); |
92560438d306
8200377: String::strip, String::stripLeading, String::stripTrailing
jlaskey
parents:
49129
diff
changeset
|
911 |
if (right == 0) { |
92560438d306
8200377: String::strip, String::stripLeading, String::stripTrailing
jlaskey
parents:
49129
diff
changeset
|
912 |
return ""; |
92560438d306
8200377: String::strip, String::stripLeading, String::stripTrailing
jlaskey
parents:
49129
diff
changeset
|
913 |
} |
92560438d306
8200377: String::strip, String::stripLeading, String::stripTrailing
jlaskey
parents:
49129
diff
changeset
|
914 |
return (right != length) ? newString(value, 0, right) : null; |
92560438d306
8200377: String::strip, String::stripLeading, String::stripTrailing
jlaskey
parents:
49129
diff
changeset
|
915 |
} |
92560438d306
8200377: String::strip, String::stripLeading, String::stripTrailing
jlaskey
parents:
49129
diff
changeset
|
916 |
|
50215 | 917 |
private final static class LinesSpliterator implements Spliterator<String> { |
918 |
private byte[] value; |
|
919 |
private int index; // current index, modified on advance/split |
|
920 |
private final int fence; // one past last index |
|
921 |
||
922 |
LinesSpliterator(byte[] value) { |
|
923 |
this(value, 0, value.length >>> 1); |
|
924 |
} |
|
925 |
||
926 |
LinesSpliterator(byte[] value, int start, int length) { |
|
927 |
this.value = value; |
|
928 |
this.index = start; |
|
929 |
this.fence = start + length; |
|
930 |
} |
|
931 |
||
932 |
private int indexOfLineSeparator(int start) { |
|
933 |
for (int current = start; current < fence; current++) { |
|
934 |
char ch = getChar(value, current); |
|
935 |
if (ch == '\n' || ch == '\r') { |
|
936 |
return current; |
|
937 |
} |
|
938 |
} |
|
939 |
return fence; |
|
940 |
} |
|
941 |
||
942 |
private int skipLineSeparator(int start) { |
|
943 |
if (start < fence) { |
|
944 |
if (getChar(value, start) == '\r') { |
|
945 |
int next = start + 1; |
|
946 |
if (next < fence && getChar(value, next) == '\n') { |
|
947 |
return next + 1; |
|
948 |
} |
|
949 |
} |
|
950 |
return start + 1; |
|
951 |
} |
|
952 |
return fence; |
|
953 |
} |
|
954 |
||
955 |
private String next() { |
|
956 |
int start = index; |
|
957 |
int end = indexOfLineSeparator(start); |
|
958 |
index = skipLineSeparator(end); |
|
959 |
return newString(value, start, end - start); |
|
960 |
} |
|
961 |
||
962 |
@Override |
|
963 |
public boolean tryAdvance(Consumer<? super String> action) { |
|
964 |
if (action == null) { |
|
965 |
throw new NullPointerException("tryAdvance action missing"); |
|
966 |
} |
|
967 |
if (index != fence) { |
|
968 |
action.accept(next()); |
|
969 |
return true; |
|
970 |
} |
|
971 |
return false; |
|
972 |
} |
|
973 |
||
974 |
@Override |
|
975 |
public void forEachRemaining(Consumer<? super String> action) { |
|
976 |
if (action == null) { |
|
977 |
throw new NullPointerException("forEachRemaining action missing"); |
|
978 |
} |
|
979 |
while (index != fence) { |
|
980 |
action.accept(next()); |
|
981 |
} |
|
982 |
} |
|
983 |
||
984 |
@Override |
|
985 |
public Spliterator<String> trySplit() { |
|
986 |
int half = (fence + index) >>> 1; |
|
987 |
int mid = skipLineSeparator(indexOfLineSeparator(half)); |
|
988 |
if (mid < fence) { |
|
989 |
int start = index; |
|
990 |
index = mid; |
|
991 |
return new LinesSpliterator(value, start, mid - start); |
|
992 |
} |
|
993 |
return null; |
|
994 |
} |
|
995 |
||
996 |
@Override |
|
997 |
public long estimateSize() { |
|
998 |
return fence - index + 1; |
|
999 |
} |
|
1000 |
||
1001 |
@Override |
|
1002 |
public int characteristics() { |
|
1003 |
return Spliterator.ORDERED | Spliterator.IMMUTABLE | Spliterator.NONNULL; |
|
1004 |
} |
|
1005 |
} |
|
1006 |
||
1007 |
static Stream<String> lines(byte[] value) { |
|
1008 |
return StreamSupport.stream(new LinesSpliterator(value), false); |
|
1009 |
} |
|
1010 |
||
44642
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1011 |
private static void putChars(byte[] val, int index, char[] str, int off, int end) { |
33663 | 1012 |
while (off < end) { |
1013 |
putChar(val, index++, str[off++]); |
|
1014 |
} |
|
1015 |
} |
|
1016 |
||
1017 |
public static String newString(byte[] val, int index, int len) { |
|
1018 |
if (String.COMPACT_STRINGS) { |
|
1019 |
byte[] buf = compress(val, index, len); |
|
1020 |
if (buf != null) { |
|
1021 |
return new String(buf, LATIN1); |
|
1022 |
} |
|
1023 |
} |
|
1024 |
int last = index + len; |
|
1025 |
return new String(Arrays.copyOfRange(val, index << 1, last << 1), UTF16); |
|
1026 |
} |
|
1027 |
||
1028 |
public static void fillNull(byte[] val, int index, int end) { |
|
1029 |
Arrays.fill(val, index << 1, end << 1, (byte)0); |
|
1030 |
} |
|
1031 |
||
1032 |
static class CharsSpliterator implements Spliterator.OfInt { |
|
1033 |
private final byte[] array; |
|
1034 |
private int index; // current index, modified on advance/split |
|
1035 |
private final int fence; // one past last index |
|
1036 |
private final int cs; |
|
1037 |
||
1038 |
CharsSpliterator(byte[] array, int acs) { |
|
1039 |
this(array, 0, array.length >> 1, acs); |
|
1040 |
} |
|
1041 |
||
1042 |
CharsSpliterator(byte[] array, int origin, int fence, int acs) { |
|
1043 |
this.array = array; |
|
1044 |
this.index = origin; |
|
1045 |
this.fence = fence; |
|
1046 |
this.cs = acs | Spliterator.ORDERED | Spliterator.SIZED |
|
1047 |
| Spliterator.SUBSIZED; |
|
1048 |
} |
|
1049 |
||
1050 |
@Override |
|
1051 |
public OfInt trySplit() { |
|
1052 |
int lo = index, mid = (lo + fence) >>> 1; |
|
1053 |
return (lo >= mid) |
|
1054 |
? null |
|
1055 |
: new CharsSpliterator(array, lo, index = mid, cs); |
|
1056 |
} |
|
1057 |
||
1058 |
@Override |
|
1059 |
public void forEachRemaining(IntConsumer action) { |
|
1060 |
byte[] a; int i, hi; // hoist accesses and checks from loop |
|
1061 |
if (action == null) |
|
1062 |
throw new NullPointerException(); |
|
1063 |
if (((a = array).length >> 1) >= (hi = fence) && |
|
1064 |
(i = index) >= 0 && i < (index = hi)) { |
|
42346
c0c6d5d20c35
8170155: StringBuffer and StringBuilder stream methods are not late-binding
psandoz
parents:
39157
diff
changeset
|
1065 |
do { |
c0c6d5d20c35
8170155: StringBuffer and StringBuilder stream methods are not late-binding
psandoz
parents:
39157
diff
changeset
|
1066 |
action.accept(charAt(a, i)); |
c0c6d5d20c35
8170155: StringBuffer and StringBuilder stream methods are not late-binding
psandoz
parents:
39157
diff
changeset
|
1067 |
} while (++i < hi); |
33663 | 1068 |
} |
1069 |
} |
|
1070 |
||
1071 |
@Override |
|
1072 |
public boolean tryAdvance(IntConsumer action) { |
|
1073 |
if (action == null) |
|
1074 |
throw new NullPointerException(); |
|
42346
c0c6d5d20c35
8170155: StringBuffer and StringBuilder stream methods are not late-binding
psandoz
parents:
39157
diff
changeset
|
1075 |
int i = index; |
c0c6d5d20c35
8170155: StringBuffer and StringBuilder stream methods are not late-binding
psandoz
parents:
39157
diff
changeset
|
1076 |
if (i >= 0 && i < fence) { |
c0c6d5d20c35
8170155: StringBuffer and StringBuilder stream methods are not late-binding
psandoz
parents:
39157
diff
changeset
|
1077 |
action.accept(charAt(array, i)); |
c0c6d5d20c35
8170155: StringBuffer and StringBuilder stream methods are not late-binding
psandoz
parents:
39157
diff
changeset
|
1078 |
index++; |
33663 | 1079 |
return true; |
1080 |
} |
|
1081 |
return false; |
|
1082 |
} |
|
1083 |
||
1084 |
@Override |
|
1085 |
public long estimateSize() { return (long)(fence - index); } |
|
1086 |
||
1087 |
@Override |
|
1088 |
public int characteristics() { |
|
1089 |
return cs; |
|
1090 |
} |
|
1091 |
} |
|
1092 |
||
1093 |
static class CodePointsSpliterator implements Spliterator.OfInt { |
|
1094 |
private final byte[] array; |
|
1095 |
private int index; // current index, modified on advance/split |
|
1096 |
private final int fence; // one past last index |
|
1097 |
private final int cs; |
|
1098 |
||
1099 |
CodePointsSpliterator(byte[] array, int acs) { |
|
1100 |
this(array, 0, array.length >> 1, acs); |
|
1101 |
} |
|
1102 |
||
1103 |
CodePointsSpliterator(byte[] array, int origin, int fence, int acs) { |
|
1104 |
this.array = array; |
|
1105 |
this.index = origin; |
|
1106 |
this.fence = fence; |
|
1107 |
this.cs = acs | Spliterator.ORDERED; |
|
1108 |
} |
|
1109 |
||
1110 |
@Override |
|
1111 |
public OfInt trySplit() { |
|
1112 |
int lo = index, mid = (lo + fence) >>> 1; |
|
1113 |
if (lo >= mid) |
|
1114 |
return null; |
|
1115 |
||
1116 |
int midOneLess; |
|
1117 |
// If the mid-point intersects a surrogate pair |
|
42346
c0c6d5d20c35
8170155: StringBuffer and StringBuilder stream methods are not late-binding
psandoz
parents:
39157
diff
changeset
|
1118 |
if (Character.isLowSurrogate(charAt(array, mid)) && |
c0c6d5d20c35
8170155: StringBuffer and StringBuilder stream methods are not late-binding
psandoz
parents:
39157
diff
changeset
|
1119 |
Character.isHighSurrogate(charAt(array, midOneLess = (mid -1)))) { |
33663 | 1120 |
// If there is only one pair it cannot be split |
1121 |
if (lo >= midOneLess) |
|
1122 |
return null; |
|
1123 |
// Shift the mid-point to align with the surrogate pair |
|
1124 |
return new CodePointsSpliterator(array, lo, index = midOneLess, cs); |
|
1125 |
} |
|
1126 |
return new CodePointsSpliterator(array, lo, index = mid, cs); |
|
1127 |
} |
|
1128 |
||
1129 |
@Override |
|
1130 |
public void forEachRemaining(IntConsumer action) { |
|
1131 |
byte[] a; int i, hi; // hoist accesses and checks from loop |
|
1132 |
if (action == null) |
|
1133 |
throw new NullPointerException(); |
|
1134 |
if (((a = array).length >> 1) >= (hi = fence) && |
|
1135 |
(i = index) >= 0 && i < (index = hi)) { |
|
1136 |
do { |
|
1137 |
i = advance(a, i, hi, action); |
|
1138 |
} while (i < hi); |
|
1139 |
} |
|
1140 |
} |
|
1141 |
||
1142 |
@Override |
|
1143 |
public boolean tryAdvance(IntConsumer action) { |
|
1144 |
if (action == null) |
|
1145 |
throw new NullPointerException(); |
|
1146 |
if (index >= 0 && index < fence) { |
|
1147 |
index = advance(array, index, fence, action); |
|
1148 |
return true; |
|
1149 |
} |
|
1150 |
return false; |
|
1151 |
} |
|
1152 |
||
1153 |
// Advance one code point from the index, i, and return the next |
|
1154 |
// index to advance from |
|
1155 |
private static int advance(byte[] a, int i, int hi, IntConsumer action) { |
|
42346
c0c6d5d20c35
8170155: StringBuffer and StringBuilder stream methods are not late-binding
psandoz
parents:
39157
diff
changeset
|
1156 |
char c1 = charAt(a, i++); |
33663 | 1157 |
int cp = c1; |
1158 |
if (Character.isHighSurrogate(c1) && i < hi) { |
|
42346
c0c6d5d20c35
8170155: StringBuffer and StringBuilder stream methods are not late-binding
psandoz
parents:
39157
diff
changeset
|
1159 |
char c2 = charAt(a, i); |
33663 | 1160 |
if (Character.isLowSurrogate(c2)) { |
1161 |
i++; |
|
1162 |
cp = Character.toCodePoint(c1, c2); |
|
1163 |
} |
|
1164 |
} |
|
1165 |
action.accept(cp); |
|
1166 |
return i; |
|
1167 |
} |
|
1168 |
||
1169 |
@Override |
|
1170 |
public long estimateSize() { return (long)(fence - index); } |
|
1171 |
||
1172 |
@Override |
|
1173 |
public int characteristics() { |
|
1174 |
return cs; |
|
1175 |
} |
|
1176 |
} |
|
1177 |
||
1178 |
//////////////////////////////////////////////////////////////// |
|
1179 |
||
1180 |
public static void putCharSB(byte[] val, int index, int c) { |
|
44642
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1181 |
checkIndex(index, val); |
33663 | 1182 |
putChar(val, index, c); |
1183 |
} |
|
1184 |
||
1185 |
public static void putCharsSB(byte[] val, int index, char[] ca, int off, int end) { |
|
44642
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1186 |
checkBoundsBeginEnd(index, index + end - off, val); |
33663 | 1187 |
putChars(val, index, ca, off, end); |
1188 |
} |
|
1189 |
||
1190 |
public static void putCharsSB(byte[] val, int index, CharSequence s, int off, int end) { |
|
44642
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1191 |
checkBoundsBeginEnd(index, index + end - off, val); |
33663 | 1192 |
for (int i = off; i < end; i++) { |
1193 |
putChar(val, index++, s.charAt(i)); |
|
1194 |
} |
|
1195 |
} |
|
1196 |
||
1197 |
public static int codePointAtSB(byte[] val, int index, int end) { |
|
44642
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1198 |
return codePointAt(val, index, end, true /* checked */); |
33663 | 1199 |
} |
1200 |
||
1201 |
public static int codePointBeforeSB(byte[] val, int index) { |
|
44642
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1202 |
return codePointBefore(val, index, true /* checked */); |
33663 | 1203 |
} |
1204 |
||
1205 |
public static int codePointCountSB(byte[] val, int beginIndex, int endIndex) { |
|
44642
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1206 |
return codePointCount(val, beginIndex, endIndex, true /* checked */); |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1207 |
} |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1208 |
|
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1209 |
public static int getChars(int i, int begin, int end, byte[] value) { |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1210 |
checkBoundsBeginEnd(begin, end, value); |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1211 |
int pos = getChars(i, end, value); |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1212 |
assert begin == pos; |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1213 |
return pos; |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1214 |
} |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1215 |
|
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1216 |
public static int getChars(long l, int begin, int end, byte[] value) { |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1217 |
checkBoundsBeginEnd(begin, end, value); |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1218 |
int pos = getChars(l, end, value); |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1219 |
assert begin == pos; |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1220 |
return pos; |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1221 |
} |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1222 |
|
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1223 |
public static boolean contentEquals(byte[] v1, byte[] v2, int len) { |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1224 |
checkBoundsOffCount(0, len, v2); |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1225 |
for (int i = 0; i < len; i++) { |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1226 |
if ((char)(v1[i] & 0xff) != getChar(v2, i)) { |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1227 |
return false; |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1228 |
} |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1229 |
} |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1230 |
return true; |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1231 |
} |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1232 |
|
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1233 |
public static boolean contentEquals(byte[] value, CharSequence cs, int len) { |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1234 |
checkOffset(len, value); |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1235 |
for (int i = 0; i < len; i++) { |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1236 |
if (getChar(value, i) != cs.charAt(i)) { |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1237 |
return false; |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1238 |
} |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1239 |
} |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1240 |
return true; |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1241 |
} |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1242 |
|
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1243 |
public static int putCharsAt(byte[] value, int i, char c1, char c2, char c3, char c4) { |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1244 |
int end = i + 4; |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1245 |
checkBoundsBeginEnd(i, end, value); |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1246 |
putChar(value, i++, c1); |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1247 |
putChar(value, i++, c2); |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1248 |
putChar(value, i++, c3); |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1249 |
putChar(value, i++, c4); |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1250 |
assert(i == end); |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1251 |
return end; |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1252 |
} |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1253 |
|
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1254 |
public static int putCharsAt(byte[] value, int i, char c1, char c2, char c3, char c4, char c5) { |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1255 |
int end = i + 5; |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1256 |
checkBoundsBeginEnd(i, end, value); |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1257 |
putChar(value, i++, c1); |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1258 |
putChar(value, i++, c2); |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1259 |
putChar(value, i++, c3); |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1260 |
putChar(value, i++, c4); |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1261 |
putChar(value, i++, c5); |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1262 |
assert(i == end); |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1263 |
return end; |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1264 |
} |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1265 |
|
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1266 |
public static char charAt(byte[] value, int index) { |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1267 |
checkIndex(index, value); |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1268 |
return getChar(value, index); |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1269 |
} |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1270 |
|
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1271 |
public static void reverse(byte[] val, int count) { |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1272 |
checkOffset(count, val); |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1273 |
int n = count - 1; |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1274 |
boolean hasSurrogates = false; |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1275 |
for (int j = (n-1) >> 1; j >= 0; j--) { |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1276 |
int k = n - j; |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1277 |
char cj = getChar(val, j); |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1278 |
char ck = getChar(val, k); |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1279 |
putChar(val, j, ck); |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1280 |
putChar(val, k, cj); |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1281 |
if (Character.isSurrogate(cj) || |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1282 |
Character.isSurrogate(ck)) { |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1283 |
hasSurrogates = true; |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1284 |
} |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1285 |
} |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1286 |
if (hasSurrogates) { |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1287 |
reverseAllValidSurrogatePairs(val, count); |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1288 |
} |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1289 |
} |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1290 |
|
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1291 |
/** Outlined helper method for reverse() */ |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1292 |
private static void reverseAllValidSurrogatePairs(byte[] val, int count) { |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1293 |
for (int i = 0; i < count - 1; i++) { |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1294 |
char c2 = getChar(val, i); |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1295 |
if (Character.isLowSurrogate(c2)) { |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1296 |
char c1 = getChar(val, i + 1); |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1297 |
if (Character.isHighSurrogate(c1)) { |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1298 |
putChar(val, i++, c1); |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1299 |
putChar(val, i, c2); |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1300 |
} |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1301 |
} |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1302 |
} |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1303 |
} |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1304 |
|
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1305 |
// inflatedCopy byte[] -> byte[] |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1306 |
public static void inflate(byte[] src, int srcOff, byte[] dst, int dstOff, int len) { |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1307 |
// We need a range check here because 'putChar' has no checks |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1308 |
checkBoundsOffCount(dstOff, len, dst); |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1309 |
for (int i = 0; i < len; i++) { |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1310 |
putChar(dst, dstOff++, src[srcOff++] & 0xff); |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1311 |
} |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1312 |
} |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1313 |
|
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1314 |
// srcCoder == UTF16 && tgtCoder == LATIN1 |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1315 |
public static int lastIndexOfLatin1(byte[] src, int srcCount, |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1316 |
byte[] tgt, int tgtCount, int fromIndex) { |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1317 |
assert fromIndex >= 0; |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1318 |
assert tgtCount > 0; |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1319 |
assert tgtCount <= tgt.length; |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1320 |
int min = tgtCount - 1; |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1321 |
int i = min + fromIndex; |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1322 |
int strLastIndex = tgtCount - 1; |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1323 |
|
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1324 |
char strLastChar = (char)(tgt[strLastIndex] & 0xff); |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1325 |
|
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1326 |
checkIndex(i, src); |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1327 |
|
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1328 |
startSearchForLastChar: |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1329 |
while (true) { |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1330 |
while (i >= min && getChar(src, i) != strLastChar) { |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1331 |
i--; |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1332 |
} |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1333 |
if (i < min) { |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1334 |
return -1; |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1335 |
} |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1336 |
int j = i - 1; |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1337 |
int start = j - strLastIndex; |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1338 |
int k = strLastIndex - 1; |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1339 |
while (j > start) { |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1340 |
if (getChar(src, j--) != (tgt[k--] & 0xff)) { |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1341 |
i--; |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1342 |
continue startSearchForLastChar; |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1343 |
} |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1344 |
} |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1345 |
return start + 1; |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1346 |
} |
33663 | 1347 |
} |
1348 |
||
1349 |
//////////////////////////////////////////////////////////////// |
|
1350 |
||
1351 |
private static native boolean isBigEndian(); |
|
1352 |
||
1353 |
static final int HI_BYTE_SHIFT; |
|
1354 |
static final int LO_BYTE_SHIFT; |
|
1355 |
static { |
|
1356 |
if (isBigEndian()) { |
|
1357 |
HI_BYTE_SHIFT = 8; |
|
1358 |
LO_BYTE_SHIFT = 0; |
|
1359 |
} else { |
|
1360 |
HI_BYTE_SHIFT = 0; |
|
1361 |
LO_BYTE_SHIFT = 8; |
|
1362 |
} |
|
1363 |
} |
|
1364 |
||
1365 |
static final int MAX_LENGTH = Integer.MAX_VALUE >> 1; |
|
44642
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1366 |
|
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1367 |
// Used by trusted callers. Assumes all necessary bounds checks have |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1368 |
// been done by the caller. |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1369 |
|
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1370 |
/** |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1371 |
* This is a variant of {@link Integer#getChars(int, int, byte[])}, but for |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1372 |
* UTF-16 coder. |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1373 |
* |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1374 |
* @param i value to convert |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1375 |
* @param index next index, after the least significant digit |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1376 |
* @param buf target buffer, UTF16-coded. |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1377 |
* @return index of the most significant digit or minus sign, if present |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1378 |
*/ |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1379 |
static int getChars(int i, int index, byte[] buf) { |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1380 |
int q, r; |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1381 |
int charPos = index; |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1382 |
|
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1383 |
boolean negative = (i < 0); |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1384 |
if (!negative) { |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1385 |
i = -i; |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1386 |
} |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1387 |
|
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1388 |
// Get 2 digits/iteration using ints |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1389 |
while (i <= -100) { |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1390 |
q = i / 100; |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1391 |
r = (q * 100) - i; |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1392 |
i = q; |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1393 |
putChar(buf, --charPos, Integer.DigitOnes[r]); |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1394 |
putChar(buf, --charPos, Integer.DigitTens[r]); |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1395 |
} |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1396 |
|
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1397 |
// We know there are at most two digits left at this point. |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1398 |
q = i / 10; |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1399 |
r = (q * 10) - i; |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1400 |
putChar(buf, --charPos, '0' + r); |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1401 |
|
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1402 |
// Whatever left is the remaining digit. |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1403 |
if (q < 0) { |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1404 |
putChar(buf, --charPos, '0' - q); |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1405 |
} |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1406 |
|
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1407 |
if (negative) { |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1408 |
putChar(buf, --charPos, '-'); |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1409 |
} |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1410 |
return charPos; |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1411 |
} |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1412 |
|
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1413 |
/** |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1414 |
* This is a variant of {@link Long#getChars(long, int, byte[])}, but for |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1415 |
* UTF-16 coder. |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1416 |
* |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1417 |
* @param i value to convert |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1418 |
* @param index next index, after the least significant digit |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1419 |
* @param buf target buffer, UTF16-coded. |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1420 |
* @return index of the most significant digit or minus sign, if present |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1421 |
*/ |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1422 |
static int getChars(long i, int index, byte[] buf) { |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1423 |
long q; |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1424 |
int r; |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1425 |
int charPos = index; |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1426 |
|
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1427 |
boolean negative = (i < 0); |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1428 |
if (!negative) { |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1429 |
i = -i; |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1430 |
} |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1431 |
|
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1432 |
// Get 2 digits/iteration using longs until quotient fits into an int |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1433 |
while (i <= Integer.MIN_VALUE) { |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1434 |
q = i / 100; |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1435 |
r = (int)((q * 100) - i); |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1436 |
i = q; |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1437 |
putChar(buf, --charPos, Integer.DigitOnes[r]); |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1438 |
putChar(buf, --charPos, Integer.DigitTens[r]); |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1439 |
} |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1440 |
|
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1441 |
// Get 2 digits/iteration using ints |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1442 |
int q2; |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1443 |
int i2 = (int)i; |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1444 |
while (i2 <= -100) { |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1445 |
q2 = i2 / 100; |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1446 |
r = (q2 * 100) - i2; |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1447 |
i2 = q2; |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1448 |
putChar(buf, --charPos, Integer.DigitOnes[r]); |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1449 |
putChar(buf, --charPos, Integer.DigitTens[r]); |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1450 |
} |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1451 |
|
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1452 |
// We know there are at most two digits left at this point. |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1453 |
q2 = i2 / 10; |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1454 |
r = (q2 * 10) - i2; |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1455 |
putChar(buf, --charPos, '0' + r); |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1456 |
|
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1457 |
// Whatever left is the remaining digit. |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1458 |
if (q2 < 0) { |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1459 |
putChar(buf, --charPos, '0' - q2); |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1460 |
} |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1461 |
|
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1462 |
if (negative) { |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1463 |
putChar(buf, --charPos, '-'); |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1464 |
} |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1465 |
return charPos; |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1466 |
} |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1467 |
// End of trusted methods. |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1468 |
|
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1469 |
public static void checkIndex(int off, byte[] val) { |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1470 |
String.checkIndex(off, length(val)); |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1471 |
} |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1472 |
|
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1473 |
public static void checkOffset(int off, byte[] val) { |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1474 |
String.checkOffset(off, length(val)); |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1475 |
} |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1476 |
|
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1477 |
public static void checkBoundsBeginEnd(int begin, int end, byte[] val) { |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1478 |
String.checkBoundsBeginEnd(begin, end, length(val)); |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1479 |
} |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1480 |
|
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1481 |
public static void checkBoundsOffCount(int offset, int count, byte[] val) { |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1482 |
String.checkBoundsOffCount(offset, count, length(val)); |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1483 |
} |
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
42346
diff
changeset
|
1484 |
|
33663 | 1485 |
} |