author | redestad |
Wed, 19 Jul 2017 14:40:50 +0200 | |
changeset 45894 | 995421c69f66 |
parent 42679 | 25fec8839946 |
child 47026 | 94c45ad89b9c |
permissions | -rw-r--r-- |
2 | 1 |
/* |
45894
995421c69f66
8184665: Skip name and alias checks for standard Charsets
redestad
parents:
42679
diff
changeset
|
2 |
* Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved. |
2 | 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 |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 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 |
* |
|
5506 | 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. |
|
2 | 24 |
*/ |
25 |
||
26 |
package sun.nio.cs; |
|
27 |
||
28 |
import java.nio.ByteBuffer; |
|
29 |
import java.nio.CharBuffer; |
|
30 |
import java.nio.charset.Charset; |
|
31 |
import java.nio.charset.CharsetDecoder; |
|
32 |
import java.nio.charset.CharsetEncoder; |
|
33 |
import java.nio.charset.CoderResult; |
|
2294 | 34 |
import java.util.Arrays; |
31671
362e0c0acece
8076112: Add @HotSpotIntrinsicCandidate annotation to indicate methods for which Java Runtime has intrinsics
zmajo
parents:
25859
diff
changeset
|
35 |
import java.util.Objects; |
362e0c0acece
8076112: Add @HotSpotIntrinsicCandidate annotation to indicate methods for which Java Runtime has intrinsics
zmajo
parents:
25859
diff
changeset
|
36 |
|
362e0c0acece
8076112: Add @HotSpotIntrinsicCandidate annotation to indicate methods for which Java Runtime has intrinsics
zmajo
parents:
25859
diff
changeset
|
37 |
import jdk.internal.HotSpotIntrinsicCandidate; |
2 | 38 |
|
39 |
class ISO_8859_1 |
|
40 |
extends Charset |
|
41 |
implements HistoricallyNamedCharset |
|
42 |
{ |
|
43 |
||
44 |
public ISO_8859_1() { |
|
45894
995421c69f66
8184665: Skip name and alias checks for standard Charsets
redestad
parents:
42679
diff
changeset
|
45 |
super(StandardCharsets.ISO_8859_1, StandardCharsets.aliases_ISO_8859_1); |
2 | 46 |
} |
47 |
||
48 |
public String historicalName() { |
|
49 |
return "ISO8859_1"; |
|
50 |
} |
|
51 |
||
52 |
public boolean contains(Charset cs) { |
|
53 |
return ((cs instanceof US_ASCII) |
|
54 |
|| (cs instanceof ISO_8859_1)); |
|
55 |
} |
|
56 |
||
57 |
public CharsetDecoder newDecoder() { |
|
58 |
return new Decoder(this); |
|
59 |
} |
|
60 |
||
61 |
public CharsetEncoder newEncoder() { |
|
62 |
return new Encoder(this); |
|
63 |
} |
|
64 |
||
2294 | 65 |
private static class Decoder extends CharsetDecoder |
66 |
implements ArrayDecoder { |
|
2 | 67 |
private Decoder(Charset cs) { |
68 |
super(cs, 1.0f, 1.0f); |
|
69 |
} |
|
70 |
||
71 |
private CoderResult decodeArrayLoop(ByteBuffer src, |
|
72 |
CharBuffer dst) |
|
73 |
{ |
|
74 |
byte[] sa = src.array(); |
|
75 |
int sp = src.arrayOffset() + src.position(); |
|
76 |
int sl = src.arrayOffset() + src.limit(); |
|
77 |
assert (sp <= sl); |
|
78 |
sp = (sp <= sl ? sp : sl); |
|
79 |
char[] da = dst.array(); |
|
80 |
int dp = dst.arrayOffset() + dst.position(); |
|
81 |
int dl = dst.arrayOffset() + dst.limit(); |
|
82 |
assert (dp <= dl); |
|
83 |
dp = (dp <= dl ? dp : dl); |
|
84 |
||
85 |
try { |
|
86 |
while (sp < sl) { |
|
87 |
byte b = sa[sp]; |
|
88 |
if (dp >= dl) |
|
89 |
return CoderResult.OVERFLOW; |
|
90 |
da[dp++] = (char)(b & 0xff); |
|
91 |
sp++; |
|
92 |
} |
|
93 |
return CoderResult.UNDERFLOW; |
|
94 |
} finally { |
|
95 |
src.position(sp - src.arrayOffset()); |
|
96 |
dst.position(dp - dst.arrayOffset()); |
|
97 |
} |
|
98 |
} |
|
99 |
||
100 |
private CoderResult decodeBufferLoop(ByteBuffer src, |
|
101 |
CharBuffer dst) |
|
102 |
{ |
|
103 |
int mark = src.position(); |
|
104 |
try { |
|
105 |
while (src.hasRemaining()) { |
|
106 |
byte b = src.get(); |
|
107 |
if (!dst.hasRemaining()) |
|
108 |
return CoderResult.OVERFLOW; |
|
109 |
dst.put((char)(b & 0xff)); |
|
110 |
mark++; |
|
111 |
} |
|
112 |
return CoderResult.UNDERFLOW; |
|
113 |
} finally { |
|
114 |
src.position(mark); |
|
115 |
} |
|
116 |
} |
|
117 |
||
118 |
protected CoderResult decodeLoop(ByteBuffer src, |
|
119 |
CharBuffer dst) |
|
120 |
{ |
|
121 |
if (src.hasArray() && dst.hasArray()) |
|
122 |
return decodeArrayLoop(src, dst); |
|
123 |
else |
|
124 |
return decodeBufferLoop(src, dst); |
|
125 |
} |
|
126 |
||
2294 | 127 |
public int decode(byte[] src, int sp, int len, char[] dst) { |
128 |
if (len > dst.length) |
|
129 |
len = dst.length; |
|
130 |
int dp = 0; |
|
131 |
while (dp < len) |
|
132 |
dst[dp++] = (char)(src[sp++] & 0xff); |
|
133 |
return dp; |
|
134 |
} |
|
33663 | 135 |
|
136 |
public boolean isASCIICompatible() { |
|
137 |
return true; |
|
138 |
} |
|
2 | 139 |
} |
140 |
||
2294 | 141 |
private static class Encoder extends CharsetEncoder |
142 |
implements ArrayEncoder { |
|
2 | 143 |
private Encoder(Charset cs) { |
144 |
super(cs, 1.0f, 1.0f); |
|
145 |
} |
|
146 |
||
147 |
public boolean canEncode(char c) { |
|
148 |
return c <= '\u00FF'; |
|
149 |
} |
|
150 |
||
2294 | 151 |
public boolean isLegalReplacement(byte[] repl) { |
3055
54b677070c61
6847092: (cs) CharsetEncoder.isLegalReplacement of US_ASCII behaves differently since
sherman
parents:
2294
diff
changeset
|
152 |
return true; // we accept any byte value |
2294 | 153 |
} |
154 |
||
2 | 155 |
private final Surrogate.Parser sgp = new Surrogate.Parser(); |
156 |
||
31671
362e0c0acece
8076112: Add @HotSpotIntrinsicCandidate annotation to indicate methods for which Java Runtime has intrinsics
zmajo
parents:
25859
diff
changeset
|
157 |
// Method possible replaced with a compiler intrinsic. |
15337
3fc0afb7ff5b
8006799: Optimize sun.nio.cs.ISO_8859_1$Encode.encodeArrayLoop() (jdk part of 6896617)
kvn
parents:
5506
diff
changeset
|
158 |
private static int encodeISOArray(char[] sa, int sp, |
31671
362e0c0acece
8076112: Add @HotSpotIntrinsicCandidate annotation to indicate methods for which Java Runtime has intrinsics
zmajo
parents:
25859
diff
changeset
|
159 |
byte[] da, int dp, int len) { |
42679
25fec8839946
8159035: com/sun/crypto/provider/Cipher/CTS/CTSMode.java test crashed due to unhandled case of cipher length value as 0
rraghavan
parents:
33663
diff
changeset
|
160 |
if (len <= 0) { |
25fec8839946
8159035: com/sun/crypto/provider/Cipher/CTS/CTSMode.java test crashed due to unhandled case of cipher length value as 0
rraghavan
parents:
33663
diff
changeset
|
161 |
return 0; |
25fec8839946
8159035: com/sun/crypto/provider/Cipher/CTS/CTSMode.java test crashed due to unhandled case of cipher length value as 0
rraghavan
parents:
33663
diff
changeset
|
162 |
} |
31671
362e0c0acece
8076112: Add @HotSpotIntrinsicCandidate annotation to indicate methods for which Java Runtime has intrinsics
zmajo
parents:
25859
diff
changeset
|
163 |
encodeISOArrayCheck(sa, sp, da, dp, len); |
362e0c0acece
8076112: Add @HotSpotIntrinsicCandidate annotation to indicate methods for which Java Runtime has intrinsics
zmajo
parents:
25859
diff
changeset
|
164 |
return implEncodeISOArray(sa, sp, da, dp, len); |
362e0c0acece
8076112: Add @HotSpotIntrinsicCandidate annotation to indicate methods for which Java Runtime has intrinsics
zmajo
parents:
25859
diff
changeset
|
165 |
} |
362e0c0acece
8076112: Add @HotSpotIntrinsicCandidate annotation to indicate methods for which Java Runtime has intrinsics
zmajo
parents:
25859
diff
changeset
|
166 |
|
362e0c0acece
8076112: Add @HotSpotIntrinsicCandidate annotation to indicate methods for which Java Runtime has intrinsics
zmajo
parents:
25859
diff
changeset
|
167 |
@HotSpotIntrinsicCandidate |
362e0c0acece
8076112: Add @HotSpotIntrinsicCandidate annotation to indicate methods for which Java Runtime has intrinsics
zmajo
parents:
25859
diff
changeset
|
168 |
private static int implEncodeISOArray(char[] sa, int sp, |
362e0c0acece
8076112: Add @HotSpotIntrinsicCandidate annotation to indicate methods for which Java Runtime has intrinsics
zmajo
parents:
25859
diff
changeset
|
169 |
byte[] da, int dp, int len) |
15337
3fc0afb7ff5b
8006799: Optimize sun.nio.cs.ISO_8859_1$Encode.encodeArrayLoop() (jdk part of 6896617)
kvn
parents:
5506
diff
changeset
|
170 |
{ |
3fc0afb7ff5b
8006799: Optimize sun.nio.cs.ISO_8859_1$Encode.encodeArrayLoop() (jdk part of 6896617)
kvn
parents:
5506
diff
changeset
|
171 |
int i = 0; |
3fc0afb7ff5b
8006799: Optimize sun.nio.cs.ISO_8859_1$Encode.encodeArrayLoop() (jdk part of 6896617)
kvn
parents:
5506
diff
changeset
|
172 |
for (; i < len; i++) { |
3fc0afb7ff5b
8006799: Optimize sun.nio.cs.ISO_8859_1$Encode.encodeArrayLoop() (jdk part of 6896617)
kvn
parents:
5506
diff
changeset
|
173 |
char c = sa[sp++]; |
3fc0afb7ff5b
8006799: Optimize sun.nio.cs.ISO_8859_1$Encode.encodeArrayLoop() (jdk part of 6896617)
kvn
parents:
5506
diff
changeset
|
174 |
if (c > '\u00FF') |
3fc0afb7ff5b
8006799: Optimize sun.nio.cs.ISO_8859_1$Encode.encodeArrayLoop() (jdk part of 6896617)
kvn
parents:
5506
diff
changeset
|
175 |
break; |
3fc0afb7ff5b
8006799: Optimize sun.nio.cs.ISO_8859_1$Encode.encodeArrayLoop() (jdk part of 6896617)
kvn
parents:
5506
diff
changeset
|
176 |
da[dp++] = (byte)c; |
3fc0afb7ff5b
8006799: Optimize sun.nio.cs.ISO_8859_1$Encode.encodeArrayLoop() (jdk part of 6896617)
kvn
parents:
5506
diff
changeset
|
177 |
} |
3fc0afb7ff5b
8006799: Optimize sun.nio.cs.ISO_8859_1$Encode.encodeArrayLoop() (jdk part of 6896617)
kvn
parents:
5506
diff
changeset
|
178 |
return i; |
3fc0afb7ff5b
8006799: Optimize sun.nio.cs.ISO_8859_1$Encode.encodeArrayLoop() (jdk part of 6896617)
kvn
parents:
5506
diff
changeset
|
179 |
} |
3fc0afb7ff5b
8006799: Optimize sun.nio.cs.ISO_8859_1$Encode.encodeArrayLoop() (jdk part of 6896617)
kvn
parents:
5506
diff
changeset
|
180 |
|
31671
362e0c0acece
8076112: Add @HotSpotIntrinsicCandidate annotation to indicate methods for which Java Runtime has intrinsics
zmajo
parents:
25859
diff
changeset
|
181 |
private static void encodeISOArrayCheck(char[] sa, int sp, |
362e0c0acece
8076112: Add @HotSpotIntrinsicCandidate annotation to indicate methods for which Java Runtime has intrinsics
zmajo
parents:
25859
diff
changeset
|
182 |
byte[] da, int dp, int len) { |
362e0c0acece
8076112: Add @HotSpotIntrinsicCandidate annotation to indicate methods for which Java Runtime has intrinsics
zmajo
parents:
25859
diff
changeset
|
183 |
Objects.requireNonNull(sa); |
362e0c0acece
8076112: Add @HotSpotIntrinsicCandidate annotation to indicate methods for which Java Runtime has intrinsics
zmajo
parents:
25859
diff
changeset
|
184 |
Objects.requireNonNull(da); |
362e0c0acece
8076112: Add @HotSpotIntrinsicCandidate annotation to indicate methods for which Java Runtime has intrinsics
zmajo
parents:
25859
diff
changeset
|
185 |
|
362e0c0acece
8076112: Add @HotSpotIntrinsicCandidate annotation to indicate methods for which Java Runtime has intrinsics
zmajo
parents:
25859
diff
changeset
|
186 |
if (sp < 0 || sp >= sa.length) { |
362e0c0acece
8076112: Add @HotSpotIntrinsicCandidate annotation to indicate methods for which Java Runtime has intrinsics
zmajo
parents:
25859
diff
changeset
|
187 |
throw new ArrayIndexOutOfBoundsException(sp); |
362e0c0acece
8076112: Add @HotSpotIntrinsicCandidate annotation to indicate methods for which Java Runtime has intrinsics
zmajo
parents:
25859
diff
changeset
|
188 |
} |
362e0c0acece
8076112: Add @HotSpotIntrinsicCandidate annotation to indicate methods for which Java Runtime has intrinsics
zmajo
parents:
25859
diff
changeset
|
189 |
|
362e0c0acece
8076112: Add @HotSpotIntrinsicCandidate annotation to indicate methods for which Java Runtime has intrinsics
zmajo
parents:
25859
diff
changeset
|
190 |
if (dp < 0 || dp >= da.length) { |
362e0c0acece
8076112: Add @HotSpotIntrinsicCandidate annotation to indicate methods for which Java Runtime has intrinsics
zmajo
parents:
25859
diff
changeset
|
191 |
throw new ArrayIndexOutOfBoundsException(dp); |
362e0c0acece
8076112: Add @HotSpotIntrinsicCandidate annotation to indicate methods for which Java Runtime has intrinsics
zmajo
parents:
25859
diff
changeset
|
192 |
} |
362e0c0acece
8076112: Add @HotSpotIntrinsicCandidate annotation to indicate methods for which Java Runtime has intrinsics
zmajo
parents:
25859
diff
changeset
|
193 |
|
362e0c0acece
8076112: Add @HotSpotIntrinsicCandidate annotation to indicate methods for which Java Runtime has intrinsics
zmajo
parents:
25859
diff
changeset
|
194 |
int endIndexSP = sp + len - 1; |
362e0c0acece
8076112: Add @HotSpotIntrinsicCandidate annotation to indicate methods for which Java Runtime has intrinsics
zmajo
parents:
25859
diff
changeset
|
195 |
if (endIndexSP < 0 || endIndexSP >= sa.length) { |
362e0c0acece
8076112: Add @HotSpotIntrinsicCandidate annotation to indicate methods for which Java Runtime has intrinsics
zmajo
parents:
25859
diff
changeset
|
196 |
throw new ArrayIndexOutOfBoundsException(endIndexSP); |
362e0c0acece
8076112: Add @HotSpotIntrinsicCandidate annotation to indicate methods for which Java Runtime has intrinsics
zmajo
parents:
25859
diff
changeset
|
197 |
} |
362e0c0acece
8076112: Add @HotSpotIntrinsicCandidate annotation to indicate methods for which Java Runtime has intrinsics
zmajo
parents:
25859
diff
changeset
|
198 |
|
362e0c0acece
8076112: Add @HotSpotIntrinsicCandidate annotation to indicate methods for which Java Runtime has intrinsics
zmajo
parents:
25859
diff
changeset
|
199 |
int endIndexDP = dp + len - 1; |
362e0c0acece
8076112: Add @HotSpotIntrinsicCandidate annotation to indicate methods for which Java Runtime has intrinsics
zmajo
parents:
25859
diff
changeset
|
200 |
if (endIndexDP < 0 || endIndexDP >= da.length) { |
362e0c0acece
8076112: Add @HotSpotIntrinsicCandidate annotation to indicate methods for which Java Runtime has intrinsics
zmajo
parents:
25859
diff
changeset
|
201 |
throw new ArrayIndexOutOfBoundsException(endIndexDP); |
362e0c0acece
8076112: Add @HotSpotIntrinsicCandidate annotation to indicate methods for which Java Runtime has intrinsics
zmajo
parents:
25859
diff
changeset
|
202 |
} |
362e0c0acece
8076112: Add @HotSpotIntrinsicCandidate annotation to indicate methods for which Java Runtime has intrinsics
zmajo
parents:
25859
diff
changeset
|
203 |
} |
362e0c0acece
8076112: Add @HotSpotIntrinsicCandidate annotation to indicate methods for which Java Runtime has intrinsics
zmajo
parents:
25859
diff
changeset
|
204 |
|
2 | 205 |
private CoderResult encodeArrayLoop(CharBuffer src, |
206 |
ByteBuffer dst) |
|
207 |
{ |
|
208 |
char[] sa = src.array(); |
|
15337
3fc0afb7ff5b
8006799: Optimize sun.nio.cs.ISO_8859_1$Encode.encodeArrayLoop() (jdk part of 6896617)
kvn
parents:
5506
diff
changeset
|
209 |
int soff = src.arrayOffset(); |
3fc0afb7ff5b
8006799: Optimize sun.nio.cs.ISO_8859_1$Encode.encodeArrayLoop() (jdk part of 6896617)
kvn
parents:
5506
diff
changeset
|
210 |
int sp = soff + src.position(); |
3fc0afb7ff5b
8006799: Optimize sun.nio.cs.ISO_8859_1$Encode.encodeArrayLoop() (jdk part of 6896617)
kvn
parents:
5506
diff
changeset
|
211 |
int sl = soff + src.limit(); |
2 | 212 |
assert (sp <= sl); |
213 |
sp = (sp <= sl ? sp : sl); |
|
214 |
byte[] da = dst.array(); |
|
15337
3fc0afb7ff5b
8006799: Optimize sun.nio.cs.ISO_8859_1$Encode.encodeArrayLoop() (jdk part of 6896617)
kvn
parents:
5506
diff
changeset
|
215 |
int doff = dst.arrayOffset(); |
3fc0afb7ff5b
8006799: Optimize sun.nio.cs.ISO_8859_1$Encode.encodeArrayLoop() (jdk part of 6896617)
kvn
parents:
5506
diff
changeset
|
216 |
int dp = doff + dst.position(); |
3fc0afb7ff5b
8006799: Optimize sun.nio.cs.ISO_8859_1$Encode.encodeArrayLoop() (jdk part of 6896617)
kvn
parents:
5506
diff
changeset
|
217 |
int dl = doff + dst.limit(); |
2 | 218 |
assert (dp <= dl); |
219 |
dp = (dp <= dl ? dp : dl); |
|
15337
3fc0afb7ff5b
8006799: Optimize sun.nio.cs.ISO_8859_1$Encode.encodeArrayLoop() (jdk part of 6896617)
kvn
parents:
5506
diff
changeset
|
220 |
int dlen = dl - dp; |
3fc0afb7ff5b
8006799: Optimize sun.nio.cs.ISO_8859_1$Encode.encodeArrayLoop() (jdk part of 6896617)
kvn
parents:
5506
diff
changeset
|
221 |
int slen = sl - sp; |
3fc0afb7ff5b
8006799: Optimize sun.nio.cs.ISO_8859_1$Encode.encodeArrayLoop() (jdk part of 6896617)
kvn
parents:
5506
diff
changeset
|
222 |
int len = (dlen < slen) ? dlen : slen; |
2 | 223 |
try { |
15337
3fc0afb7ff5b
8006799: Optimize sun.nio.cs.ISO_8859_1$Encode.encodeArrayLoop() (jdk part of 6896617)
kvn
parents:
5506
diff
changeset
|
224 |
int ret = encodeISOArray(sa, sp, da, dp, len); |
3fc0afb7ff5b
8006799: Optimize sun.nio.cs.ISO_8859_1$Encode.encodeArrayLoop() (jdk part of 6896617)
kvn
parents:
5506
diff
changeset
|
225 |
sp = sp + ret; |
3fc0afb7ff5b
8006799: Optimize sun.nio.cs.ISO_8859_1$Encode.encodeArrayLoop() (jdk part of 6896617)
kvn
parents:
5506
diff
changeset
|
226 |
dp = dp + ret; |
3fc0afb7ff5b
8006799: Optimize sun.nio.cs.ISO_8859_1$Encode.encodeArrayLoop() (jdk part of 6896617)
kvn
parents:
5506
diff
changeset
|
227 |
if (ret != len) { |
3fc0afb7ff5b
8006799: Optimize sun.nio.cs.ISO_8859_1$Encode.encodeArrayLoop() (jdk part of 6896617)
kvn
parents:
5506
diff
changeset
|
228 |
if (sgp.parse(sa[sp], sa, sp, sl) < 0) |
2 | 229 |
return sgp.error(); |
230 |
return sgp.unmappableResult(); |
|
231 |
} |
|
15337
3fc0afb7ff5b
8006799: Optimize sun.nio.cs.ISO_8859_1$Encode.encodeArrayLoop() (jdk part of 6896617)
kvn
parents:
5506
diff
changeset
|
232 |
if (len < slen) |
3fc0afb7ff5b
8006799: Optimize sun.nio.cs.ISO_8859_1$Encode.encodeArrayLoop() (jdk part of 6896617)
kvn
parents:
5506
diff
changeset
|
233 |
return CoderResult.OVERFLOW; |
2 | 234 |
return CoderResult.UNDERFLOW; |
235 |
} finally { |
|
15337
3fc0afb7ff5b
8006799: Optimize sun.nio.cs.ISO_8859_1$Encode.encodeArrayLoop() (jdk part of 6896617)
kvn
parents:
5506
diff
changeset
|
236 |
src.position(sp - soff); |
3fc0afb7ff5b
8006799: Optimize sun.nio.cs.ISO_8859_1$Encode.encodeArrayLoop() (jdk part of 6896617)
kvn
parents:
5506
diff
changeset
|
237 |
dst.position(dp - doff); |
2 | 238 |
} |
239 |
} |
|
240 |
||
241 |
private CoderResult encodeBufferLoop(CharBuffer src, |
|
242 |
ByteBuffer dst) |
|
243 |
{ |
|
244 |
int mark = src.position(); |
|
245 |
try { |
|
246 |
while (src.hasRemaining()) { |
|
247 |
char c = src.get(); |
|
248 |
if (c <= '\u00FF') { |
|
249 |
if (!dst.hasRemaining()) |
|
250 |
return CoderResult.OVERFLOW; |
|
251 |
dst.put((byte)c); |
|
252 |
mark++; |
|
253 |
continue; |
|
254 |
} |
|
255 |
if (sgp.parse(c, src) < 0) |
|
256 |
return sgp.error(); |
|
257 |
return sgp.unmappableResult(); |
|
258 |
} |
|
259 |
return CoderResult.UNDERFLOW; |
|
260 |
} finally { |
|
261 |
src.position(mark); |
|
262 |
} |
|
263 |
} |
|
264 |
||
265 |
protected CoderResult encodeLoop(CharBuffer src, |
|
266 |
ByteBuffer dst) |
|
267 |
{ |
|
268 |
if (src.hasArray() && dst.hasArray()) |
|
269 |
return encodeArrayLoop(src, dst); |
|
270 |
else |
|
271 |
return encodeBufferLoop(src, dst); |
|
272 |
} |
|
273 |
||
2294 | 274 |
private byte repl = (byte)'?'; |
275 |
protected void implReplaceWith(byte[] newReplacement) { |
|
276 |
repl = newReplacement[0]; |
|
277 |
} |
|
278 |
||
279 |
public int encode(char[] src, int sp, int len, byte[] dst) { |
|
280 |
int dp = 0; |
|
15337
3fc0afb7ff5b
8006799: Optimize sun.nio.cs.ISO_8859_1$Encode.encodeArrayLoop() (jdk part of 6896617)
kvn
parents:
5506
diff
changeset
|
281 |
int slen = Math.min(len, dst.length); |
3fc0afb7ff5b
8006799: Optimize sun.nio.cs.ISO_8859_1$Encode.encodeArrayLoop() (jdk part of 6896617)
kvn
parents:
5506
diff
changeset
|
282 |
int sl = sp + slen; |
2294 | 283 |
while (sp < sl) { |
15337
3fc0afb7ff5b
8006799: Optimize sun.nio.cs.ISO_8859_1$Encode.encodeArrayLoop() (jdk part of 6896617)
kvn
parents:
5506
diff
changeset
|
284 |
int ret = encodeISOArray(src, sp, dst, dp, slen); |
3fc0afb7ff5b
8006799: Optimize sun.nio.cs.ISO_8859_1$Encode.encodeArrayLoop() (jdk part of 6896617)
kvn
parents:
5506
diff
changeset
|
285 |
sp = sp + ret; |
3fc0afb7ff5b
8006799: Optimize sun.nio.cs.ISO_8859_1$Encode.encodeArrayLoop() (jdk part of 6896617)
kvn
parents:
5506
diff
changeset
|
286 |
dp = dp + ret; |
3fc0afb7ff5b
8006799: Optimize sun.nio.cs.ISO_8859_1$Encode.encodeArrayLoop() (jdk part of 6896617)
kvn
parents:
5506
diff
changeset
|
287 |
if (ret != slen) { |
3fc0afb7ff5b
8006799: Optimize sun.nio.cs.ISO_8859_1$Encode.encodeArrayLoop() (jdk part of 6896617)
kvn
parents:
5506
diff
changeset
|
288 |
char c = src[sp++]; |
3fc0afb7ff5b
8006799: Optimize sun.nio.cs.ISO_8859_1$Encode.encodeArrayLoop() (jdk part of 6896617)
kvn
parents:
5506
diff
changeset
|
289 |
if (Character.isHighSurrogate(c) && sp < sl && |
3fc0afb7ff5b
8006799: Optimize sun.nio.cs.ISO_8859_1$Encode.encodeArrayLoop() (jdk part of 6896617)
kvn
parents:
5506
diff
changeset
|
290 |
Character.isLowSurrogate(src[sp])) { |
3fc0afb7ff5b
8006799: Optimize sun.nio.cs.ISO_8859_1$Encode.encodeArrayLoop() (jdk part of 6896617)
kvn
parents:
5506
diff
changeset
|
291 |
if (len > dst.length) { |
3fc0afb7ff5b
8006799: Optimize sun.nio.cs.ISO_8859_1$Encode.encodeArrayLoop() (jdk part of 6896617)
kvn
parents:
5506
diff
changeset
|
292 |
sl++; |
3fc0afb7ff5b
8006799: Optimize sun.nio.cs.ISO_8859_1$Encode.encodeArrayLoop() (jdk part of 6896617)
kvn
parents:
5506
diff
changeset
|
293 |
len--; |
3fc0afb7ff5b
8006799: Optimize sun.nio.cs.ISO_8859_1$Encode.encodeArrayLoop() (jdk part of 6896617)
kvn
parents:
5506
diff
changeset
|
294 |
} |
3fc0afb7ff5b
8006799: Optimize sun.nio.cs.ISO_8859_1$Encode.encodeArrayLoop() (jdk part of 6896617)
kvn
parents:
5506
diff
changeset
|
295 |
sp++; |
3fc0afb7ff5b
8006799: Optimize sun.nio.cs.ISO_8859_1$Encode.encodeArrayLoop() (jdk part of 6896617)
kvn
parents:
5506
diff
changeset
|
296 |
} |
3fc0afb7ff5b
8006799: Optimize sun.nio.cs.ISO_8859_1$Encode.encodeArrayLoop() (jdk part of 6896617)
kvn
parents:
5506
diff
changeset
|
297 |
dst[dp++] = repl; |
3fc0afb7ff5b
8006799: Optimize sun.nio.cs.ISO_8859_1$Encode.encodeArrayLoop() (jdk part of 6896617)
kvn
parents:
5506
diff
changeset
|
298 |
slen = Math.min((sl - sp), (dst.length - dp)); |
2294 | 299 |
} |
300 |
} |
|
301 |
return dp; |
|
302 |
} |
|
33663 | 303 |
|
304 |
public boolean isASCIICompatible() { |
|
305 |
return true; |
|
306 |
} |
|
2 | 307 |
} |
308 |
} |