1
1
/*
2
- * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
2
+ * Copyright (c) 2011, 2021, Oracle and/or its affiliates. All rights reserved.
3
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
4
*
5
5
* This code is free software; you can redistribute it and/or modify it
25
25
26
26
package sun .nio .cs ;
27
27
28
+ import jdk .internal .access .JavaLangAccess ;
29
+ import jdk .internal .access .SharedSecrets ;
30
+
28
31
import java .nio .Buffer ;
29
32
import java .nio .ByteBuffer ;
30
33
import java .nio .CharBuffer ;
@@ -75,6 +78,9 @@ private static final void updatePositions(Buffer src, int sp,
75
78
76
79
private static class Decoder extends CharsetDecoder
77
80
implements ArrayDecoder {
81
+
82
+ private static final JavaLangAccess JLA = SharedSecrets .getJavaLangAccess ();
83
+
78
84
private Decoder (Charset cs ) {
79
85
super (cs , 1.0f , 1.0f );
80
86
}
@@ -96,27 +102,6 @@ private static boolean isMalformed3_2(int b1, int b2) {
96
102
(b2 & 0xc0 ) != 0x80 ;
97
103
}
98
104
99
-
100
- // [F0] [90..BF] [80..BF] [80..BF]
101
- // [F1..F3] [80..BF] [80..BF] [80..BF]
102
- // [F4] [80..8F] [80..BF] [80..BF]
103
- // only check 80-be range here, the [0xf0,0x80...] and [0xf4,0x90-...]
104
- // will be checked by Character.isSupplementaryCodePoint(uc)
105
- private static boolean isMalformed4 (int b2 , int b3 , int b4 ) {
106
- return (b2 & 0xc0 ) != 0x80 || (b3 & 0xc0 ) != 0x80 ||
107
- (b4 & 0xc0 ) != 0x80 ;
108
- }
109
-
110
- // only used when there is less than 4 bytes left in src buffer
111
- private static boolean isMalformed4_2 (int b1 , int b2 ) {
112
- return (b1 == 0xf0 && b2 == 0x90 ) ||
113
- (b2 & 0xc0 ) != 0x80 ;
114
- }
115
-
116
- private static boolean isMalformed4_3 (int b3 ) {
117
- return (b3 & 0xc0 ) != 0x80 ;
118
- }
119
-
120
105
private static CoderResult malformedN (ByteBuffer src , int nb ) {
121
106
switch (nb ) {
122
107
case 1 :
@@ -202,17 +187,19 @@ private CoderResult decodeArrayLoop(ByteBuffer src,
202
187
{
203
188
// This method is optimized for ASCII input.
204
189
byte [] sa = src .array ();
205
- int sp = src .arrayOffset () + src .position ();
206
- int sl = src .arrayOffset () + src .limit ();
190
+ int soff = src .arrayOffset ();
191
+ int sp = soff + src .position ();
192
+ int sl = soff + src .limit ();
207
193
208
194
char [] da = dst .array ();
209
- int dp = dst .arrayOffset () + dst .position ();
210
- int dl = dst .arrayOffset () + dst .limit ();
211
- int dlASCII = dp + Math .min (sl - sp , dl - dp );
195
+ int doff = dst .arrayOffset ();
196
+ int dp = doff + dst .position ();
197
+ int dl = doff + dst .limit ();
198
+
199
+ int n = JLA .decodeASCII (sa , sp , da , dp , Math .min (sl - sp , dl - dp ));
200
+ sp += n ;
201
+ dp += n ;
212
202
213
- // ASCII only loop
214
- while (dp < dlASCII && sa [sp ] >= 0 )
215
- da [dp ++] = (char ) sa [sp ++];
216
203
while (sp < sl ) {
217
204
int b1 = sa [sp ];
218
205
if (b1 >= 0 ) {
0 commit comments