|
33 | 33 | import java.util.stream.Stream; |
34 | 34 | import java.util.stream.StreamSupport; |
35 | 35 | import jdk.internal.util.ArraysSupport; |
36 | | -import jdk.internal.util.ByteArrayLittleEndian; |
| 36 | +import jdk.internal.util.DecimalDigits; |
37 | 37 | import jdk.internal.vm.annotation.IntrinsicCandidate; |
38 | | -import jdk.internal.vm.annotation.Stable; |
39 | 38 |
|
40 | 39 | import static java.lang.String.LATIN1; |
41 | 40 | import static java.lang.String.UTF16; |
42 | 41 | import static java.lang.String.checkIndex; |
43 | 42 | import static java.lang.String.checkOffset; |
44 | 43 |
|
45 | 44 | final class StringLatin1 { |
46 | | - |
47 | | - /** |
48 | | - * Each element of the array represents the packaging of two ascii characters based on little endian:<p> |
49 | | - * <pre> |
50 | | - * 00 -> '0' | ('0' << 8) -> 0x3030 |
51 | | - * 01 -> '1' | ('0' << 8) -> 0x3130 |
52 | | - * 02 -> '2' | ('0' << 8) -> 0x3230 |
53 | | - * |
54 | | - * ... |
55 | | - * |
56 | | - * 10 -> '0' | ('1' << 8) -> 0x3031 |
57 | | - * 11 -> '1' | ('1' << 8) -> 0x3131 |
58 | | - * 12 -> '2' | ('1' << 8) -> 0x3231 |
59 | | - * |
60 | | - * ... |
61 | | - * |
62 | | - * 97 -> '7' | ('9' << 8) -> 0x3739 |
63 | | - * 98 -> '8' | ('9' << 8) -> 0x3839 |
64 | | - * 99 -> '9' | ('9' << 8) -> 0x3939 |
65 | | - * </pre> |
66 | | - */ |
67 | | - @Stable |
68 | | - static final short[] PACKED_DIGITS = new short[] { |
69 | | - 0x3030, 0x3130, 0x3230, 0x3330, 0x3430, 0x3530, 0x3630, 0x3730, 0x3830, 0x3930, |
70 | | - 0x3031, 0x3131, 0x3231, 0x3331, 0x3431, 0x3531, 0x3631, 0x3731, 0x3831, 0x3931, |
71 | | - 0x3032, 0x3132, 0x3232, 0x3332, 0x3432, 0x3532, 0x3632, 0x3732, 0x3832, 0x3932, |
72 | | - 0x3033, 0x3133, 0x3233, 0x3333, 0x3433, 0x3533, 0x3633, 0x3733, 0x3833, 0x3933, |
73 | | - 0x3034, 0x3134, 0x3234, 0x3334, 0x3434, 0x3534, 0x3634, 0x3734, 0x3834, 0x3934, |
74 | | - 0x3035, 0x3135, 0x3235, 0x3335, 0x3435, 0x3535, 0x3635, 0x3735, 0x3835, 0x3935, |
75 | | - 0x3036, 0x3136, 0x3236, 0x3336, 0x3436, 0x3536, 0x3636, 0x3736, 0x3836, 0x3936, |
76 | | - 0x3037, 0x3137, 0x3237, 0x3337, 0x3437, 0x3537, 0x3637, 0x3737, 0x3837, 0x3937, |
77 | | - 0x3038, 0x3138, 0x3238, 0x3338, 0x3438, 0x3538, 0x3638, 0x3738, 0x3838, 0x3938, |
78 | | - 0x3039, 0x3139, 0x3239, 0x3339, 0x3439, 0x3539, 0x3639, 0x3739, 0x3839, 0x3939 |
79 | | - }; |
80 | | - |
81 | 45 | public static char charAt(byte[] value, int index) { |
82 | 46 | checkIndex(index, value.length); |
83 | 47 | return (char)(value[index] & 0xff); |
@@ -115,115 +79,6 @@ public static byte[] inflate(byte[] value, int off, int len) { |
115 | 79 | return ret; |
116 | 80 | } |
117 | 81 |
|
118 | | - /** |
119 | | - * Places characters representing the integer i into the |
120 | | - * character array buf. The characters are placed into |
121 | | - * the buffer backwards starting with the least significant |
122 | | - * digit at the specified index (exclusive), and working |
123 | | - * backwards from there. |
124 | | - * |
125 | | - * @implNote This method converts positive inputs into negative |
126 | | - * values, to cover the Integer.MIN_VALUE case. Converting otherwise |
127 | | - * (negative to positive) will expose -Integer.MIN_VALUE that overflows |
128 | | - * integer. |
129 | | - * |
130 | | - * @param i value to convert |
131 | | - * @param index next index, after the least significant digit |
132 | | - * @param buf target buffer, Latin1-encoded |
133 | | - * @return index of the most significant digit or minus sign, if present |
134 | | - */ |
135 | | - static int getChars(int i, int index, byte[] buf) { |
136 | | - // Used by trusted callers. Assumes all necessary bounds checks have been done by the caller. |
137 | | - int q, r; |
138 | | - int charPos = index; |
139 | | - |
140 | | - boolean negative = i < 0; |
141 | | - if (!negative) { |
142 | | - i = -i; |
143 | | - } |
144 | | - |
145 | | - // Generate two digits per iteration |
146 | | - while (i <= -100) { |
147 | | - q = i / 100; |
148 | | - r = (q * 100) - i; |
149 | | - i = q; |
150 | | - charPos -= 2; |
151 | | - ByteArrayLittleEndian.setShort(buf, charPos, PACKED_DIGITS[r]); |
152 | | - } |
153 | | - |
154 | | - // We know there are at most two digits left at this point. |
155 | | - if (i < -9) { |
156 | | - charPos -= 2; |
157 | | - ByteArrayLittleEndian.setShort(buf, charPos, PACKED_DIGITS[-i]); |
158 | | - } else { |
159 | | - buf[--charPos] = (byte)('0' - i); |
160 | | - } |
161 | | - |
162 | | - if (negative) { |
163 | | - buf[--charPos] = (byte)'-'; |
164 | | - } |
165 | | - return charPos; |
166 | | - } |
167 | | - |
168 | | - /** |
169 | | - * Places characters representing the long i into the |
170 | | - * character array buf. The characters are placed into |
171 | | - * the buffer backwards starting with the least significant |
172 | | - * digit at the specified index (exclusive), and working |
173 | | - * backwards from there. |
174 | | - * |
175 | | - * @implNote This method converts positive inputs into negative |
176 | | - * values, to cover the Long.MIN_VALUE case. Converting otherwise |
177 | | - * (negative to positive) will expose -Long.MIN_VALUE that overflows |
178 | | - * long. |
179 | | - * |
180 | | - * @param i value to convert |
181 | | - * @param index next index, after the least significant digit |
182 | | - * @param buf target buffer, Latin1-encoded |
183 | | - * @return index of the most significant digit or minus sign, if present |
184 | | - */ |
185 | | - static int getChars(long i, int index, byte[] buf) { |
186 | | - // Used by trusted callers. Assumes all necessary bounds checks have been done by the caller. |
187 | | - long q; |
188 | | - int charPos = index; |
189 | | - |
190 | | - boolean negative = (i < 0); |
191 | | - if (!negative) { |
192 | | - i = -i; |
193 | | - } |
194 | | - |
195 | | - // Get 2 digits/iteration using longs until quotient fits into an int |
196 | | - while (i <= Integer.MIN_VALUE) { |
197 | | - q = i / 100; |
198 | | - charPos -= 2; |
199 | | - ByteArrayLittleEndian.setShort(buf, charPos, PACKED_DIGITS[(int)((q * 100) - i)]); |
200 | | - i = q; |
201 | | - } |
202 | | - |
203 | | - // Get 2 digits/iteration using ints |
204 | | - int q2; |
205 | | - int i2 = (int)i; |
206 | | - while (i2 <= -100) { |
207 | | - q2 = i2 / 100; |
208 | | - charPos -= 2; |
209 | | - ByteArrayLittleEndian.setShort(buf, charPos, PACKED_DIGITS[(q2 * 100) - i2]); |
210 | | - i2 = q2; |
211 | | - } |
212 | | - |
213 | | - // We know there are at most two digits left at this point. |
214 | | - if (i2 < -9) { |
215 | | - charPos -= 2; |
216 | | - ByteArrayLittleEndian.setShort(buf, charPos, PACKED_DIGITS[-i2]); |
217 | | - } else { |
218 | | - buf[--charPos] = (byte)('0' - i2); |
219 | | - } |
220 | | - |
221 | | - if (negative) { |
222 | | - buf[--charPos] = (byte)'-'; |
223 | | - } |
224 | | - return charPos; |
225 | | - } |
226 | | - |
227 | 82 | public static void getChars(byte[] value, int srcBegin, int srcEnd, char[] dst, int dstBegin) { |
228 | 83 | inflate(value, srcBegin, dst, dstBegin, srcEnd - srcBegin); |
229 | 84 | } |
|
0 commit comments